mirror of https://github.com/kubernetes/kops.git
Add ability to set various cilium flags through CLI
Needed for a new e2e cilium test
This commit is contained in:
parent
b532a60917
commit
cf9a5c0289
|
|
@ -19,6 +19,7 @@ go_library(
|
|||
"//pkg/client/simple:go_default_library",
|
||||
"//pkg/featureflag:go_default_library",
|
||||
"//pkg/resources/digitalocean:go_default_library",
|
||||
"//upup/pkg/fi:go_default_library",
|
||||
"//upup/pkg/fi/cloudup:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/aliup:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/awstasks:go_default_library",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"k8s.io/kops/cmd/kops/util"
|
||||
api "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/featureflag"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
type SetClusterOptions struct {
|
||||
|
|
@ -145,6 +146,32 @@ func SetClusterFields(fields []string, cluster *api.Cluster, instanceGroups []*a
|
|||
}
|
||||
etcd.Manager.Image = kv[1]
|
||||
}
|
||||
case "cluster.spec.networking.cilium.ipam":
|
||||
createCiliumNetworking(cluster)
|
||||
cluster.Spec.Networking.Cilium.Ipam = kv[1]
|
||||
case "cluster.spec.networking.cilium.enableNodePort":
|
||||
createCiliumNetworking(cluster)
|
||||
v, err := strconv.ParseBool(kv[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown boolean value: %q", kv[1])
|
||||
}
|
||||
cluster.Spec.Networking.Cilium.EnableNodePort = v
|
||||
case "cluster.spec.networking.cilium.disableMasquerade":
|
||||
createCiliumNetworking(cluster)
|
||||
v, err := strconv.ParseBool(kv[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown boolean value: %q", kv[1])
|
||||
}
|
||||
cluster.Spec.Networking.Cilium.DisableMasquerade = v
|
||||
case "cluster.spec.kubeProxy.enabled":
|
||||
if cluster.Spec.KubeProxy == nil {
|
||||
cluster.Spec.KubeProxy = &api.KubeProxyConfig{}
|
||||
}
|
||||
v, err := strconv.ParseBool(kv[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown boolean value: %q", kv[1])
|
||||
}
|
||||
cluster.Spec.KubeProxy.Enabled = fi.Bool(v)
|
||||
default:
|
||||
return fmt.Errorf("unhandled field: %q", field)
|
||||
}
|
||||
|
|
@ -152,6 +179,15 @@ func SetClusterFields(fields []string, cluster *api.Cluster, instanceGroups []*a
|
|||
return nil
|
||||
}
|
||||
|
||||
func createCiliumNetworking(cluster *api.Cluster) {
|
||||
if cluster.Spec.Networking == nil {
|
||||
cluster.Spec.Networking = &api.NetworkingSpec{}
|
||||
}
|
||||
if cluster.Spec.Networking.Cilium == nil {
|
||||
cluster.Spec.Networking.Cilium = &api.CiliumNetworkingSpec{}
|
||||
}
|
||||
}
|
||||
|
||||
func toEtcdProviderType(in string) (api.EtcdProviderType, error) {
|
||||
s := strings.ToLower(in)
|
||||
switch s {
|
||||
|
|
|
|||
|
|
@ -70,3 +70,55 @@ func TestSetClusterFields(t *testing.T) {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCiliumFields(t *testing.T) {
|
||||
|
||||
grid := []struct {
|
||||
Fields []string
|
||||
Input kops.Cluster
|
||||
Output kops.Cluster
|
||||
}{
|
||||
{
|
||||
Fields: []string{
|
||||
"cluster.spec.networking.cilium.ipam=eni",
|
||||
"cluster.spec.networking.cilium.enableNodePort=true",
|
||||
"cluster.spec.networking.cilium.disableMasquerade=true",
|
||||
"cluster.spec.kubeProxy.enabled=false",
|
||||
},
|
||||
Input: kops.Cluster{
|
||||
Spec: kops.ClusterSpec{},
|
||||
},
|
||||
Output: kops.Cluster{
|
||||
Spec: kops.ClusterSpec{
|
||||
KubeProxy: &kops.KubeProxyConfig{
|
||||
Enabled: fi.Bool(false),
|
||||
},
|
||||
Networking: &kops.NetworkingSpec{
|
||||
Cilium: &kops.CiliumNetworkingSpec{
|
||||
Ipam: "eni",
|
||||
EnableNodePort: true,
|
||||
DisableMasquerade: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, g := range grid {
|
||||
var igs []*kops.InstanceGroup
|
||||
c := g.Input
|
||||
|
||||
err := SetClusterFields(g.Fields, &c, igs)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error from setClusterFields %v: %v", g.Fields, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(c, g.Output) {
|
||||
t.Errorf("unexpected output from setClusterFields %v. expected=%v, actual=%v", g.Fields, g.Output, c)
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue