Browse Source

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 <raliev@mirantis.com>
changes/50/782850/4
Ruslan Aliev 10 months ago
parent
commit
b8e0978d6d
  1. 3
      cmd/config/get_context_test.go
  2. 16
      cmd/config/set_context_test.go
  3. 3
      cmd/config/testdata/TestGetContextCmdGoldenOutput/get-all-contexts.golden
  4. 1
      cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden
  5. 1
      cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden
  6. 3
      cmd/config/testdata/TestGetContextCmdGoldenOutput/get-multiple-contexts.golden
  7. 1
      cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden
  8. 1
      cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden
  9. 1
      docs/azure/azure-integration.md
  10. 6
      docs/source/providers/cluster_api_docker.md
  11. 2
      docs/source/providers/cluster_api_gcp.md
  12. 1
      pkg/cluster/resetsatoken/testdata/airshipconfig.yaml
  13. 5
      pkg/config/config.go
  14. 3
      pkg/config/config_test.go
  15. 6
      pkg/config/context.go
  16. 5
      pkg/config/errors.go
  17. 1
      pkg/config/testdata/config-string.yaml
  18. 1
      pkg/config/testdata/context-string.yaml
  19. 1
      pkg/phase/helper_test.go
  20. 1
      pkg/phase/testdata/airshipconfig.yaml
  21. 1
      testdata/k8s/config.yaml
  22. 4
      testutil/testconfig.go
  23. 2
      tools/deployment/templates/airshipconfig_template
  24. 1
      tools/deployment/templates/azure_airshipconfig_template
  25. 1
      tools/document/validate_site_docs.sh

3
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

16
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 {

3
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

1
cmd/config/testdata/TestGetContextCmdGoldenOutput/get-context.golden

@ -1,4 +1,3 @@
contextKubeconf: ContextFoo
managementConfiguration: ""
manifest: Manifest_ContextFoo

1
cmd/config/testdata/TestGetContextCmdGoldenOutput/get-current-context.golden

@ -1,4 +1,3 @@
contextKubeconf: ContextBaz
managementConfiguration: ""
manifest: Manifest_ContextBaz

3
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

1
cmd/config/testdata/TestSetContextGoldenOutput/modify-context.golden

@ -1 +0,0 @@
Context "def_target" modified.

1
cmd/config/testdata/TestSetContextGoldenOutput/set-current-context.golden

@ -1 +0,0 @@
Context "def_target" not modified. No new options provided.

1
docs/azure/azure-integration.md

@ -139,7 +139,6 @@ az-target-cluster-md-0-z5lff Ready <none> 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

6
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 \

2
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

1
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

5
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

3
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")

6
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)
}

5
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

1
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

1
pkg/config/testdata/context-string.yaml

@ -1,3 +1,2 @@
contextKubeconf: dummy_cluster_ephemeral
managementConfiguration: dummy_management_config
manifest: dummy_manifest

1
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

1
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

1
testdata/k8s/config.yaml

@ -1,7 +1,6 @@
apiVersion: airshipit.org/v1alpha1
contexts:
default:
contextKubeconf: default_target
manifest: default
currentContext: ""
kind: Config

4
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

2
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

1
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

1
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}

Loading…
Cancel
Save