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 2 years ago
parent bde1998648
commit b8e0978d6d

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

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

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

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

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

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

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

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

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

@ -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,7 +1,6 @@
apiVersion: airshipit.org/v1alpha1
contexts:
dummy_cluster:
contextKubeconf: dummycluster_ephemeral
manifest: dummy_manifest
currentContext: dummy_cluster
kind: Config

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

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

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

@ -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,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,3 +1,2 @@
contextKubeconf: dummy_cluster_ephemeral
managementConfiguration: dummy_management_config
manifest: dummy_manifest

@ -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,7 +1,6 @@
apiVersion: airshipit.org/v1alpha1
contexts:
dummy_cluster:
contextKubeconf: dummycluster_ephemeral
manifest: dummy_manifest
currentContext: dummy_cluster
kind: Config

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

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

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

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