From 0b78dbd14b70bd122037684f541eb5e45cea8b12 Mon Sep 17 00:00:00 2001 From: Saurabh Parekh Date: Sun, 3 Mar 2024 18:39:28 -0800 Subject: [PATCH] Fix lint warnings --- .../anywhere.eks.amazonaws.com_clusters.yaml | 2 +- config/manifest/eksa-components.yaml | 2 +- internal/pkg/api/cluster.go | 16 +++++++++------- pkg/api/v1alpha1/cluster.go | 6 +++--- pkg/api/v1alpha1/cluster_test.go | 2 +- pkg/api/v1alpha1/cluster_types.go | 6 +++--- pkg/api/v1alpha1/zz_generated.deepcopy.go | 4 ++-- pkg/clusterapi/extraargs.go | 3 ++- pkg/clusterapi/extraargs_test.go | 2 +- pkg/providers/cloudstack/template.go | 2 +- pkg/providers/docker/docker.go | 2 +- pkg/providers/nutanix/template.go | 2 +- pkg/providers/tinkerbell/template.go | 2 +- pkg/providers/vsphere/template.go | 2 +- test/e2e/cloudstack_test.go | 10 +++++----- test/e2e/vsphere_test.go | 10 +++++----- 16 files changed, 38 insertions(+), 35 deletions(-) diff --git a/config/crd/bases/anywhere.eks.amazonaws.com_clusters.yaml b/config/crd/bases/anywhere.eks.amazonaws.com_clusters.yaml index 116d66ddeefc9..0f323ebf4a009 100644 --- a/config/crd/bases/anywhere.eks.amazonaws.com_clusters.yaml +++ b/config/crd/bases/anywhere.eks.amazonaws.com_clusters.yaml @@ -154,7 +154,7 @@ spec: apiServerExtraArgs: additionalProperties: type: string - description: ApiServerExtraArgs defines the flags to configure + description: APIServerExtraArgs defines the flags to configure for the API server. type: object certSans: diff --git a/config/manifest/eksa-components.yaml b/config/manifest/eksa-components.yaml index d786e60298987..a113b8cabafff 100644 --- a/config/manifest/eksa-components.yaml +++ b/config/manifest/eksa-components.yaml @@ -3857,7 +3857,7 @@ spec: apiServerExtraArgs: additionalProperties: type: string - description: ApiServerExtraArgs defines the flags to configure + description: APIServerExtraArgs defines the flags to configure for the API server. type: object certSans: diff --git a/internal/pkg/api/cluster.go b/internal/pkg/api/cluster.go index 59d10383557f1..2bc6e273e979a 100644 --- a/internal/pkg/api/cluster.go +++ b/internal/pkg/api/cluster.go @@ -126,19 +126,21 @@ func WithControlPlaneLabel(key string, val string) ClusterFiller { } } -func WithControlPlaneApiServerExtraArgs(key string, val string) ClusterFiller { +// WithControlPlaneAPIServerExtraArgs adds the APIServerExtraArgs to the cluster spec. +func WithControlPlaneAPIServerExtraArgs(key string, val string) ClusterFiller { return func(c *anywherev1.Cluster) { - if c.Spec.ControlPlaneConfiguration.ApiServerExtraArgs == nil { - c.Spec.ControlPlaneConfiguration.ApiServerExtraArgs = map[string]string{} + if c.Spec.ControlPlaneConfiguration.APIServerExtraArgs == nil { + c.Spec.ControlPlaneConfiguration.APIServerExtraArgs = map[string]string{} } - c.Spec.ControlPlaneConfiguration.ApiServerExtraArgs[key] = val + c.Spec.ControlPlaneConfiguration.APIServerExtraArgs[key] = val } } -func RemoveAllApiServerExtraArgs() ClusterFiller { +// RemoveAllAPIServerExtraArgs removes all the API server flags from the cluster spec. +func RemoveAllAPIServerExtraArgs() ClusterFiller { return func(c *anywherev1.Cluster) { - for k := range c.Spec.ControlPlaneConfiguration.ApiServerExtraArgs { - delete(c.Spec.ControlPlaneConfiguration.ApiServerExtraArgs, k) + for k := range c.Spec.ControlPlaneConfiguration.APIServerExtraArgs { + delete(c.Spec.ControlPlaneConfiguration.APIServerExtraArgs, k) } } } diff --git a/pkg/api/v1alpha1/cluster.go b/pkg/api/v1alpha1/cluster.go index 459c5a61e3f6e..ac4d4b3fc6fba 100644 --- a/pkg/api/v1alpha1/cluster.go +++ b/pkg/api/v1alpha1/cluster.go @@ -190,7 +190,7 @@ var clusterConfigValidations = []func(*Cluster) error{ validatePackageControllerConfiguration, validateEksaVersion, validateControlPlaneCertSANs, - validateControlPlaneApiServerExtraArgs, + validateControlPlaneAPIServerExtraArgs, } // GetClusterConfig parses a Cluster object from a multiobject yaml file in disk @@ -495,9 +495,9 @@ func validateControlPlaneCertSANs(cfg *Cluster) error { return nil } -func validateControlPlaneApiServerExtraArgs(clusterConfig *Cluster) error { +func validateControlPlaneAPIServerExtraArgs(clusterConfig *Cluster) error { allowedFlags := map[string]string{"service-account-issuer": "", "service-account-jwks-uri": ""} - for k := range clusterConfig.Spec.ControlPlaneConfiguration.ApiServerExtraArgs { + for k := range clusterConfig.Spec.ControlPlaneConfiguration.APIServerExtraArgs { if _, ok := allowedFlags[k]; !ok { return fmt.Errorf("invalid argument in ControlPlaneConfiguration.APIServerExtraArgs (service-account-issuer, service-account-jwks-uri): %v", k) } diff --git a/pkg/api/v1alpha1/cluster_test.go b/pkg/api/v1alpha1/cluster_test.go index 7d58bb21c9499..8947b9385394f 100644 --- a/pkg/api/v1alpha1/cluster_test.go +++ b/pkg/api/v1alpha1/cluster_test.go @@ -849,7 +849,7 @@ func TestGetAndValidateClusterConfig(t *testing.T) { Kind: VSphereMachineConfigKind, Name: "eksa-unit-test", }, - ApiServerExtraArgs: map[string]string{ + APIServerExtraArgs: map[string]string{ "service-account-issuer": "https://test-issuer-url", "service-account-jwks-uri": "https://test-issuer-url/openid/v1/jwks", }, diff --git a/pkg/api/v1alpha1/cluster_types.go b/pkg/api/v1alpha1/cluster_types.go index dcc01c8f41209..4173209b3cfe3 100644 --- a/pkg/api/v1alpha1/cluster_types.go +++ b/pkg/api/v1alpha1/cluster_types.go @@ -307,8 +307,8 @@ type ControlPlaneConfiguration struct { CertSANs []string `json:"certSans,omitempty"` // MachineHealthCheck is a control-plane level override for the timeouts and maxUnhealthy specified in the top-level MHC configuration. If not configured, the defaults in the top-level MHC configuration are used. MachineHealthCheck *MachineHealthCheck `json:"machineHealthCheck,omitempty"` - // ApiServerExtraArgs defines the flags to configure for the API server. - ApiServerExtraArgs map[string]string `json:"apiServerExtraArgs,omitempty"` + // APIServerExtraArgs defines the flags to configure for the API server. + APIServerExtraArgs map[string]string `json:"apiServerExtraArgs,omitempty"` } // MachineHealthCheck allows to configure timeouts for machine health checks. Machine Health Checks are responsible for remediating unhealthy Machines. @@ -365,7 +365,7 @@ func (n *ControlPlaneConfiguration) Equal(o *ControlPlaneConfiguration) bool { } return n.Count == o.Count && n.MachineGroupRef.Equal(o.MachineGroupRef) && TaintsSliceEqual(n.Taints, o.Taints) && MapEqual(n.Labels, o.Labels) && - SliceEqual(n.CertSANs, o.CertSANs) && MapEqual(n.ApiServerExtraArgs, o.ApiServerExtraArgs) + SliceEqual(n.CertSANs, o.CertSANs) && MapEqual(n.APIServerExtraArgs, o.APIServerExtraArgs) } type Endpoint struct { diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/pkg/api/v1alpha1/zz_generated.deepcopy.go index f0cef8fb212c2..e77f5f7440482 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/api/v1alpha1/zz_generated.deepcopy.go @@ -878,8 +878,8 @@ func (in *ControlPlaneConfiguration) DeepCopyInto(out *ControlPlaneConfiguration *out = new(MachineHealthCheck) (*in).DeepCopyInto(*out) } - if in.ApiServerExtraArgs != nil { - in, out := &in.ApiServerExtraArgs, &out.ApiServerExtraArgs + if in.APIServerExtraArgs != nil { + in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs *out = make(map[string]string, len(*in)) for key, val := range *in { (*out)[key] = val diff --git a/pkg/clusterapi/extraargs.go b/pkg/clusterapi/extraargs.go index 4b10bb53be05d..2ae614dbac27c 100644 --- a/pkg/clusterapi/extraargs.go +++ b/pkg/clusterapi/extraargs.go @@ -53,7 +53,8 @@ func EtcdEncryptionExtraArgs(config *[]v1alpha1.EtcdEncryption) ExtraArgs { return args } -func ApiServerExtraArgs(apiServerExtraArgs map[string]string) ExtraArgs { +// APIServerExtraArgs takes a map of API Server extra args and returns the relevant API server extra args if it's not nil or empty. +func APIServerExtraArgs(apiServerExtraArgs map[string]string) ExtraArgs { args := ExtraArgs{} for k, v := range apiServerExtraArgs { args.AddIfNotEmpty(k, v) diff --git a/pkg/clusterapi/extraargs_test.go b/pkg/clusterapi/extraargs_test.go index 30762955d577f..2484589823262 100644 --- a/pkg/clusterapi/extraargs_test.go +++ b/pkg/clusterapi/extraargs_test.go @@ -205,7 +205,7 @@ func TestApiServerExtraArgs(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { - if got := clusterapi.ApiServerExtraArgs(tt.apiServerExtraArgs); !reflect.DeepEqual(got, tt.want) { + if got := clusterapi.APIServerExtraArgs(tt.apiServerExtraArgs); !reflect.DeepEqual(got, tt.want) { t.Errorf("ApiServerExtraArgs() = %v, want %v", got, tt.want) } }) diff --git a/pkg/providers/cloudstack/template.go b/pkg/providers/cloudstack/template.go index ff46da30332ee..d6ad013bf239a 100644 --- a/pkg/providers/cloudstack/template.go +++ b/pkg/providers/cloudstack/template.go @@ -123,7 +123,7 @@ func buildTemplateMapCP(clusterSpec *cluster.Spec) (map[string]interface{}, erro Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)). Append(clusterapi.PodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig)). Append(clusterapi.EtcdEncryptionExtraArgs(clusterSpec.Cluster.Spec.EtcdEncryption)). - Append(clusterapi.ApiServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.ApiServerExtraArgs)). + Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs)). Append(sharedExtraArgs) controllerManagerExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs(). diff --git a/pkg/providers/docker/docker.go b/pkg/providers/docker/docker.go index b07e623e0154f..52042b03f9fca 100644 --- a/pkg/providers/docker/docker.go +++ b/pkg/providers/docker/docker.go @@ -295,7 +295,7 @@ func buildTemplateMapCP(clusterSpec *cluster.Spec) (map[string]interface{}, erro apiServerExtraArgs := clusterapi.OIDCToExtraArgs(clusterSpec.OIDCConfig). Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)). Append(clusterapi.PodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig)). - Append(clusterapi.ApiServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.ApiServerExtraArgs)). + Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs)). Append(sharedExtraArgs) controllerManagerExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs(). Append(clusterapi.NodeCIDRMaskExtraArgs(&clusterSpec.Cluster.Spec.ClusterNetwork)) diff --git a/pkg/providers/nutanix/template.go b/pkg/providers/nutanix/template.go index 8b145dd9584c5..10564ff78d841 100644 --- a/pkg/providers/nutanix/template.go +++ b/pkg/providers/nutanix/template.go @@ -163,7 +163,7 @@ func buildTemplateMapCP( Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)). Append(clusterapi.PodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig)). Append(clusterapi.EtcdEncryptionExtraArgs(clusterSpec.Cluster.Spec.EtcdEncryption)). - Append(clusterapi.ApiServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.ApiServerExtraArgs)) + Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs)) kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs(). Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf)). Append(clusterapi.ControlPlaneNodeLabelsExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration)) diff --git a/pkg/providers/tinkerbell/template.go b/pkg/providers/tinkerbell/template.go index 4ab6096e32c54..645c22eca2981 100644 --- a/pkg/providers/tinkerbell/template.go +++ b/pkg/providers/tinkerbell/template.go @@ -400,7 +400,7 @@ func buildTemplateMapCP( apiServerExtraArgs := clusterapi.OIDCToExtraArgs(clusterSpec.OIDCConfig). Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)). Append(clusterapi.PodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig)). - Append(clusterapi.ApiServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.ApiServerExtraArgs)) + Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs)) kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs(). Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf)). diff --git a/pkg/providers/vsphere/template.go b/pkg/providers/vsphere/template.go index c832a0c178c3f..903ff4020f9b0 100644 --- a/pkg/providers/vsphere/template.go +++ b/pkg/providers/vsphere/template.go @@ -145,7 +145,7 @@ func buildTemplateMapCP( Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)). Append(clusterapi.PodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig)). Append(clusterapi.EtcdEncryptionExtraArgs(clusterSpec.Cluster.Spec.EtcdEncryption)). - Append(clusterapi.ApiServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.ApiServerExtraArgs)). + Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs)). Append(sharedExtraArgs) controllerManagerExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs(). Append(clusterapi.NodeCIDRMaskExtraArgs(&clusterSpec.Cluster.Spec.ClusterNetwork)) diff --git a/test/e2e/cloudstack_test.go b/test/e2e/cloudstack_test.go index f58827806c026..f32dc465fda20 100644 --- a/test/e2e/cloudstack_test.go +++ b/test/e2e/cloudstack_test.go @@ -23,8 +23,8 @@ func TestCloudStackKubernetes129RedHat8ApiServerExtraArgsSimpleFlow(t *testing.T t, framework.NewCloudStack(t, framework.WithCloudStackRedhat129()), framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube129)), - framework.WithClusterFiller(api.WithControlPlaneApiServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url")), - framework.WithClusterFiller(api.WithControlPlaneApiServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks")), + framework.WithClusterFiller(api.WithControlPlaneAPIServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url")), + framework.WithClusterFiller(api.WithControlPlaneAPIServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks")), ) runSimpleFlow(test) } @@ -40,14 +40,14 @@ func TestCloudStackKubernetes129Redhat8ApiServerExtraArgsUpgradeFlow(t *testing. addApiServerExtraArgsclusterOpts = append( addApiServerExtraArgsclusterOpts, framework.WithClusterUpgrade( - api.WithControlPlaneApiServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url"), - api.WithControlPlaneApiServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks"), + api.WithControlPlaneAPIServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url"), + api.WithControlPlaneAPIServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks"), ), ) removeApiServerExtraArgsclusterOpts = append( removeApiServerExtraArgsclusterOpts, framework.WithClusterUpgrade( - api.RemoveAllApiServerExtraArgs(), + api.RemoveAllAPIServerExtraArgs(), ), ) runApiServerExtraArgsUpgradeFlow( diff --git a/test/e2e/vsphere_test.go b/test/e2e/vsphere_test.go index 07fa3f45dca5a..795ea425c47a5 100644 --- a/test/e2e/vsphere_test.go +++ b/test/e2e/vsphere_test.go @@ -24,8 +24,8 @@ func TestVSphereKubernetes129BottlerocketApiServerExtraArgsSimpleFlow(t *testing t, framework.NewVSphere(t, framework.WithBottleRocket129()), framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube129)), - framework.WithClusterFiller(api.WithControlPlaneApiServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url")), - framework.WithClusterFiller(api.WithControlPlaneApiServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks")), + framework.WithClusterFiller(api.WithControlPlaneAPIServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url")), + framework.WithClusterFiller(api.WithControlPlaneAPIServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks")), ) runSimpleFlow(test) } @@ -41,14 +41,14 @@ func TestVSphereKubernetes129BottlerocketApiServerExtraArgsUpgradeFlow(t *testin addApiServerExtraArgsclusterOpts = append( addApiServerExtraArgsclusterOpts, framework.WithClusterUpgrade( - api.WithControlPlaneApiServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url"), - api.WithControlPlaneApiServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks"), + api.WithControlPlaneAPIServerExtraArgs("service-account-issuer", "https://my-custom-issuer-url"), + api.WithControlPlaneAPIServerExtraArgs("service-account-jwks-uri", "https://my-custom-issuer-url/openid/v1/jwks"), ), ) removeApiServerExtraArgsclusterOpts = append( removeApiServerExtraArgsclusterOpts, framework.WithClusterUpgrade( - api.RemoveAllApiServerExtraArgs(), + api.RemoveAllAPIServerExtraArgs(), ), ) runApiServerExtraArgsUpgradeFlow(