mirror of https://github.com/kubernetes/kops.git
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
/*
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/blang/semver"
|
|
"k8s.io/kops/pkg/apis/kops"
|
|
"k8s.io/kops/pkg/apis/kops/util"
|
|
)
|
|
|
|
// OptionsContext is the context object for options builders
|
|
type OptionsContext struct {
|
|
Cluster *kops.Cluster
|
|
}
|
|
|
|
// KubernetesVersion parses the semver version of kubernetes, from the cluster spec
|
|
func (c *OptionsContext) KubernetesVersion() (*semver.Version, error) {
|
|
kubernetesVersion := c.Cluster.Spec.KubernetesVersion
|
|
|
|
if kubernetesVersion == "" {
|
|
return nil, fmt.Errorf("KubernetesVersion is required")
|
|
}
|
|
|
|
sv, err := util.ParseKubernetesVersion(kubernetesVersion)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("unable to determine kubernetes version from %q", kubernetesVersion)
|
|
}
|
|
|
|
return sv, nil
|
|
}
|
|
|
|
// UsesKubenet returns true if our networking is derived from kubenet
|
|
func (c *OptionsContext) UsesKubenet() (bool, error) {
|
|
networking := c.Cluster.Spec.Networking
|
|
if networking == nil || networking.Classic != nil {
|
|
return false, nil
|
|
} else if networking.Kubenet != nil {
|
|
return true, nil
|
|
} else if networking.External != nil {
|
|
// external is based on kubenet
|
|
return true, nil
|
|
} else if networking.CNI != nil || networking.Weave != nil || networking.Flannel != nil || networking.Calico != nil || networking.Canal != nil {
|
|
return false, nil
|
|
} else if networking.Kopeio != nil {
|
|
// Kopeio is based on kubenet / external
|
|
return true, nil
|
|
} else {
|
|
return false, fmt.Errorf("No networking mode set")
|
|
}
|
|
}
|