Merge "Remove NameInKubeconf field from Context struct"
This commit is contained in:
commit
5737f3bf26
@ -91,8 +91,7 @@ func TestNoContextsGetContextCmd(t *testing.T) {
|
|||||||
|
|
||||||
func getNamedTestContext(contextName string) *config.Context {
|
func getNamedTestContext(contextName string) *config.Context {
|
||||||
newContext := &config.Context{
|
newContext := &config.Context{
|
||||||
NameInKubeconf: contextName,
|
Manifest: fmt.Sprintf("Manifest_%s", contextName),
|
||||||
Manifest: fmt.Sprintf("Manifest_%s", contextName),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newContext
|
return newContext
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultManifest = "edge_cloud"
|
defaultManifest = "edge_cloud"
|
||||||
testManifest = "test_manifest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type setContextTest struct {
|
type setContextTest struct {
|
||||||
@ -84,21 +83,6 @@ func TestSetContext(t *testing.T) {
|
|||||||
givenConfig: given,
|
givenConfig: given,
|
||||||
manifest: defaultManifest,
|
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 {
|
for _, tt := range tests {
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
contextKubeconf: ContextBar
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBar
|
manifest: Manifest_ContextBar
|
||||||
|
|
||||||
contextKubeconf: ContextBaz
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
contextKubeconf: ContextFoo
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
contextKubeconf: ContextFoo
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
contextKubeconf: ContextBaz
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
contextKubeconf: ContextBar
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBar
|
manifest: Manifest_ContextBar
|
||||||
|
|
||||||
contextKubeconf: ContextBaz
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
contextKubeconf: ContextFoo
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Context "def_target" modified.
|
|
@ -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
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
az-target-cluster-admin@az-target-cluster:
|
az-target-cluster-admin@az-target-cluster:
|
||||||
contextKubeconf: az-target-cluster_target
|
|
||||||
manifest: azure_manifest
|
manifest: azure_manifest
|
||||||
currentContext: az-target-cluster-admin@az-target-cluster
|
currentContext: az-target-cluster-admin@az-target-cluster
|
||||||
kind: Config
|
kind: Config
|
||||||
|
@ -111,9 +111,15 @@ $ export KIND_EXPERIMENTAL_DOCKER_NETWORK=bridge
|
|||||||
|
|
||||||
$ export KUBECONFIG="${HOME}/.airship/kubeconfig"
|
$ export KUBECONFIG="${HOME}/.airship/kubeconfig"
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
$ kind create cluster --name ephemeral-cluster --wait 120s --kubeconfig \
|
$ kind create cluster --name ephemeral-cluster --wait 120s --kubeconfig \
|
||||||
"${HOME}/.airship/kubeconfig" \
|
"${HOME}/.airship/kubeconfig" \
|
||||||
--config ./tools/deployment/templates/kind-cluster-with-extramounts
|
--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 \
|
$ kubectl config set-context ephemeral-cluster \
|
||||||
--cluster kind-ephemeral-cluster \
|
--cluster kind-ephemeral-cluster \
|
||||||
|
@ -166,11 +166,9 @@ $ cat ~/.airship/config
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
default:
|
default:
|
||||||
contextKubeconf: ""
|
|
||||||
managementConfiguration: default
|
managementConfiguration: default
|
||||||
manifest: default
|
manifest: default
|
||||||
ephemeral-cluster:
|
ephemeral-cluster:
|
||||||
contextKubeconf: ephemeral-cluster
|
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: gcp_manifest
|
manifest: gcp_manifest
|
||||||
currentContext: ephemeral-cluster
|
currentContext: ephemeral-cluster
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
dummy_cluster:
|
dummy_cluster:
|
||||||
contextKubeconf: dummycluster_ephemeral
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
currentContext: dummy_cluster
|
currentContext: dummy_cluster
|
||||||
kind: Config
|
kind: Config
|
||||||
|
@ -282,7 +282,6 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context {
|
|||||||
// Create the new Airship config context
|
// Create the new Airship config context
|
||||||
nContext := NewContext()
|
nContext := NewContext()
|
||||||
c.Contexts[theContext.Name] = nContext
|
c.Contexts[theContext.Name] = nContext
|
||||||
nContext.NameInKubeconf = theContext.Name
|
|
||||||
|
|
||||||
// Ok , I have initialized structs for the Context information
|
// Ok , I have initialized structs for the Context information
|
||||||
// We can use Modify to populate the correct information
|
// We can use Modify to populate the correct information
|
||||||
@ -482,13 +481,13 @@ func (c *Config) CurrentContextManagementConfig() (*ManagementConfiguration, err
|
|||||||
|
|
||||||
if currentContext.ManagementConfiguration == "" {
|
if currentContext.ManagementConfiguration == "" {
|
||||||
return nil, ErrMissingConfig{
|
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]
|
managementCfg, exists := c.ManagementConfiguration[currentContext.ManagementConfiguration]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, ErrMissingManagementConfiguration{context: currentContext}
|
return nil, ErrMissingManagementConfiguration{contextName: c.CurrentContext}
|
||||||
}
|
}
|
||||||
|
|
||||||
return managementCfg, nil
|
return managementCfg, nil
|
||||||
|
@ -245,8 +245,7 @@ func TestGetContext(t *testing.T) {
|
|||||||
context, err := conf.GetContext("def_ephemeral")
|
context, err := conf.GetContext("def_ephemeral")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Test Positives
|
assert.EqualValues(t, context.Manifest, "dummy_manifest")
|
||||||
assert.EqualValues(t, context.NameInKubeconf, "def_ephemeral")
|
|
||||||
|
|
||||||
// Test Wrong Cluster
|
// Test Wrong Cluster
|
||||||
_, err = conf.GetContext("unknown")
|
_, 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),
|
// 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)
|
// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
|
||||||
type Context struct {
|
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
|
// Manifest is the default manifest to be use with this context
|
||||||
// +optional
|
// +optional
|
||||||
Manifest string `json:"manifest,omitempty"`
|
Manifest string `json:"manifest,omitempty"`
|
||||||
@ -37,8 +34,5 @@ func (c *Context) String() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return string(cyaml)
|
|
||||||
}
|
|
||||||
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.
|
// ErrMissingManagementConfiguration means the management configuration was not defined for the active cluster.
|
||||||
type ErrMissingManagementConfiguration struct {
|
type ErrMissingManagementConfiguration struct {
|
||||||
context *Context
|
contextName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrMissingManagementConfiguration) Error() string {
|
func (e ErrMissingManagementConfiguration) Error() string {
|
||||||
return fmt.Sprintf("Management configuration %s for cluster %s undefined.", e.context.ManagementConfiguration,
|
return fmt.Sprintf("Management configuration for context '%s' undefined.", e.contextName)
|
||||||
e.context.NameInKubeconf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrMissingPhaseRepo returned when Phase Repository is not set in context manifest
|
// ErrMissingPhaseRepo returned when Phase Repository is not set in context manifest
|
||||||
|
1
pkg/config/testdata/config-string.yaml
vendored
1
pkg/config/testdata/config-string.yaml
vendored
@ -1,7 +1,6 @@
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
dummy_context:
|
dummy_context:
|
||||||
contextKubeconf: dummy_cluster_ephemeral
|
|
||||||
managementConfiguration: dummy_management_config
|
managementConfiguration: dummy_management_config
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
currentContext: dummy_context
|
currentContext: dummy_context
|
||||||
|
1
pkg/config/testdata/context-string.yaml
vendored
1
pkg/config/testdata/context-string.yaml
vendored
@ -1,3 +1,2 @@
|
|||||||
contextKubeconf: dummy_cluster_ephemeral
|
|
||||||
managementConfiguration: dummy_management_config
|
managementConfiguration: dummy_management_config
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
|
@ -587,7 +587,6 @@ func testConfig(t *testing.T) *config.Config {
|
|||||||
confString := `apiVersion: airshipit.org/v1alpha1
|
confString := `apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
dummy_cluster:
|
dummy_cluster:
|
||||||
contextKubeconf: dummy_cluster
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
currentContext: dummy_cluster
|
currentContext: dummy_cluster
|
||||||
kind: Config
|
kind: Config
|
||||||
|
1
pkg/phase/testdata/airshipconfig.yaml
vendored
1
pkg/phase/testdata/airshipconfig.yaml
vendored
@ -1,7 +1,6 @@
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
dummy_cluster:
|
dummy_cluster:
|
||||||
contextKubeconf: dummycluster_ephemeral
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
currentContext: dummy_cluster
|
currentContext: dummy_cluster
|
||||||
kind: Config
|
kind: Config
|
||||||
|
1
testdata/k8s/config.yaml
vendored
1
testdata/k8s/config.yaml
vendored
@ -1,7 +1,6 @@
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
default:
|
default:
|
||||||
contextKubeconf: default_target
|
|
||||||
manifest: default
|
manifest: default
|
||||||
currentContext: ""
|
currentContext: ""
|
||||||
kind: Config
|
kind: Config
|
||||||
|
@ -52,7 +52,6 @@ func DummyConfig() *config.Config {
|
|||||||
// DummyContext creates a Context config object for unit testing
|
// DummyContext creates a Context config object for unit testing
|
||||||
func DummyContext() *config.Context {
|
func DummyContext() *config.Context {
|
||||||
c := config.NewContext()
|
c := config.NewContext()
|
||||||
c.NameInKubeconf = "dummy_cluster_ephemeral"
|
|
||||||
c.Manifest = "dummy_manifest"
|
c.Manifest = "dummy_manifest"
|
||||||
c.ManagementConfiguration = "dummy_management_config"
|
c.ManagementConfiguration = "dummy_management_config"
|
||||||
return c
|
return c
|
||||||
@ -163,12 +162,9 @@ const (
|
|||||||
testConfigYAML = `apiVersion: airshipit.org/v1alpha1
|
testConfigYAML = `apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
def_ephemeral:
|
def_ephemeral:
|
||||||
contextKubeconf: def_ephemeral
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
def_target:
|
def_target:
|
||||||
contextKubeconf: def_target
|
|
||||||
onlyink:
|
onlyink:
|
||||||
contextKubeconf: onlyinkubeconf_target
|
|
||||||
encryptionConfigs: {}
|
encryptionConfigs: {}
|
||||||
currentContext: def_ephemeral
|
currentContext: def_ephemeral
|
||||||
kind: Config
|
kind: Config
|
||||||
|
@ -8,11 +8,9 @@ managementConfiguration:
|
|||||||
systemRebootDelay: ${SYSTEM_REBOOT_DELAY}
|
systemRebootDelay: ${SYSTEM_REBOOT_DELAY}
|
||||||
contexts:
|
contexts:
|
||||||
ephemeral-cluster:
|
ephemeral-cluster:
|
||||||
contextKubeconf: ephemeral-cluster_ephemeral
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
managementConfiguration: dummy_management_config
|
managementConfiguration: dummy_management_config
|
||||||
target-cluster:
|
target-cluster:
|
||||||
contextKubeconf: target-cluster_target
|
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
managementConfiguration: dummy_management_config
|
managementConfiguration: dummy_management_config
|
||||||
currentContext: ephemeral-cluster
|
currentContext: ephemeral-cluster
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
kind-capi-azure:
|
kind-capi-azure:
|
||||||
contextKubeconf: kind-capi-azure_target
|
|
||||||
manifest: azure_manifest
|
manifest: azure_manifest
|
||||||
currentContext: kind-capi-azure
|
currentContext: kind-capi-azure
|
||||||
kind: Config
|
kind: Config
|
||||||
|
@ -54,7 +54,6 @@ function generate_airshipconf() {
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
contexts:
|
contexts:
|
||||||
${CONTEXT}_${cluster}:
|
${CONTEXT}_${cluster}:
|
||||||
contextKubeconf: ${CONTEXT}_${cluster}
|
|
||||||
manifest: ${CONTEXT}_${cluster}
|
manifest: ${CONTEXT}_${cluster}
|
||||||
managementConfiguration: default
|
managementConfiguration: default
|
||||||
currentContext: ${CONTEXT}_${cluster}
|
currentContext: ${CONTEXT}_${cluster}
|
||||||
|
Loading…
Reference in New Issue
Block a user