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>
This commit is contained in:
Ruslan Aliev 2021-03-24 14:34:11 -05:00
parent bde1998648
commit b8e0978d6d
25 changed files with 12 additions and 59 deletions

View File

@ -91,7 +91,6 @@ func TestNoContextsGetContextCmd(t *testing.T) {
func getNamedTestContext(contextName string) *config.Context {
newContext := &config.Context{
NameInKubeconf: contextName,
Manifest: fmt.Sprintf("Manifest_%s", contextName),
}

View File

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

View File

@ -1,12 +1,9 @@
contextKubeconf: ContextBar
managementConfiguration: ""
manifest: Manifest_ContextBar
contextKubeconf: ContextBaz
managementConfiguration: ""
manifest: Manifest_ContextBaz
contextKubeconf: ContextFoo
managementConfiguration: ""
manifest: Manifest_ContextFoo

View File

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

View File

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

View File

@ -1,12 +1,9 @@
contextKubeconf: ContextBar
managementConfiguration: ""
manifest: Manifest_ContextBar
contextKubeconf: ContextBaz
managementConfiguration: ""
manifest: Manifest_ContextBaz
contextKubeconf: ContextFoo
managementConfiguration: ""
manifest: Manifest_ContextFoo

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

@ -1,7 +1,6 @@
apiVersion: airshipit.org/v1alpha1
contexts:
dummy_cluster:
contextKubeconf: dummycluster_ephemeral
manifest: dummy_manifest
currentContext: dummy_cluster
kind: Config

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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

View File

@ -1,7 +1,6 @@
apiVersion: airshipit.org/v1alpha1
contexts:
dummy_cluster:
contextKubeconf: dummycluster_ephemeral
manifest: dummy_manifest
currentContext: dummy_cluster
kind: Config

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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