diff --git a/pkg/api/v1alpha1/cluster.go b/pkg/api/v1alpha1/cluster.go index aa750a011da3..18696fabb266 100644 --- a/pkg/api/v1alpha1/cluster.go +++ b/pkg/api/v1alpha1/cluster.go @@ -576,6 +576,10 @@ func validateKubeletConfiguration(eksakubeconfig *unstructured.Unstructured) err return fmt.Errorf("unmarshaling KubeletConfiguration for %v", err) } + if _, ok := eksakubeconfig.Object["providerID"]; ok { + return errors.New("can not override providerID or cloudProvider (set by EKS Anywhere)") + } + return nil } diff --git a/pkg/api/v1alpha1/cluster_test.go b/pkg/api/v1alpha1/cluster_test.go index 941484bb41cb..8277d24ee73d 100644 --- a/pkg/api/v1alpha1/cluster_test.go +++ b/pkg/api/v1alpha1/cluster_test.go @@ -1177,7 +1177,7 @@ func TestValidateClusterConfigContent(t *testing.T) { } c.Spec.WorkerNodeGroupConfigurations[0].KubeletConfiguration = &unstructured.Unstructured{ Object: map[string]interface{}{ - "maxPods": 20, + "maxPods": 25, "apiVersion": "kubelet.config.k8s.io/v1beta1", "kind": "KubeletConfiguration", }, @@ -1213,6 +1213,52 @@ func TestValidateClusterConfigContent(t *testing.T) { wantErr: true, err: "unknown field", }, + { + testName: "providerid error", + cluster: baseCluster(func(c *Cluster) { + c.Spec.WorkerNodeGroupConfigurations[0].KubeletConfiguration = &unstructured.Unstructured{ + Object: map[string]interface{}{ + "maxPods": 20, + "apiVersion": "kubelet.config.k8s.io/v1beta1", + "kind": "KubeletConfiguration", + "providerID": "provider id", + }, + } + c.Spec.ControlPlaneConfiguration.KubeletConfiguration = &unstructured.Unstructured{ + Object: map[string]interface{}{ + "maxPods": 20, + "apiVersion": "kubelet.config.k8s.io/v1beta1", + "kind": "KubeletConfiguration", + "providerID": "provider id", + }, + } + }), + wantErr: true, + err: "can not override providerID or cloudProvider", + }, + { + testName: "providerid error", + cluster: baseCluster(func(c *Cluster) { + c.Spec.WorkerNodeGroupConfigurations[0].KubeletConfiguration = &unstructured.Unstructured{ + Object: map[string]interface{}{ + "maxPods": 20, + "apiVersion": "kubelet.config.k8s.io/v1beta1", + "kind": "KubeletConfiguration", + "cloudProvider": "external", + }, + } + c.Spec.ControlPlaneConfiguration.KubeletConfiguration = &unstructured.Unstructured{ + Object: map[string]interface{}{ + "maxPods": 20, + "apiVersion": "kubelet.config.k8s.io/v1beta1", + "kind": "KubeletConfiguration", + "cloudProvider": "external", + }, + } + }), + wantErr: true, + err: "unknown field \"cloudProvider\"", + }, } for _, tt := range tests {