From 196afeb9283fa387c1cc4c64926b265306ff5ab6 Mon Sep 17 00:00:00 2001 From: Devinwong Date: Fri, 15 Nov 2024 15:32:36 -0800 Subject: [PATCH] chore: rename nbcontract to AKSNodeConfig (#5276) --- aks-node-controller/README.md | 2 +- aks-node-controller/app_test.go | 8 +- aks-node-controller/parser/helper.go | 8 +- aks-node-controller/parser/parser_test.go | 124 +++++++++--------- ...{test_nbc.json => test_aksnodeconfig.json} | 0 ...=> test_aksnodeconfig_fields_missing.json} | 0 ...test_aksnodeconfig_fields_unexpected.json} | 0 aks-node-controller/test_helpers.go | 13 +- apiserver/getnodebootstrapdata.go | 2 +- e2e/cluster.go | 2 +- e2e/node_bootstrapper_test.go | 2 +- e2e/template.go | 2 +- e2e/vmss.go | 2 +- pkg/proto/aksnodeconfig/v1/README.md | 2 +- pkg/proto/aksnodeconfig/v1/helper.go | 67 +++++----- pkg/proto/aksnodeconfig/v1/helper_test.go | 43 +++--- 16 files changed, 132 insertions(+), 145 deletions(-) rename aks-node-controller/parser/testdata/{test_nbc.json => test_aksnodeconfig.json} (100%) rename aks-node-controller/parser/testdata/{test_nbc_fields_missing.json => test_aksnodeconfig_fields_missing.json} (100%) rename aks-node-controller/parser/testdata/{test_nbc_fields_unexpected.json => test_aksnodeconfig_fields_unexpected.json} (100%) diff --git a/aks-node-controller/README.md b/aks-node-controller/README.md index 0dd89324991..ebb3cf53c54 100644 --- a/aks-node-controller/README.md +++ b/aks-node-controller/README.md @@ -13,7 +13,7 @@ AKS Node Controller relies on two Azure mechanisms to inject the necessary data Here is an example on how to retrieve node bootstrapping params and pass in the returned `CSE` and `CustomData` to CRP API for creating a VMSS instance. ```go -builder := aksnodeconfigv1.NewNBContractBuilder() +builder := aksnodeconfigv1.NewAKSNodeConfigBuilder() builder.ApplyConfiguration(aksNodeConfig) nodeBootstrapping, err = builder.GetNodeBootstrapping() diff --git a/aks-node-controller/app_test.go b/aks-node-controller/app_test.go index 3b0e447f2a3..6094861d11c 100644 --- a/aks-node-controller/app_test.go +++ b/aks-node-controller/app_test.go @@ -61,7 +61,7 @@ func TestApp_Run(t *testing.T) { }, { name: "provision command with valid flag", - args: []string{"aks-node-controller", "provision", "--provision-config=parser/testdata/test_nbc.json"}, + args: []string{"aks-node-controller", "provision", "--provision-config=parser/testdata/test_aksnodeconfig.json"}, setupMocks: func(mc *MockCmdRunner) { mc.RunFunc = func(cmd *exec.Cmd) error { return nil @@ -71,7 +71,7 @@ func TestApp_Run(t *testing.T) { }, { name: "provision command with command runner error", - args: []string{"aks-node-controller", "provision", "--provision-config=parser/testdata/test_nbc.json"}, + args: []string{"aks-node-controller", "provision", "--provision-config=parser/testdata/test_aksnodeconfig.json"}, setupMocks: func(mc *MockCmdRunner) { mc.RunFunc = func(cmd *exec.Cmd) error { return &ExitError{Code: 666} @@ -107,7 +107,7 @@ func TestApp_Provision(t *testing.T) { }{ { name: "valid provision config", - flags: ProvisionFlags{ProvisionConfig: "parser/testdata/test_nbc.json"}, + flags: ProvisionFlags{ProvisionConfig: "parser/testdata/test_aksnodeconfig.json"}, wantErr: false, }, { @@ -117,7 +117,7 @@ func TestApp_Provision(t *testing.T) { }, { name: "command runner error", - flags: ProvisionFlags{ProvisionConfig: "parser/testdata/test_nbc.json"}, + flags: ProvisionFlags{ProvisionConfig: "parser/testdata/test_aksnodeconfig.json"}, setupMocks: func(mc *MockCmdRunner) { mc.RunFunc = func(cmd *exec.Cmd) error { return errors.New("command runner error") diff --git a/aks-node-controller/parser/helper.go b/aks-node-controller/parser/helper.go index 323d780dda8..1c51bbc44b5 100644 --- a/aks-node-controller/parser/helper.go +++ b/aks-node-controller/parser/helper.go @@ -143,7 +143,7 @@ func getContainerdConfig(aksnodeconfig *aksnodeconfigv1.Configuration) string { return "" } - containerdConfig, err := containerdConfigFromNodeBootstrapContract(aksnodeconfig) + containerdConfig, err := containerdConfigFromAKSNodeConfig(aksnodeconfig) if err != nil { return fmt.Sprintf("error getting containerd config from node bootstrap variables: %v", err) } @@ -151,14 +151,14 @@ func getContainerdConfig(aksnodeconfig *aksnodeconfigv1.Configuration) string { return base64.StdEncoding.EncodeToString([]byte(containerdConfig)) } -func containerdConfigFromNodeBootstrapContract(aksnodeconfig *aksnodeconfigv1.Configuration) (string, error) { +func containerdConfigFromAKSNodeConfig(aksnodeconfig *aksnodeconfigv1.Configuration) (string, error) { if aksnodeconfig == nil { - return "", fmt.Errorf("node bootstrap contract is nil") + return "", fmt.Errorf("AKSNodeConfig is nil") } var buffer bytes.Buffer if err := containerdConfigTemplate.Execute(&buffer, aksnodeconfig); err != nil { - return "", fmt.Errorf("error executing containerd config template for NBContract: %w", err) + return "", fmt.Errorf("error executing containerd config template for AKSNodeConfig: %w", err) } return buffer.String(), nil diff --git a/aks-node-controller/parser/parser_test.go b/aks-node-controller/parser/parser_test.go index 6dcc8c51bb0..b75305a97b6 100644 --- a/aks-node-controller/parser/parser_test.go +++ b/aks-node-controller/parser/parser_test.go @@ -24,21 +24,21 @@ const encodedTestCert = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUgvVENDQmVXZ0F func TestBuildCSECmd(t *testing.T) { tests := []struct { - name string - folder string - k8sVersion string - nbcUpdator func(*aksnodeconfigv1.Configuration) - validator func(cmd *exec.Cmd) + name string + folder string + k8sVersion string + aKSNodeConfigUpdator func(*aksnodeconfigv1.Configuration) + validator func(cmd *exec.Cmd) }{ { name: "AKSUbuntu2204 containerd with multi-instance GPU", folder: "AKSUbuntu2204+Containerd+MIG", k8sVersion: "1.19.13", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.GpuConfig.GpuInstanceProfile = "MIG7g" + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.GpuConfig.GpuInstanceProfile = "MIG7g" // Skip GPU driver install - nbc.GpuConfig.EnableNvidia = to.BoolPtr(false) - nbc.VmSize = "Standard_ND96asr_v4" + aksNodeConfig.GpuConfig.EnableNvidia = to.BoolPtr(false) + aksNodeConfig.VmSize = "Standard_ND96asr_v4" }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -76,8 +76,8 @@ oom_score = 0 name: "AKSUbuntu2204 DisableSSH with enabled ssh", folder: "AKSUbuntu2204+SSHStatusOn", k8sVersion: "1.24.2", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.EnableSsh = to.BoolPtr(true) + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.EnableSsh = to.BoolPtr(true) }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -88,9 +88,9 @@ oom_score = 0 name: "AKSUbuntu2204 in China", folder: "AKSUbuntu2204+China", k8sVersion: "1.24.2", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.ClusterConfig.Location = "chinaeast2" - nbc.CustomCloudConfig.CustomCloudEnvName = "AzureChinaCloud" + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.ClusterConfig.Location = "chinaeast2" + aksNodeConfig.CustomCloudConfig.CustomCloudEnvName = "AzureChinaCloud" }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -103,8 +103,8 @@ oom_score = 0 name: "AKSUbuntu2204 with custom cloud", folder: "AKSUbuntu2204+CustomCloud", k8sVersion: "1.24.2", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.CustomCloudConfig.CustomCloudEnvName = aksnodeconfigv1.AksCustomCloudName + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.CustomCloudConfig.CustomCloudEnvName = aksnodeconfigv1.AksCustomCloudName }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -117,8 +117,8 @@ oom_score = 0 name: "AKSUbuntu2204 with custom osConfig", folder: "AKSUbuntu2204+CustomOSConfig", k8sVersion: "1.24.2", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.CustomLinuxOsConfig = &aksnodeconfigv1.CustomLinuxOSConfig{ + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.CustomLinuxOsConfig = &aksnodeconfigv1.CustomLinuxOSConfig{ EnableSwapConfig: true, SwapFileSize: int32(1500), TransparentHugepageSupport: "never", @@ -150,10 +150,10 @@ oom_score = 0 name: "AzureLinux v2 with kata and DisableUnattendedUpgrades=false", folder: "AzureLinuxv2+Kata+DisableUnattendedUpgrades=false", k8sVersion: "1.28.0", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.IsKata = true - nbc.EnableUnattendedUpgrade = true - nbc.NeedsCgroupv2 = to.BoolPtr(true) + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.IsKata = true + aksNodeConfig.EnableUnattendedUpgrade = true + aksNodeConfig.NeedsCgroupv2 = to.BoolPtr(true) }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -166,8 +166,8 @@ oom_score = 0 name: "AKSUbuntu1804 with containerd and kubenet cni", folder: "AKSUbuntu1804+Containerd+Kubenet", k8sVersion: "1.19.13", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.NetworkConfig.NetworkPlugin = aksnodeconfigv1.GetNetworkPluginType(aksnodeconfigv1.NetworkPluginKubenet) + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.NetworkConfig.NetworkPlugin = aksnodeconfigv1.GetNetworkPluginType(aksnodeconfigv1.NetworkPluginKubenet) }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -179,8 +179,8 @@ oom_score = 0 name: "AKSUbuntu1804 with http proxy config", folder: "AKSUbuntu1804+HTTPProxy", k8sVersion: "1.18.14", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.HttpProxyConfig = &aksnodeconfigv1.HTTPProxyConfig{ + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.HttpProxyConfig = &aksnodeconfigv1.HTTPProxyConfig{ HttpProxy: "http://myproxy.server.com:8080/", HttpsProxy: "https://myproxy.server.com:8080/", NoProxyEntries: []string{ @@ -200,8 +200,8 @@ oom_score = 0 name: "AKSUbuntu1804 with custom ca trust", folder: "AKSUbuntu1804+CustomCATrust", k8sVersion: "1.18.14", - nbcUpdator: func(nbc *aksnodeconfigv1.Configuration) { - nbc.CustomCaCerts = []string{encodedTestCert, encodedTestCert, encodedTestCert} + aKSNodeConfigUpdator: func(aksNodeConfig *aksnodeconfigv1.Configuration) { + aksNodeConfig.CustomCaCerts = []string{encodedTestCert, encodedTestCert, encodedTestCert} }, validator: func(cmd *exec.Cmd) { vars := environToMap(cmd.Env) @@ -288,8 +288,8 @@ oom_score = 0 } aksnodeconfigv1.ValidateAndSetLinuxKubeletFlags(kubeletConfig, cs, agentPool) - nBCB := aksnodeconfigv1.NewNBContractBuilder() - nbc := &aksnodeconfigv1.Configuration{ + aKSNodeConfigBuilder := aksnodeconfigv1.NewAKSNodeConfigBuilder() + aksNodeConfig := &aksnodeconfigv1.Configuration{ LinuxAdminUsername: "azureuser", VmSize: "Standard_DS1_v2", ClusterConfig: &aksnodeconfigv1.ClusterConfig{ @@ -331,14 +331,14 @@ oom_score = 0 KubeletNodeLabels: aksnodeconfigv1.GetKubeletNodeLabels(agentPool), }, } - nBCB.ApplyConfiguration(nbc) - nbc = nBCB.GetNodeBootstrapConfig() + aKSNodeConfigBuilder.ApplyConfiguration(aksNodeConfig) + aksNodeConfig = aKSNodeConfigBuilder.GetAKSNodeConfig() - if tt.nbcUpdator != nil { - tt.nbcUpdator(nbc) + if tt.aKSNodeConfigUpdator != nil { + tt.aKSNodeConfigUpdator(aksNodeConfig) } - cseCMD, err := parser.BuildCSECmd(context.TODO(), nBCB.GetNodeBootstrapConfig()) + cseCMD, err := parser.BuildCSECmd(context.TODO(), aKSNodeConfigBuilder.GetAKSNodeConfig()) require.NoError(t, err) generateTestDataIfRequested(t, tt.folder, cseCMD) @@ -350,7 +350,7 @@ oom_score = 0 } } -func TestNBContractCompatibilityFromJsonToCSECommand(t *testing.T) { +func TestAKSNodeConfigCompatibilityFromJsonToCSECommand(t *testing.T) { tests := []struct { name string folder string @@ -404,10 +404,10 @@ func TestNBContractCompatibilityFromJsonToCSECommand(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - nBCB := aksnodeconfigv1.NewNBContractBuilder() - nBCB.ApplyConfiguration(&aksnodeconfigv1.Configuration{}) + aKSNodeConfigBuilder := aksnodeconfigv1.NewAKSNodeConfigBuilder() + aKSNodeConfigBuilder.ApplyConfiguration(&aksnodeconfigv1.Configuration{}) - cseCMD, err := parser.BuildCSECmd(context.TODO(), nBCB.GetNodeBootstrapConfig()) + cseCMD, err := parser.BuildCSECmd(context.TODO(), aKSNodeConfigBuilder.GetAKSNodeConfig()) require.NoError(t, err) generateTestDataIfRequested(t, tt.folder, cseCMD) @@ -432,47 +432,47 @@ func environToMap(env []string) map[string]string { func TestContractCompatibilityHandledByProtobuf(t *testing.T) { tests := []struct { - name string - nbcUTFilePath string - validator func(*aksnodeconfigv1.Configuration, *aksnodeconfigv1.Configuration) + name string + aKSNodeConfigUTFilePath string + validator func(*aksnodeconfigv1.Configuration, *aksnodeconfigv1.Configuration) }{ { - name: "with unexpected new fields in json should be ignored", - nbcUTFilePath: "./testdata/test_nbc_fields_unexpected.json", - validator: func(nbcExpected *aksnodeconfigv1.Configuration, nbcUT *aksnodeconfigv1.Configuration) { + name: "with unexpected new fields in json should be ignored", + aKSNodeConfigUTFilePath: "./testdata/test_aksnodeconfig_fields_unexpected.json", + validator: func(aKSNodeConfigExpected *aksnodeconfigv1.Configuration, aKSNodeConfigUT *aksnodeconfigv1.Configuration) { // The unexpected fields will natively be ignored when unmarshalling the json to the contract object. // We use this test to ensure it. - assert.Equal(t, nbcExpected, nbcUT) + assert.Equal(t, aKSNodeConfigExpected, aKSNodeConfigUT) }, }, { - name: "with missing fields in json should be set with default values", - nbcUTFilePath: "./testdata/test_nbc_fields_missing.json", - validator: func(_ *aksnodeconfigv1.Configuration, nbcUT *aksnodeconfigv1.Configuration) { + name: "with missing fields in json should be set with default values", + aKSNodeConfigUTFilePath: "./testdata/test_aksnodeconfig_fields_missing.json", + validator: func(_ *aksnodeconfigv1.Configuration, aKSNodeConfigUT *aksnodeconfigv1.Configuration) { // if a string field is unset, it will be set to empty string by protobuf by default - assert.Equal(t, "", nbcUT.GetLinuxAdminUsername()) + assert.Equal(t, "", aKSNodeConfigUT.GetLinuxAdminUsername()) // if an optional (explicit presence) bool field is unset, it will be set to nil by protobuf by default. // Here we don't use the getter because getter is nil safe and will default to false. - assert.Nil(t, nbcUT.IsVhd) + assert.Nil(t, aKSNodeConfigUT.IsVhd) // if an optional (explicit presence) field is unset, it will be set to nil by protobuf by default. // Here we don't use the getter because getter is nil safe and will default to false. - assert.Nil(t, nbcUT.ClusterConfig.LoadBalancerConfig.ExcludeMasterFromStandardLoadBalancer) + assert.Nil(t, aKSNodeConfigUT.ClusterConfig.LoadBalancerConfig.ExcludeMasterFromStandardLoadBalancer) // if an optional enum field is unset, it will be set to 0 (in this case LoadBalancerConfig_UNSPECIFIED) by protobuf by default. - assert.Equal(t, aksnodeconfigv1.LoadBalancerConfig_UNSPECIFIED, nbcUT.ClusterConfig.LoadBalancerConfig.GetLoadBalancerSku()) + assert.Equal(t, aksnodeconfigv1.LoadBalancerConfig_UNSPECIFIED, aKSNodeConfigUT.ClusterConfig.LoadBalancerConfig.GetLoadBalancerSku()) }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - nbcExpected := getNBCInstance("./testdata/test_nbc.json") - nbcUT := getNBCInstance(tt.nbcUTFilePath) + aKSNodeConfigExpected := getaKSNodeConfigInstance("./testdata/test_aksnodeconfig.json") + aKSNodeConfigUT := getaKSNodeConfigInstance(tt.aKSNodeConfigUTFilePath) if tt.validator != nil { - tt.validator(nbcExpected, nbcUT) + tt.validator(aKSNodeConfigExpected, aKSNodeConfigUT) } }) } @@ -487,18 +487,18 @@ func getBase64DecodedValue(data []byte) (string, error) { return string(decoded), nil } -func getNBCInstance(jsonFilePath string) *aksnodeconfigv1.Configuration { - nBCB := aksnodeconfigv1.NewNBContractBuilder() - nbc := aksnodeconfigv1.Configuration{} +func getaKSNodeConfigInstance(jsonFilePath string) *aksnodeconfigv1.Configuration { + aKSNodeConfigBuilder := aksnodeconfigv1.NewAKSNodeConfigBuilder() + aksNodeConfig := aksnodeconfigv1.Configuration{} content, err := os.ReadFile(jsonFilePath) if err != nil { log.Fatal(err) } - if err = json.Unmarshal(content, &nbc); err != nil { + if err = json.Unmarshal(content, &aksNodeConfig); err != nil { log.Printf("Failed to unmarshal the aksnodeconfigv1 from json: %v", err) } - nBCB.ApplyConfiguration(&nbc) - return nBCB.GetNodeBootstrapConfig() + aKSNodeConfigBuilder.ApplyConfiguration(&aksNodeConfig) + return aKSNodeConfigBuilder.GetAKSNodeConfig() } func generateTestDataIfRequested(t *testing.T, folder string, cmd *exec.Cmd) { diff --git a/aks-node-controller/parser/testdata/test_nbc.json b/aks-node-controller/parser/testdata/test_aksnodeconfig.json similarity index 100% rename from aks-node-controller/parser/testdata/test_nbc.json rename to aks-node-controller/parser/testdata/test_aksnodeconfig.json diff --git a/aks-node-controller/parser/testdata/test_nbc_fields_missing.json b/aks-node-controller/parser/testdata/test_aksnodeconfig_fields_missing.json similarity index 100% rename from aks-node-controller/parser/testdata/test_nbc_fields_missing.json rename to aks-node-controller/parser/testdata/test_aksnodeconfig_fields_missing.json diff --git a/aks-node-controller/parser/testdata/test_nbc_fields_unexpected.json b/aks-node-controller/parser/testdata/test_aksnodeconfig_fields_unexpected.json similarity index 100% rename from aks-node-controller/parser/testdata/test_nbc_fields_unexpected.json rename to aks-node-controller/parser/testdata/test_aksnodeconfig_fields_unexpected.json diff --git a/aks-node-controller/test_helpers.go b/aks-node-controller/test_helpers.go index f346a1004ea..b83d3854806 100644 --- a/aks-node-controller/test_helpers.go +++ b/aks-node-controller/test_helpers.go @@ -4,22 +4,11 @@ import ( "github.com/Azure/agentbaker/pkg/agent/datamodel" ) -//func getFile(t *testing.T, nbc *datamodel.NodeBootstrappingConfiguration, path string, expectedMode fs.FileMode) string { -// t.Helper() -// files, err := customData(nbc) -// require.NoError(t, err) -// require.Contains(t, files, path) -// actual := files[path] -// assert.Equal(t, expectedMode, actual.Mode) -// -// return actual.Content -//} - func Ptr[T any](input T) *T { return &input } -func validNBC() *datamodel.NodeBootstrappingConfiguration { +func validAKSNodeConfig() *datamodel.NodeBootstrappingConfiguration { return &datamodel.NodeBootstrappingConfiguration{ ContainerService: &datamodel.ContainerService{ Properties: &datamodel.Properties{ diff --git a/apiserver/getnodebootstrapdata.go b/apiserver/getnodebootstrapdata.go index 345e82b7b41..328fe9ddbd5 100644 --- a/apiserver/getnodebootstrapdata.go +++ b/apiserver/getnodebootstrapdata.go @@ -18,7 +18,7 @@ const ( defaultTimeout = 30 * time.Second ) -// GetNodeBootstrapConfig endpoint for getting node bootstrapping data. +// GetNodeBootstrapData endpoint for getting node bootstrapping data. func (api *APIServer) GetNodeBootstrapData(w http.ResponseWriter, r *http.Request) { ctx := r.Context() ctx, cancel := context.WithTimeout(ctx, defaultTimeout) diff --git a/e2e/cluster.go b/e2e/cluster.go index 3814171d25d..0fdd6eb7f43 100644 --- a/e2e/cluster.go +++ b/e2e/cluster.go @@ -137,7 +137,7 @@ func prepareCluster(ctx context.Context, t *testing.T, cluster *armcontainerserv SubnetID: subnetID, NodeBootstrappingConfiguration: nbc, Maintenance: maintenance, - AKSNodeConfig: nbcToNbcContractV1(nbc), // TODO: replace with base template + AKSNodeConfig: nbcToAKSNodeConfigV1(nbc), // TODO: replace with base template }, nil } diff --git a/e2e/node_bootstrapper_test.go b/e2e/node_bootstrapper_test.go index 5882ebc0e61..2db08ac9a2a 100644 --- a/e2e/node_bootstrapper_test.go +++ b/e2e/node_bootstrapper_test.go @@ -98,7 +98,7 @@ func CSEAKSNodeController(t *testing.T, cluster *Cluster) string { nbc := nbcAny.(*datamodel.NodeBootstrappingConfiguration) agent.ValidateAndSetLinuxNodeBootstrappingConfiguration(nbc) - configContent := nbcToNbcContractV1(nbc) + configContent := nbcToAKSNodeConfigV1(nbc) configJSON, err := json.Marshal(configContent) require.NoError(t, err) diff --git a/e2e/template.go b/e2e/template.go index b06f2af462b..6dbac1c6a1e 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -25,7 +25,7 @@ func getBaseNodeBootstrappingConfiguration(ctx context.Context, t *testing.T, ku // is a temporary workaround // eventually we want to phase out usage of nbc -func nbcToNbcContractV1(nbc *datamodel.NodeBootstrappingConfiguration) *aksnodeconfigv1.Configuration { +func nbcToAKSNodeConfigV1(nbc *datamodel.NodeBootstrappingConfiguration) *aksnodeconfigv1.Configuration { cs := nbc.ContainerService agentPool := nbc.AgentPoolProfile agent.ValidateAndSetLinuxNodeBootstrappingConfiguration(nbc) diff --git a/e2e/vmss.go b/e2e/vmss.go index efcc371047a..b2cbcd8ada4 100644 --- a/e2e/vmss.go +++ b/e2e/vmss.go @@ -39,7 +39,7 @@ func createVMSS(ctx context.Context, t *testing.T, vmssName string, scenario *Sc ab, err := agent.NewAgentBaker() require.NoError(t, err) if scenario.AKSNodeConfigMutator != nil { - builder := aksnodeconfigv1.NewNBContractBuilder() + builder := aksnodeconfigv1.NewAKSNodeConfigBuilder() builder.ApplyConfiguration(scenario.Runtime.AKSNodeConfig) nodeBootstrapping, err = builder.GetNodeBootstrapping() require.NoError(t, err) diff --git a/pkg/proto/aksnodeconfig/v1/README.md b/pkg/proto/aksnodeconfig/v1/README.md index d1cce0d8e5a..0bec7121eeb 100644 --- a/pkg/proto/aksnodeconfig/v1/README.md +++ b/pkg/proto/aksnodeconfig/v1/README.md @@ -9,7 +9,7 @@ This table is describing the all the AKSNodeConfig Fields converted to .go files | AKSNodeConfig Fields | Types | Descriptions | OLD CSE env variables mapping | |------------|------------|--------------|-------------------------------| -| `Version` | `string` | Semantic version of this node bootstrap contract | N/A, new | +| `Version` | `string` | Semantic version of this AKSNodeConfig | N/A, new | | `KubeBinaryConfig` | `KubeBinaryConfig` | Kubernetes binary URL configuration | `KUBE_BINARY_URL`, `CUSTOM_KUBE_BINARY_URL`, `PRIVATE_KUBE_BINARY_URL` , `CREDENTIAL_PROVIDER_DOWNLOAD_URL` | | `CustomCloudConfig` | `CustomCloudConfig` | Custom cloud configuration | `IS_CUSTOM_CLOUD`, `AKS_CUSTOM_CLOUD_CONTAINER_REGISTRY_DNS_SUFFIX`, `REPO_DEPOT_ENDPOINT`, `CUSTOM_ENV_JSON` | | `ApiServerConfig` | `ApiServerConfig` | Kubernetes API server configuration | `APISERVER_PUBLIC_KEY`, `API_SERVER_NAME` | diff --git a/pkg/proto/aksnodeconfig/v1/helper.go b/pkg/proto/aksnodeconfig/v1/helper.go index 0a68a0f9f8a..8d118c5d68e 100644 --- a/pkg/proto/aksnodeconfig/v1/helper.go +++ b/pkg/proto/aksnodeconfig/v1/helper.go @@ -11,11 +11,11 @@ import ( "github.com/Azure/agentbaker/pkg/agent/datamodel" ) -// NBContractBuilder is a helper struct to build the NBContract (Node Bootstrap Contract). -// It provides methods to apply configuration, get the NBContract object, and validate the contract, etc. -type NBContractBuilder struct { - // nodeBootstrapConfig is the configuration object for the NBContract (Node Bootstrap Contract). - nodeBootstrapConfig *Configuration +// AKSNodeConfigBuilder is a helper struct to build the AKSNodeConfig. +// It provides methods to apply configuration, get the AKSNodeConfig object, and validate the contract, etc. +type AKSNodeConfigBuilder struct { + // aksNodeConfig is the configuration object for the AKSNodeConfig. + aksNodeConfig *Configuration } // Check and initialize each field if it is nil. @@ -48,38 +48,38 @@ func ensureConfigsNonNil(nBC *Configuration) { initializeIfNil(&nBC.CustomSearchDomainConfig) } -// NewNBContractBuilder creates a new instance of NBContractBuilder and ensures all objects in nodeBootstrapConfig are non-nil. -func NewNBContractBuilder() *NBContractBuilder { - nbc := Configuration{ +// NewAKSNodeConfigBuilder creates a new instance of AKSNodeConfigBuilder and ensures all objects in aksNodeConfig are non-nil. +func NewAKSNodeConfigBuilder() *AKSNodeConfigBuilder { + config := Configuration{ Version: contractVersion, } - ensureConfigsNonNil(&nbc) - nBCB := &NBContractBuilder{nodeBootstrapConfig: &nbc} - return nBCB + ensureConfigsNonNil(&config) + aksNodeConfig := &AKSNodeConfigBuilder{aksNodeConfig: &config} + return aksNodeConfig } -// ApplyConfiguration Applies the configuration to the nodeBootstrapConfig object. -func (nBCB *NBContractBuilder) ApplyConfiguration(config *Configuration) { +// ApplyConfiguration Applies the configuration to the aksNodeConfig object. +func (b *AKSNodeConfigBuilder) ApplyConfiguration(config *Configuration) { if config == nil { return } // Use deep copy to avoid modifying the original object 'config'. - if err := nBCB.deepCopy(config, nBCB.nodeBootstrapConfig); err != nil { + if err := deepCopy(config, b.aksNodeConfig); err != nil { log.Printf("Failed to deep copy the configuration: %v", err) - ensureConfigsNonNil(nBCB.nodeBootstrapConfig) + ensureConfigsNonNil(b.aksNodeConfig) } } -// GetNodeBootstrapConfig gets the nodeBootstrapConfig object. -func (nBCB *NBContractBuilder) GetNodeBootstrapConfig() *Configuration { - return nBCB.nodeBootstrapConfig +// GetAKSNodeConfig gets the aksNodeConfig object. +func (b *AKSNodeConfigBuilder) GetAKSNodeConfig() *Configuration { + return b.aksNodeConfig } // Deep copy the source object to the destination object. // Note that the existing value in the destination object will not be cleared // if the source object doesn't have that field. -func (nBCB *NBContractBuilder) deepCopy(src, dst interface{}) error { +func deepCopy(src, dst interface{}) error { if src == nil { return nil } @@ -91,11 +91,11 @@ func (nBCB *NBContractBuilder) deepCopy(src, dst interface{}) error { return gob.NewDecoder(&buf).Decode(dst) } -// ValidateNBContract validates the NBContract. +// ValidateAKSNodeConfig validates the AKSNodeConfig. // It returns an error if the contract is invalid. // This function should be called after applying all configuration and before sending to downstream component. -func (nBCB *NBContractBuilder) ValidateNBContract() error { - if err := nBCB.validateRequiredFields(); err != nil { +func (b *AKSNodeConfigBuilder) ValidateAKSNodeConfig() error { + if err := b.validateRequiredFields(); err != nil { return err } // Add more validations here if needed. @@ -103,8 +103,9 @@ func (nBCB *NBContractBuilder) ValidateNBContract() error { return nil } -func (nBCB *NBContractBuilder) GetNodeBootstrapping() (*datamodel.NodeBootstrapping, error) { - scriptlessCustomData, err := getScriptlessCustomDataContent(nBCB.nodeBootstrapConfig) +// GetNodeBootstrapping gets the NodeBootstrapping object. +func (b *AKSNodeConfigBuilder) GetNodeBootstrapping() (*datamodel.NodeBootstrapping, error) { + scriptlessCustomData, err := getScriptlessCustomDataContent(b.aksNodeConfig) if err != nil { return nil, err } @@ -127,8 +128,8 @@ func getScriptlessCustomDataContent(config any) (string, error) { return base64.StdEncoding.EncodeToString([]byte(customDataYAML)), nil } -func (nBCB *NBContractBuilder) validateRequiredFields() error { - if err := nBCB.validateRequiredStringsNotEmpty(); err != nil { +func (b *AKSNodeConfigBuilder) validateRequiredFields() error { + if err := b.validateRequiredStringsNotEmpty(); err != nil { return err } // Add more required fields validations here if needed. @@ -136,14 +137,14 @@ func (nBCB *NBContractBuilder) validateRequiredFields() error { return nil } -func (nBCB *NBContractBuilder) validateRequiredStringsNotEmpty() error { +func (b *AKSNodeConfigBuilder) validateRequiredStringsNotEmpty() error { requiredStrings := map[string]string{ - "AuthConfig.SubscriptionId": nBCB.nodeBootstrapConfig.GetAuthConfig().GetSubscriptionId(), - "ClusterConfig.ResourceGroup": nBCB.nodeBootstrapConfig.GetClusterConfig().GetResourceGroup(), - "ClusterConfig.Location": nBCB.nodeBootstrapConfig.GetClusterConfig().GetLocation(), - "ClusterConfig.ClusterNetworkConfig.VnetName": nBCB.nodeBootstrapConfig.GetClusterConfig().GetClusterNetworkConfig().GetVnetName(), - "ClusterConfig.ClusterNetworkConfig.RouteTable": nBCB.nodeBootstrapConfig.GetClusterConfig().GetClusterNetworkConfig().GetRouteTable(), - "ApiServerConfig.ApiServerName": nBCB.nodeBootstrapConfig.ApiServerConfig.GetApiServerName(), + "AuthConfig.SubscriptionId": b.aksNodeConfig.GetAuthConfig().GetSubscriptionId(), + "ClusterConfig.ResourceGroup": b.aksNodeConfig.GetClusterConfig().GetResourceGroup(), + "ClusterConfig.Location": b.aksNodeConfig.GetClusterConfig().GetLocation(), + "ClusterConfig.ClusterNetworkConfig.VnetName": b.aksNodeConfig.GetClusterConfig().GetClusterNetworkConfig().GetVnetName(), + "ClusterConfig.ClusterNetworkConfig.RouteTable": b.aksNodeConfig.GetClusterConfig().GetClusterNetworkConfig().GetRouteTable(), + "ApiServerConfig.ApiServerName": b.aksNodeConfig.ApiServerConfig.GetApiServerName(), } for field, value := range requiredStrings { diff --git a/pkg/proto/aksnodeconfig/v1/helper_test.go b/pkg/proto/aksnodeconfig/v1/helper_test.go index cc09b7b5e3e..6a845b54f56 100644 --- a/pkg/proto/aksnodeconfig/v1/helper_test.go +++ b/pkg/proto/aksnodeconfig/v1/helper_test.go @@ -8,7 +8,7 @@ import ( "github.com/Azure/go-autorest/autorest/to" ) -func TestNewNBContractBuilder(t *testing.T) { +func TestNewAKSNodeConfigBuilder(t *testing.T) { wantedResult := Configuration{ Version: contractVersion, KubeBinaryConfig: &KubeBinaryConfig{}, @@ -44,16 +44,16 @@ func TestNewNBContractBuilder(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := NewNBContractBuilder().nodeBootstrapConfig; !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewNBContractConfiguration() = %v, want %v", got, tt.want) + if got := NewAKSNodeConfigBuilder().aksNodeConfig; !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAKSNodeConfigConfiguration() = %v, want %v", got, tt.want) } }) } } -func TestNBContractBuilder_ApplyConfiguration(t *testing.T) { +func TestAKSNodeConfigBuilder_ApplyConfiguration(t *testing.T) { type fields struct { - nBContractConfiguration *Configuration + AKSNodeConfigConfiguration *Configuration } wantedResult := &Configuration{ Version: contractVersion, @@ -87,14 +87,14 @@ func TestNBContractBuilder_ApplyConfiguration(t *testing.T) { { name: "Test with nil configuration", fields: fields{ - nBContractConfiguration: &Configuration{}, + AKSNodeConfigConfiguration: &Configuration{}, }, want: wantedResult, }, { - name: "Apply nil AuthConfig configuration and expect AuthConfig in nBContractConfiguration to be non-nil", + name: "Apply nil AuthConfig configuration and expect AuthConfig in AKSNodeConfigConfiguration to be non-nil", fields: fields{ - nBContractConfiguration: &Configuration{ + AKSNodeConfigConfiguration: &Configuration{ AuthConfig: nil, }, }, @@ -103,7 +103,7 @@ func TestNBContractBuilder_ApplyConfiguration(t *testing.T) { { name: "Apply some configurations and expect them to be applied", fields: fields{ - nBContractConfiguration: &Configuration{ + AKSNodeConfigConfiguration: &Configuration{ CustomCloudConfig: &CustomCloudConfig{ CustomCloudEnvName: "some-cloud", }, @@ -111,7 +111,7 @@ func TestNBContractBuilder_ApplyConfiguration(t *testing.T) { }, }, want: func() *Configuration { - tmpResult := NewNBContractBuilder().nodeBootstrapConfig + tmpResult := NewAKSNodeConfigBuilder().aksNodeConfig tmpResult.CustomCloudConfig.CustomCloudEnvName = "some-cloud" tmpResult.LinuxAdminUsername = "testuser" return tmpResult @@ -120,16 +120,16 @@ func TestNBContractBuilder_ApplyConfiguration(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - builder := NewNBContractBuilder() - builder.ApplyConfiguration(tt.fields.nBContractConfiguration) - if got := builder.nodeBootstrapConfig; !reflect.DeepEqual(got, tt.want) { + builder := NewAKSNodeConfigBuilder() + builder.ApplyConfiguration(tt.fields.AKSNodeConfigConfiguration) + if got := builder.aksNodeConfig; !reflect.DeepEqual(got, tt.want) { t.Errorf("ApplyConfiguration() = %v, want %v", got, tt.want) } }) } } -func TestNBContractBuilder_deepCopy(t *testing.T) { +func TestDeepCopy(t *testing.T) { type Teststruct struct { A string B *int @@ -209,10 +209,7 @@ func TestNBContractBuilder_deepCopy(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - nBCB := &NBContractBuilder{ - nodeBootstrapConfig: &Configuration{}, - } - if err := nBCB.deepCopy(tt.args.src, tt.args.dst); err != nil { + if err := deepCopy(tt.args.src, tt.args.dst); err != nil { log.Printf("Failed to deep copy the configuration: %v", err) } log.Printf("dst = %v, src %v", tt.args.dst, tt.args.src) @@ -230,7 +227,7 @@ func TestNBContractBuilder_deepCopy(t *testing.T) { } } -func TestNBContractBuilder_validateRequiredFields(t *testing.T) { +func TestAKSNodeConfigBuilder_validateRequiredFields(t *testing.T) { type fields struct { nodeBootstrapConfig *Configuration } @@ -288,11 +285,11 @@ func TestNBContractBuilder_validateRequiredFields(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - nBCB := NewNBContractBuilder() - nBCB.ApplyConfiguration(tt.fields.nodeBootstrapConfig) - err := nBCB.validateRequiredFields() + aKSNodeConfigBuilder := NewAKSNodeConfigBuilder() + aKSNodeConfigBuilder.ApplyConfiguration(tt.fields.nodeBootstrapConfig) + err := aKSNodeConfigBuilder.validateRequiredFields() if (err != nil) != tt.wantErr { - t.Errorf("NBContractBuilder.validateRequiredFields() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("aKSNodeConfigBuilder.validateRequiredFields() error = %v, wantErr %v", err, tt.wantErr) } }) }