From b8e0978d6d3ace5b344314cd4b6f9e42ba4441e5 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Wed, 24 Mar 2021 14:34:11 -0500 Subject: [PATCH] Remove NameInKubeconf field from Context struct Since this field is no longer actually used, there is need to remove it completely. Change-Id: I9f7002f8def31d1660919bd0128707e43a57ad71 Signed-off-by: Ruslan Aliev --- cmd/config/get_context_test.go | 3 +-- cmd/config/set_context_test.go | 16 ---------------- .../get-all-contexts.golden | 3 --- .../get-context.golden | 1 - .../get-current-context.golden | 1 - .../get-multiple-contexts.golden | 3 --- .../modify-context.golden | 1 - .../set-current-context.golden | 1 - docs/azure/azure-integration.md | 1 - docs/source/providers/cluster_api_docker.md | 6 ++++++ docs/source/providers/cluster_api_gcp.md | 2 -- .../resetsatoken/testdata/airshipconfig.yaml | 1 - pkg/config/config.go | 5 ++--- pkg/config/config_test.go | 3 +-- pkg/config/context.go | 6 ------ pkg/config/errors.go | 5 ++--- pkg/config/testdata/config-string.yaml | 1 - pkg/config/testdata/context-string.yaml | 1 - pkg/phase/helper_test.go | 1 - pkg/phase/testdata/airshipconfig.yaml | 1 - testdata/k8s/config.yaml | 1 - testutil/testconfig.go | 4 ---- .../deployment/templates/airshipconfig_template | 2 -- .../templates/azure_airshipconfig_template | 1 - tools/document/validate_site_docs.sh | 1 - 25 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden delete mode 100644 cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden diff --git a/cmd/config/get_context_test.go b/cmd/config/get_context_test.go index 25573c508..f8d54b99b 100644 --- a/cmd/config/get_context_test.go +++ b/cmd/config/get_context_test.go @@ -91,8 +91,7 @@ func TestNoContextsGetContextCmd(t *testing.T) { func getNamedTestContext(contextName string) *config.Context { newContext := &config.Context{ - NameInKubeconf: contextName, - Manifest: fmt.Sprintf("Manifest_%s", contextName), + Manifest: fmt.Sprintf("Manifest_%s", contextName), } return newContext diff --git a/cmd/config/set_context_test.go b/cmd/config/set_context_test.go index 6045f5297..88a191eff 100644 --- a/cmd/config/set_context_test.go +++ b/cmd/config/set_context_test.go @@ -29,7 +29,6 @@ import ( const ( defaultManifest = "edge_cloud" - testManifest = "test_manifest" ) type setContextTest struct { @@ -84,21 +83,6 @@ func TestSetContext(t *testing.T) { givenConfig: given, manifest: defaultManifest, }, - { - testName: "set-current-context", - contextName: "def_target", - flags: []string{}, - givenConfig: given, - }, - { - testName: "modify-context", - contextName: "def_target", - flags: []string{ - "--manifest=" + testManifest, - }, - givenConfig: given, - manifest: testManifest, - }, } for _, tt := range tests { diff --git a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-all-contexts.golden b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-all-contexts.golden index e5ca803f3..875dcb32a 100644 --- a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-all-contexts.golden +++ b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-all-contexts.golden @@ -1,12 +1,9 @@ -contextKubeconf: ContextBar managementConfiguration: "" manifest: Manifest_ContextBar -contextKubeconf: ContextBaz managementConfiguration: "" manifest: Manifest_ContextBaz -contextKubeconf: ContextFoo managementConfiguration: "" manifest: Manifest_ContextFoo diff --git a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden index dcb24aadd..461c3f74d 100644 --- a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden +++ b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden @@ -1,4 +1,3 @@ -contextKubeconf: ContextFoo managementConfiguration: "" manifest: Manifest_ContextFoo diff --git a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden index d95b36d79..c4603a93a 100644 --- a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden +++ b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden @@ -1,4 +1,3 @@ -contextKubeconf: ContextBaz managementConfiguration: "" manifest: Manifest_ContextBaz diff --git a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-multiple-contexts.golden b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-multiple-contexts.golden index e5ca803f3..875dcb32a 100644 --- a/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-multiple-contexts.golden +++ b/cmd/config/testdata/TestGetContextCmdGoldenOutput/get-multiple-contexts.golden @@ -1,12 +1,9 @@ -contextKubeconf: ContextBar managementConfiguration: "" manifest: Manifest_ContextBar -contextKubeconf: ContextBaz managementConfiguration: "" manifest: Manifest_ContextBaz -contextKubeconf: ContextFoo managementConfiguration: "" manifest: Manifest_ContextFoo diff --git a/cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden b/cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden deleted file mode 100644 index 449c394f5..000000000 --- a/cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden +++ /dev/null @@ -1 +0,0 @@ -Context "def_target" modified. diff --git a/cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden b/cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden deleted file mode 100644 index a48fc22ec..000000000 --- a/cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden +++ /dev/null @@ -1 +0,0 @@ -Context "def_target" not modified. No new options provided. diff --git a/docs/azure/azure-integration.md b/docs/azure/azure-integration.md index 58237b403..67e26f4b2 100644 --- a/docs/azure/azure-integration.md +++ b/docs/azure/azure-integration.md @@ -139,7 +139,6 @@ az-target-cluster-md-0-z5lff Ready 17h v1.18.2 apiVersion: airshipit.org/v1alpha1 contexts: az-target-cluster-admin@az-target-cluster: - contextKubeconf: az-target-cluster_target manifest: azure_manifest currentContext: az-target-cluster-admin@az-target-cluster kind: Config diff --git a/docs/source/providers/cluster_api_docker.md b/docs/source/providers/cluster_api_docker.md index 9a49fd960..5d8607b3c 100755 --- a/docs/source/providers/cluster_api_docker.md +++ b/docs/source/providers/cluster_api_docker.md @@ -111,9 +111,15 @@ $ export KIND_EXPERIMENTAL_DOCKER_NETWORK=bridge $ export KUBECONFIG="${HOME}/.airship/kubeconfig" +<<<<<<< HEAD $ kind create cluster --name ephemeral-cluster --wait 120s --kubeconfig \ "${HOME}/.airship/kubeconfig" \ --config ./tools/deployment/templates/kind-cluster-with-extramounts +======= +``` +Context: kind-capi-docker +manifest: docker_manifest +>>>>>>> Remove NameInKubeconf field from Context struct $ kubectl config set-context ephemeral-cluster \ --cluster kind-ephemeral-cluster \ diff --git a/docs/source/providers/cluster_api_gcp.md b/docs/source/providers/cluster_api_gcp.md index f36dcf827..411e37586 100755 --- a/docs/source/providers/cluster_api_gcp.md +++ b/docs/source/providers/cluster_api_gcp.md @@ -166,11 +166,9 @@ $ cat ~/.airship/config apiVersion: airshipit.org/v1alpha1 contexts: default: - contextKubeconf: "" managementConfiguration: default manifest: default ephemeral-cluster: - contextKubeconf: ephemeral-cluster managementConfiguration: "" manifest: gcp_manifest currentContext: ephemeral-cluster diff --git a/pkg/cluster/resetsatoken/testdata/airshipconfig.yaml b/pkg/cluster/resetsatoken/testdata/airshipconfig.yaml index b619b6fdb..7a7d762e9 100644 --- a/pkg/cluster/resetsatoken/testdata/airshipconfig.yaml +++ b/pkg/cluster/resetsatoken/testdata/airshipconfig.yaml @@ -1,7 +1,6 @@ apiVersion: airshipit.org/v1alpha1 contexts: dummy_cluster: - contextKubeconf: dummycluster_ephemeral manifest: dummy_manifest currentContext: dummy_cluster kind: Config diff --git a/pkg/config/config.go b/pkg/config/config.go index 425741564..658ff08ad 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -282,7 +282,6 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context { // Create the new Airship config context nContext := NewContext() c.Contexts[theContext.Name] = nContext - nContext.NameInKubeconf = theContext.Name // Ok , I have initialized structs for the Context information // We can use Modify to populate the correct information @@ -482,13 +481,13 @@ func (c *Config) CurrentContextManagementConfig() (*ManagementConfiguration, err if currentContext.ManagementConfiguration == "" { return nil, ErrMissingConfig{ - What: fmt.Sprintf("no management config listed for cluster %s", currentContext.NameInKubeconf), + What: fmt.Sprintf("no management config listed for context '%s'", c.CurrentContext), } } managementCfg, exists := c.ManagementConfiguration[currentContext.ManagementConfiguration] if !exists { - return nil, ErrMissingManagementConfiguration{context: currentContext} + return nil, ErrMissingManagementConfiguration{contextName: c.CurrentContext} } return managementCfg, nil diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 03add579c..c91eeab3b 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -245,8 +245,7 @@ func TestGetContext(t *testing.T) { context, err := conf.GetContext("def_ephemeral") require.NoError(t, err) - // Test Positives - assert.EqualValues(t, context.NameInKubeconf, "def_ephemeral") + assert.EqualValues(t, context.Manifest, "dummy_manifest") // Test Wrong Cluster _, err = conf.GetContext("unknown") diff --git a/pkg/config/context.go b/pkg/config/context.go index ef488a764..31db50ced 100644 --- a/pkg/config/context.go +++ b/pkg/config/context.go @@ -21,9 +21,6 @@ import ( // Context is a tuple of references to a cluster (how do I communicate with a kubernetes context), // a user (how do I identify myself), and a namespace (what subset of resources do I want to work with) type Context struct { - // NameInKubeconf is the Context name in kubeconf - NameInKubeconf string `json:"contextKubeconf"` - // Manifest is the default manifest to be use with this context // +optional Manifest string `json:"manifest,omitempty"` @@ -37,8 +34,5 @@ func (c *Context) String() string { if err != nil { return "" } - if err != nil { - return string(cyaml) - } return string(cyaml) } diff --git a/pkg/config/errors.go b/pkg/config/errors.go index 0b16fba2c..294ba2ec8 100644 --- a/pkg/config/errors.go +++ b/pkg/config/errors.go @@ -154,12 +154,11 @@ func (e ErrMissingCurrentContext) Error() string { // ErrMissingManagementConfiguration means the management configuration was not defined for the active cluster. type ErrMissingManagementConfiguration struct { - context *Context + contextName string } func (e ErrMissingManagementConfiguration) Error() string { - return fmt.Sprintf("Management configuration %s for cluster %s undefined.", e.context.ManagementConfiguration, - e.context.NameInKubeconf) + return fmt.Sprintf("Management configuration for context '%s' undefined.", e.contextName) } // ErrMissingPhaseRepo returned when Phase Repository is not set in context manifest diff --git a/pkg/config/testdata/config-string.yaml b/pkg/config/testdata/config-string.yaml index 6880ab352..ca262558b 100644 --- a/pkg/config/testdata/config-string.yaml +++ b/pkg/config/testdata/config-string.yaml @@ -1,7 +1,6 @@ apiVersion: airshipit.org/v1alpha1 contexts: dummy_context: - contextKubeconf: dummy_cluster_ephemeral managementConfiguration: dummy_management_config manifest: dummy_manifest currentContext: dummy_context diff --git a/pkg/config/testdata/context-string.yaml b/pkg/config/testdata/context-string.yaml index e7196e583..b7bfa271c 100644 --- a/pkg/config/testdata/context-string.yaml +++ b/pkg/config/testdata/context-string.yaml @@ -1,3 +1,2 @@ -contextKubeconf: dummy_cluster_ephemeral managementConfiguration: dummy_management_config manifest: dummy_manifest diff --git a/pkg/phase/helper_test.go b/pkg/phase/helper_test.go index ddb31a321..1f3d7ed4c 100644 --- a/pkg/phase/helper_test.go +++ b/pkg/phase/helper_test.go @@ -552,7 +552,6 @@ func testConfig(t *testing.T) *config.Config { confString := `apiVersion: airshipit.org/v1alpha1 contexts: dummy_cluster: - contextKubeconf: dummy_cluster manifest: dummy_manifest currentContext: dummy_cluster kind: Config diff --git a/pkg/phase/testdata/airshipconfig.yaml b/pkg/phase/testdata/airshipconfig.yaml index e610942f0..45f59ae24 100644 --- a/pkg/phase/testdata/airshipconfig.yaml +++ b/pkg/phase/testdata/airshipconfig.yaml @@ -1,7 +1,6 @@ apiVersion: airshipit.org/v1alpha1 contexts: dummy_cluster: - contextKubeconf: dummycluster_ephemeral manifest: dummy_manifest currentContext: dummy_cluster kind: Config diff --git a/testdata/k8s/config.yaml b/testdata/k8s/config.yaml index f7ac37512..a46d8ab2f 100644 --- a/testdata/k8s/config.yaml +++ b/testdata/k8s/config.yaml @@ -1,7 +1,6 @@ apiVersion: airshipit.org/v1alpha1 contexts: default: - contextKubeconf: default_target manifest: default currentContext: "" kind: Config diff --git a/testutil/testconfig.go b/testutil/testconfig.go index 893d3b2e0..55630869f 100644 --- a/testutil/testconfig.go +++ b/testutil/testconfig.go @@ -52,7 +52,6 @@ func DummyConfig() *config.Config { // DummyContext creates a Context config object for unit testing func DummyContext() *config.Context { c := config.NewContext() - c.NameInKubeconf = "dummy_cluster_ephemeral" c.Manifest = "dummy_manifest" c.ManagementConfiguration = "dummy_management_config" return c @@ -163,12 +162,9 @@ const ( testConfigYAML = `apiVersion: airshipit.org/v1alpha1 contexts: def_ephemeral: - contextKubeconf: def_ephemeral manifest: dummy_manifest def_target: - contextKubeconf: def_target onlyink: - contextKubeconf: onlyinkubeconf_target encryptionConfigs: {} currentContext: def_ephemeral kind: Config diff --git a/tools/deployment/templates/airshipconfig_template b/tools/deployment/templates/airshipconfig_template index 43cf36e46..0a5c4311b 100644 --- a/tools/deployment/templates/airshipconfig_template +++ b/tools/deployment/templates/airshipconfig_template @@ -8,11 +8,9 @@ managementConfiguration: systemRebootDelay: ${SYSTEM_REBOOT_DELAY} contexts: ephemeral-cluster: - contextKubeconf: ephemeral-cluster_ephemeral manifest: dummy_manifest managementConfiguration: dummy_management_config target-cluster: - contextKubeconf: target-cluster_target manifest: dummy_manifest managementConfiguration: dummy_management_config currentContext: ephemeral-cluster diff --git a/tools/deployment/templates/azure_airshipconfig_template b/tools/deployment/templates/azure_airshipconfig_template index 05adec07b..3930554f3 100644 --- a/tools/deployment/templates/azure_airshipconfig_template +++ b/tools/deployment/templates/azure_airshipconfig_template @@ -1,7 +1,6 @@ apiVersion: airshipit.org/v1alpha1 contexts: kind-capi-azure: - contextKubeconf: kind-capi-azure_target manifest: azure_manifest currentContext: kind-capi-azure kind: Config diff --git a/tools/document/validate_site_docs.sh b/tools/document/validate_site_docs.sh index a4e6c03c0..147e782b0 100755 --- a/tools/document/validate_site_docs.sh +++ b/tools/document/validate_site_docs.sh @@ -54,7 +54,6 @@ function generate_airshipconf() { apiVersion: airshipit.org/v1alpha1 contexts: ${CONTEXT}_${cluster}: - contextKubeconf: ${CONTEXT}_${cluster} manifest: ${CONTEXT}_${cluster} managementConfiguration: default currentContext: ${CONTEXT}_${cluster}