Remove clustertype-related functions
We don't use clustertype anymore, so all the related functions must be deleted or adjusted as well as appropriate config fields. Change-Id: I3931fdc71d4318e916f8bbc2d94e062c9df5f641 Signed-off-by: Ruslan Aliev <raliev@mirantis.com> Relates-To: #349
This commit is contained in:
parent
23224e57c5
commit
0c870e5244
|
@ -63,7 +63,7 @@ func NewGetContextCommand(cfgFactory config.Factory) *cobra.Command {
|
||||||
fmt.Fprintln(cmd.OutOrStdout(), "No Contexts found in the configuration.")
|
fmt.Fprintln(cmd.OutOrStdout(), "No Contexts found in the configuration.")
|
||||||
}
|
}
|
||||||
for _, context := range contexts {
|
for _, context := range contexts {
|
||||||
fmt.Fprintln(cmd.OutOrStdout(), context.PrettyString())
|
fmt.Fprintln(cmd.OutOrStdout(), context.String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func NewGetContextCommand(cfgFactory config.Factory) *cobra.Command {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(cmd.OutOrStdout(), context.PrettyString())
|
fmt.Fprintln(cmd.OutOrStdout(), context.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,12 +98,6 @@ func addSetContextFlags(o *config.ContextOptions, cmd *cobra.Command) {
|
||||||
"",
|
"",
|
||||||
"set the encryption config for the specified context")
|
"set the encryption config for the specified context")
|
||||||
|
|
||||||
flags.StringVar(
|
|
||||||
&o.ClusterType,
|
|
||||||
"cluster-type",
|
|
||||||
"",
|
|
||||||
"set the cluster-type for the specified context")
|
|
||||||
|
|
||||||
flags.BoolVar(
|
flags.BoolVar(
|
||||||
&o.Current,
|
&o.Current,
|
||||||
"current",
|
"current",
|
||||||
|
|
|
@ -81,7 +81,6 @@ func TestSetContext(t *testing.T) {
|
||||||
testName: "set-context",
|
testName: "set-context",
|
||||||
contextName: "dummycontext",
|
contextName: "dummycontext",
|
||||||
flags: []string{
|
flags: []string{
|
||||||
"--cluster-type=target",
|
|
||||||
"--manifest=" + defaultManifest,
|
"--manifest=" + defaultManifest,
|
||||||
"--encryption-config=" + testEncryptionConfig,
|
"--encryption-config=" + testEncryptionConfig,
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,7 +16,6 @@ airshipctl config set-context \
|
||||||
|
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--cluster-type string set the cluster-type for the specified context
|
|
||||||
--current update the current context
|
--current update the current context
|
||||||
--encryption-config string set the encryption config for the specified context
|
--encryption-config string set the encryption config for the specified context
|
||||||
-h, --help help for set-context
|
-h, --help help for set-context
|
||||||
|
|
|
@ -17,7 +17,6 @@ airshipctl config set-context \
|
||||||
|
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--cluster-type string set the cluster-type for the specified context
|
|
||||||
--current update the current context
|
--current update the current context
|
||||||
--encryption-config string set the encryption config for the specified context
|
--encryption-config string set the encryption config for the specified context
|
||||||
-h, --help help for set-context
|
-h, --help help for set-context
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
Context: ContextBar
|
|
||||||
contextKubeconf: ContextBar_ephemeral
|
contextKubeconf: ContextBar_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBar
|
manifest: Manifest_ContextBar
|
||||||
|
|
||||||
|
|
||||||
Context: ContextBaz
|
|
||||||
contextKubeconf: ContextBaz_ephemeral
|
contextKubeconf: ContextBaz_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
|
|
||||||
Context: ContextFoo
|
|
||||||
contextKubeconf: ContextFoo_ephemeral
|
contextKubeconf: ContextFoo_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
Context: ContextFoo
|
|
||||||
contextKubeconf: ContextFoo_ephemeral
|
contextKubeconf: ContextFoo_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
Context: ContextBaz
|
|
||||||
contextKubeconf: ContextBaz_ephemeral
|
contextKubeconf: ContextBaz_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
Context: ContextBar
|
|
||||||
contextKubeconf: ContextBar_ephemeral
|
contextKubeconf: ContextBar_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBar
|
manifest: Manifest_ContextBar
|
||||||
|
|
||||||
|
|
||||||
Context: ContextBaz
|
|
||||||
contextKubeconf: ContextBaz_ephemeral
|
contextKubeconf: ContextBaz_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextBaz
|
manifest: Manifest_ContextBaz
|
||||||
|
|
||||||
|
|
||||||
Context: ContextFoo
|
|
||||||
contextKubeconf: ContextFoo_ephemeral
|
contextKubeconf: ContextFoo_ephemeral
|
||||||
managementConfiguration: ""
|
managementConfiguration: ""
|
||||||
manifest: Manifest_ContextFoo
|
manifest: Manifest_ContextFoo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -137,36 +137,6 @@ az-target-cluster-md-0-z5lff Ready <none> 17h v1.18.2
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
bootstrapInfo:
|
|
||||||
azure_bootstrap_config:
|
|
||||||
builder:
|
|
||||||
networkConfigFileName: network-config
|
|
||||||
outputMetadataFileName: output-metadata.yaml
|
|
||||||
userDataFileName: user-data
|
|
||||||
container:
|
|
||||||
containerRuntime: docker
|
|
||||||
image: quay.io/airshipit/isogen:latest-debian_stable
|
|
||||||
volume: /srv/iso:/config
|
|
||||||
remoteDirect:
|
|
||||||
isoUrl: http://localhost:8099/debian-custom.iso
|
|
||||||
default:
|
|
||||||
builder:
|
|
||||||
networkConfigFileName: network-config
|
|
||||||
outputMetadataFileName: output-metadata.yaml
|
|
||||||
userDataFileName: user-data
|
|
||||||
container:
|
|
||||||
containerRuntime: docker
|
|
||||||
image: quay.io/airshipit/isogen:latest-debian_stable
|
|
||||||
volume: /srv/iso:/config
|
|
||||||
remoteDirect:
|
|
||||||
isoUrl: http://localhost:8099/debian-custom.iso
|
|
||||||
clusters:
|
|
||||||
az-target-cluster:
|
|
||||||
clusterType:
|
|
||||||
target:
|
|
||||||
bootstrapInfo: default
|
|
||||||
clusterKubeconf: az-target-cluster_target
|
|
||||||
managementConfiguration: default
|
|
||||||
contexts:
|
contexts:
|
||||||
az-target-cluster-admin@az-target-cluster:
|
az-target-cluster-admin@az-target-cluster:
|
||||||
contextKubeconf: az-target-cluster_target
|
contextKubeconf: az-target-cluster_target
|
||||||
|
@ -208,6 +178,4 @@ manifests:
|
||||||
url: https://opendev.org/airship/treasuremap
|
url: https://opendev.org/airship/treasuremap
|
||||||
subPath: treasuremap/manifests/site
|
subPath: treasuremap/manifests/site
|
||||||
targetPath: /tmp/default
|
targetPath: /tmp/default
|
||||||
users:
|
|
||||||
az-target-cluster-admin: {}
|
|
||||||
```
|
```
|
|
@ -30,7 +30,6 @@ airshipctl config set-context \
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--cluster-type string set the cluster-type for the specified context
|
|
||||||
--current update the current context
|
--current update the current context
|
||||||
--encryption-config string set the encryption config for the specified context
|
--encryption-config string set the encryption config for the specified context
|
||||||
-h, --help help for set-context
|
-h, --help help for set-context
|
||||||
|
|
|
@ -37,7 +37,6 @@ airshipctl secret decrypt \
|
||||||
```
|
```
|
||||||
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
|
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
|
||||||
--debug enable verbose output
|
--debug enable verbose output
|
||||||
--kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default "$HOME/.airship/kubeconfig")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
|
@ -37,7 +37,6 @@ airshipctl secret encrypt \
|
||||||
```
|
```
|
||||||
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
|
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
|
||||||
--debug enable verbose output
|
--debug enable verbose output
|
||||||
--kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default "$HOME/.airship/kubeconfig")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"opendev.org/airship/airshipctl/pkg/config"
|
"opendev.org/airship/airshipctl/pkg/config"
|
||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
"opendev.org/airship/airshipctl/pkg/log"
|
"opendev.org/airship/airshipctl/pkg/log"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/phase"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command adds a layer to clusterctl interface with airshipctl context
|
// Command adds a layer to clusterctl interface with airshipctl context
|
||||||
|
@ -89,11 +90,11 @@ func clusterctlOptions(bundle document.Bundle) (*airshipv1.Clusterctl, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBundle(conf *config.Config) (document.Bundle, error) {
|
func getBundle(conf *config.Config) (document.Bundle, error) {
|
||||||
path, err := conf.CurrentContextEntryPoint(config.ClusterctlPhase)
|
helper, err := phase.NewHelper(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return document.NewBundleByPath(path)
|
return document.NewBundleByPath(helper.PhaseRoot())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move runs clusterctl move
|
// Move runs clusterctl move
|
||||||
|
|
|
@ -48,6 +48,7 @@ func TestNewCommand(t *testing.T) {
|
||||||
TargetPath: "testdata",
|
TargetPath: "testdata",
|
||||||
SubPath: "valid",
|
SubPath: "valid",
|
||||||
PhaseRepositoryName: "primary",
|
PhaseRepositoryName: "primary",
|
||||||
|
MetadataPath: "metadata.yaml",
|
||||||
Repositories: map[string]*config.Repository{
|
Repositories: map[string]*config.Repository{
|
||||||
"primary": {},
|
"primary": {},
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
phase:
|
||||||
|
path: phases
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: ClusterMap
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
airshipit.org/deploy-k8s: "false"
|
||||||
|
name: main-map
|
||||||
|
map:
|
||||||
|
target-cluster:
|
||||||
|
parent: ephemeral-cluster
|
||||||
|
ephemeral-cluster: {}
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: Clusterctl
|
||||||
|
metadata:
|
||||||
|
name: clusterctl_init
|
||||||
|
action: init
|
|
@ -0,0 +1,4 @@
|
||||||
|
resources:
|
||||||
|
- phases.yaml
|
||||||
|
- executors.yaml
|
||||||
|
- cluster-map.yaml
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: Phase
|
||||||
|
metadata:
|
||||||
|
name: phase
|
||||||
|
clusterName: ephemeral-cluster
|
||||||
|
config:
|
||||||
|
executorRef:
|
||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: KubernetesApply
|
||||||
|
name: kubernetes-apply
|
||||||
|
documentEntryPoint: ephemeral/initinfra
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -285,7 +284,6 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context {
|
||||||
// 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
|
||||||
c.ModifyContext(nContext, theContext)
|
c.ModifyContext(nContext, theContext)
|
||||||
nContext.ClusterType()
|
|
||||||
return nContext
|
return nContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,9 +302,6 @@ func (c *Config) ModifyContext(context *Context, theContext *ContextOptions) {
|
||||||
|
|
||||||
// GetCurrentContext methods Returns the appropriate information for the current context
|
// GetCurrentContext methods Returns the appropriate information for the current context
|
||||||
// Current Context holds labels for the appropriate config objects
|
// Current Context holds labels for the appropriate config objects
|
||||||
// ClusterType is the name of the clustertype for this context, it should be a flag we pass to it??
|
|
||||||
// Manifest is the default manifest to be use with this context
|
|
||||||
// Purpose for this method is simplifying the current context information
|
|
||||||
func (c *Config) GetCurrentContext() (*Context, error) {
|
func (c *Config) GetCurrentContext() (*Context, error) {
|
||||||
currentContext, err := c.GetContext(c.CurrentContext)
|
currentContext, err := c.GetContext(c.CurrentContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -326,29 +321,6 @@ func (c *Config) CurrentContextManifest() (*Manifest, error) {
|
||||||
return c.Manifests[currentContext.Manifest], nil
|
return c.Manifests[currentContext.Manifest], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentContextEntryPoint returns path to build bundle based on clusterType and phase
|
|
||||||
// example CurrentContextEntryPoint("ephemeral", "initinfra")
|
|
||||||
func (c *Config) CurrentContextEntryPoint(phase string) (string, error) {
|
|
||||||
clusterType, err := c.CurrentContextClusterType()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
ccm, err := c.CurrentContextManifest()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
_, exists := ccm.Repositories[ccm.PhaseRepositoryName]
|
|
||||||
if !exists {
|
|
||||||
return "", ErrMissingPhaseRepo{}
|
|
||||||
}
|
|
||||||
epp := path.Join(ccm.TargetPath, ccm.SubPath, clusterType, phase)
|
|
||||||
if _, err := os.Stat(epp); err != nil {
|
|
||||||
return "", ErrMissingPhaseDocument{PhaseName: phase}
|
|
||||||
}
|
|
||||||
return epp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CurrentContextTargetPath returns target path from current context's manifest
|
// CurrentContextTargetPath returns target path from current context's manifest
|
||||||
func (c *Config) CurrentContextTargetPath() (string, error) {
|
func (c *Config) CurrentContextTargetPath() (string, error) {
|
||||||
ccm, err := c.CurrentContextManifest()
|
ccm, err := c.CurrentContextManifest()
|
||||||
|
@ -372,24 +344,6 @@ func (c *Config) CurrentContextPhaseRepositoryDir() (string, error) {
|
||||||
return util.GitDirNameFromURL(repo.URL()), nil
|
return util.GitDirNameFromURL(repo.URL()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentContextClusterType returns cluster type of current context
|
|
||||||
func (c *Config) CurrentContextClusterType() (string, error) {
|
|
||||||
context, err := c.GetCurrentContext()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return context.ClusterType(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CurrentContextClusterName returns cluster name of current context
|
|
||||||
func (c *Config) CurrentContextClusterName() (string, error) {
|
|
||||||
context, err := c.GetCurrentContext()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return context.ClusterName(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetManifests returns all of the Manifests associated with the Config sorted by name
|
// GetManifests returns all of the Manifests associated with the Config sorted by name
|
||||||
func (c *Config) GetManifests() []*Manifest {
|
func (c *Config) GetManifests() []*Manifest {
|
||||||
keys := make([]string, 0, len(c.Manifests))
|
keys := make([]string, 0, len(c.Manifests))
|
||||||
|
|
|
@ -337,50 +337,6 @@ func TestCurrentPhaseRepositoryDir(t *testing.T) {
|
||||||
assert.Equal(t, "", phaseRepoDir)
|
assert.Equal(t, "", phaseRepoDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCurrentContextEntryPoint(t *testing.T) {
|
|
||||||
conf, cleanup := testutil.InitConfig(t)
|
|
||||||
defer cleanup(t)
|
|
||||||
|
|
||||||
entryPoint, err := conf.CurrentContextEntryPoint(defaultString)
|
|
||||||
require.Error(t, err)
|
|
||||||
assert.Equal(t, "", entryPoint)
|
|
||||||
|
|
||||||
conf.CurrentContext = currentContextName
|
|
||||||
conf.Contexts[currentContextName].Manifest = defaultString
|
|
||||||
|
|
||||||
entryPoint, err = conf.CurrentContextEntryPoint(defaultString)
|
|
||||||
assert.Equal(t, config.ErrMissingPhaseDocument{PhaseName: defaultString}, err)
|
|
||||||
assert.Nil(t, nil, entryPoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCurrentContextClusterType(t *testing.T) {
|
|
||||||
conf, cleanup := testutil.InitConfig(t)
|
|
||||||
defer cleanup(t)
|
|
||||||
|
|
||||||
expectedClusterType := "ephemeral"
|
|
||||||
|
|
||||||
conf.CurrentContext = currentContextName
|
|
||||||
conf.Contexts[currentContextName].Manifest = defaultString
|
|
||||||
|
|
||||||
actualClusterType, err := conf.CurrentContextClusterType()
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, expectedClusterType, actualClusterType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCurrentContextClusterName(t *testing.T) {
|
|
||||||
conf, cleanup := testutil.InitConfig(t)
|
|
||||||
defer cleanup(t)
|
|
||||||
|
|
||||||
expectedClusterName := "def"
|
|
||||||
|
|
||||||
conf.CurrentContext = currentContextName
|
|
||||||
conf.Contexts[currentContextName].Manifest = defaultString
|
|
||||||
|
|
||||||
actualClusterName, err := conf.CurrentContextClusterName()
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, expectedClusterName, actualClusterName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCurrentContextManifestMetadata(t *testing.T) {
|
func TestCurrentContextManifestMetadata(t *testing.T) {
|
||||||
expectedMeta := &config.Metadata{
|
expectedMeta := &config.Metadata{
|
||||||
Inventory: &config.InventoryMeta{
|
Inventory: &config.InventoryMeta{
|
||||||
|
@ -469,49 +425,6 @@ func TestCurrentContextManifestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewClusterComplexNameFromKubeClusterName(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
inputName string
|
|
||||||
expectedName string
|
|
||||||
expectedType string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "single-word",
|
|
||||||
inputName: "myCluster",
|
|
||||||
expectedName: "myCluster",
|
|
||||||
expectedType: config.AirshipDefaultClusterType,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "multi-word",
|
|
||||||
inputName: "myCluster_two",
|
|
||||||
expectedName: "myCluster_two",
|
|
||||||
expectedType: config.AirshipDefaultClusterType,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "cluster-appended",
|
|
||||||
inputName: "myCluster_ephemeral",
|
|
||||||
expectedName: "myCluster",
|
|
||||||
expectedType: config.Ephemeral,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "multi-word-cluster-appended",
|
|
||||||
inputName: "myCluster_two_ephemeral",
|
|
||||||
expectedName: "myCluster_two",
|
|
||||||
expectedType: config.Ephemeral,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
tt := tt
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
complexName := config.NewClusterComplexNameFromKubeClusterName(tt.inputName)
|
|
||||||
assert.Equal(t, tt.expectedName, complexName.Name)
|
|
||||||
assert.Equal(t, tt.expectedType, complexName.Type)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementConfigurationByName(t *testing.T) {
|
func TestManagementConfigurationByName(t *testing.T) {
|
||||||
conf, cleanupConfig := testutil.InitConfig(t)
|
conf, cleanupConfig := testutil.InitConfig(t)
|
||||||
defer cleanupConfig(t)
|
defer cleanupConfig(t)
|
||||||
|
|
|
@ -16,24 +16,14 @@ package config
|
||||||
|
|
||||||
import "opendev.org/airship/airshipctl/pkg/remote/redfish"
|
import "opendev.org/airship/airshipctl/pkg/remote/redfish"
|
||||||
|
|
||||||
// Constants related to the ClusterType type
|
|
||||||
const (
|
|
||||||
Ephemeral = "ephemeral"
|
|
||||||
Target = "target"
|
|
||||||
AirshipClusterNameSeparator = "_"
|
|
||||||
AirshipDefaultClusterType = Target
|
|
||||||
)
|
|
||||||
|
|
||||||
// Constants related to Phases
|
// Constants related to Phases
|
||||||
const (
|
const (
|
||||||
|
Ephemeral = "ephemeral"
|
||||||
InitinfraPhase = "initinfra"
|
InitinfraPhase = "initinfra"
|
||||||
ClusterctlPhase = InitinfraPhase
|
ClusterctlPhase = InitinfraPhase
|
||||||
BootstrapPhase = "bootstrap"
|
BootstrapPhase = "bootstrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AllClusterTypes holds cluster types
|
|
||||||
var AllClusterTypes = [2]string{Ephemeral, Target}
|
|
||||||
|
|
||||||
// Constants defining default values
|
// Constants defining default values
|
||||||
const (
|
const (
|
||||||
AirshipConfig = "config"
|
AirshipConfig = "config"
|
||||||
|
@ -50,8 +40,6 @@ const (
|
||||||
AirshipDefaultManifest = "default"
|
AirshipDefaultManifest = "default"
|
||||||
AirshipDefaultManifestRepo = "treasuremap"
|
AirshipDefaultManifestRepo = "treasuremap"
|
||||||
AirshipDefaultManifestRepoLocation = "https://opendev.org/airship/" + AirshipDefaultManifestRepo
|
AirshipDefaultManifestRepoLocation = "https://opendev.org/airship/" + AirshipDefaultManifestRepo
|
||||||
AirshipKubeConfig = "kubeconfig"
|
|
||||||
AirshipKubeConfigEnv = "AIRSHIP_KUBECONFIG"
|
|
||||||
AirshipPluginPath = "kustomize-plugins"
|
AirshipPluginPath = "kustomize-plugins"
|
||||||
AirshipPluginPathEnv = "AIRSHIP_KUSTOMIZE_PLUGINS"
|
AirshipPluginPathEnv = "AIRSHIP_KUSTOMIZE_PLUGINS"
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,6 @@ limitations under the License.
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,66 +46,3 @@ func (c *Context) String() string {
|
||||||
}
|
}
|
||||||
return string(cyaml)
|
return string(cyaml)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrettyString returns cluster name in a formatted string
|
|
||||||
func (c *Context) PrettyString() string {
|
|
||||||
clusterName := NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf)
|
|
||||||
return fmt.Sprintf("Context: %s\n%s\n", clusterName.Name, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClusterType returns cluster type by extracting the type portion from
|
|
||||||
// the complex cluster name
|
|
||||||
func (c *Context) ClusterType() string {
|
|
||||||
return NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf).Type
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClusterName returns cluster name by extracting the name portion from
|
|
||||||
// the complex cluster name
|
|
||||||
func (c *Context) ClusterName() string {
|
|
||||||
return NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf).Name
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClusterComplexName holds the complex cluster name information
|
|
||||||
// Encapsulates the different operations around using it.
|
|
||||||
type ClusterComplexName struct {
|
|
||||||
Name string
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewClusterComplexName returns a ClusterComplexName with the given name and type.
|
|
||||||
func NewClusterComplexName(clusterName, clusterType string) ClusterComplexName {
|
|
||||||
return ClusterComplexName{
|
|
||||||
Name: clusterName,
|
|
||||||
Type: clusterType,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewClusterComplexNameFromKubeClusterName takes the name of a cluster in a
|
|
||||||
// format which might be found in a kubeconfig file. This may be a simple
|
|
||||||
// string (e.g. myCluster), or it may be prepended with the type of the cluster
|
|
||||||
// (e.g. myCluster_target)
|
|
||||||
//
|
|
||||||
// If a valid cluster type was appended, the returned ClusterComplexName will
|
|
||||||
// have that type. If no cluster type is provided, the
|
|
||||||
// AirshipDefaultClusterType will be used.
|
|
||||||
func NewClusterComplexNameFromKubeClusterName(kubeClusterName string) ClusterComplexName {
|
|
||||||
parts := strings.Split(kubeClusterName, AirshipClusterNameSeparator)
|
|
||||||
|
|
||||||
if len(parts) == 1 {
|
|
||||||
return NewClusterComplexName(kubeClusterName, AirshipDefaultClusterType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// kubeClusterName matches the format myCluster_something.
|
|
||||||
// Let's check if "something" is a clusterType.
|
|
||||||
potentialType := parts[len(parts)-1]
|
|
||||||
for _, ct := range AllClusterTypes {
|
|
||||||
if potentialType == ct {
|
|
||||||
// Rejoin the parts in the case of "my_cluster_etc_etc_<clusterType>"
|
|
||||||
name := strings.Join(parts[:len(parts)-1], AirshipClusterNameSeparator)
|
|
||||||
return NewClusterComplexName(name, potentialType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// "something" is not a valid clusterType, so just use the default
|
|
||||||
return NewClusterComplexName(kubeClusterName, AirshipDefaultClusterType)
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
// ContextOptions holds all configurable options for context
|
// ContextOptions holds all configurable options for context
|
||||||
type ContextOptions struct {
|
type ContextOptions struct {
|
||||||
Name string
|
Name string
|
||||||
ClusterType string
|
|
||||||
CurrentContext bool
|
CurrentContext bool
|
||||||
Manifest string
|
Manifest string
|
||||||
Current bool
|
Current bool
|
||||||
|
|
|
@ -50,14 +50,6 @@ func TestContextOptionsValidate(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "ValidClusterType",
|
|
||||||
testOptions: config.ContextOptions{
|
|
||||||
Name: "testContext",
|
|
||||||
ClusterType: "target",
|
|
||||||
},
|
|
||||||
expectError: false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
@ -70,8 +70,8 @@ var pluginPathLock = &sync.Mutex{}
|
||||||
// instead of inplace, useful, when you don't know if bundle will be needed or not, see phase for detail
|
// instead of inplace, useful, when you don't know if bundle will be needed or not, see phase for detail
|
||||||
type BundleFactoryFunc func() (Bundle, error)
|
type BundleFactoryFunc func() (Bundle, error)
|
||||||
|
|
||||||
// NewBundleByPath helper function that returns new document.Bundle interface based on clusterType and
|
// NewBundleByPath is a function which builds new document.Bundle from kustomize rootPath using default FS object
|
||||||
// phase, example: helpers.NewBunde(airConfig, "ephemeral", "initinfra")
|
// example: document.NewBundleByPath("path/to/phase-root")
|
||||||
func NewBundleByPath(rootPath string) (Bundle, error) {
|
func NewBundleByPath(rootPath string) (Bundle, error) {
|
||||||
return NewBundle(NewDocumentFs(), rootPath)
|
return NewBundle(NewDocumentFs(), rootPath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
clusters:
|
|
||||||
kind-capi-azure:
|
|
||||||
clusterType:
|
|
||||||
target:
|
|
||||||
bootstrapInfo: default
|
|
||||||
clusterKubeconf: kind-capi-azure_target
|
|
||||||
managementConfiguration: default
|
|
||||||
contexts:
|
contexts:
|
||||||
kind-capi-azure:
|
kind-capi-azure:
|
||||||
contextKubeconf: kind-capi-azure_target
|
contextKubeconf: kind-capi-azure_target
|
||||||
|
|
Loading…
Reference in New Issue