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:
Ruslan Aliev 2020-10-07 22:26:54 -05:00
parent 23224e57c5
commit 0c870e5244
28 changed files with 44 additions and 294 deletions

View File

@ -63,7 +63,7 @@ func NewGetContextCommand(cfgFactory config.Factory) *cobra.Command {
fmt.Fprintln(cmd.OutOrStdout(), "No Contexts found in the configuration.")
}
for _, context := range contexts {
fmt.Fprintln(cmd.OutOrStdout(), context.PrettyString())
fmt.Fprintln(cmd.OutOrStdout(), context.String())
}
return nil
}
@ -76,7 +76,7 @@ func NewGetContextCommand(cfgFactory config.Factory) *cobra.Command {
if err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), context.PrettyString())
fmt.Fprintln(cmd.OutOrStdout(), context.String())
return nil
},
}

View File

@ -98,12 +98,6 @@ func addSetContextFlags(o *config.ContextOptions, cmd *cobra.Command) {
"",
"set the encryption config for the specified context")
flags.StringVar(
&o.ClusterType,
"cluster-type",
"",
"set the cluster-type for the specified context")
flags.BoolVar(
&o.Current,
"current",

View File

@ -81,7 +81,6 @@ func TestSetContext(t *testing.T) {
testName: "set-context",
contextName: "dummycontext",
flags: []string{
"--cluster-type=target",
"--manifest=" + defaultManifest,
"--encryption-config=" + testEncryptionConfig,
},

View File

@ -16,7 +16,6 @@ airshipctl config set-context \
Flags:
--cluster-type string set the cluster-type for the specified context
--current update the current context
--encryption-config string set the encryption config for the specified context
-h, --help help for set-context

View File

@ -17,7 +17,6 @@ airshipctl config set-context \
Flags:
--cluster-type string set the cluster-type for the specified context
--current update the current context
--encryption-config string set the encryption config for the specified context
-h, --help help for set-context

View File

@ -1,18 +1,12 @@
Context: ContextBar
contextKubeconf: ContextBar_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextBar
Context: ContextBaz
contextKubeconf: ContextBaz_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextBaz
Context: ContextFoo
contextKubeconf: ContextFoo_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextFoo

View File

@ -1,6 +1,4 @@
Context: ContextFoo
contextKubeconf: ContextFoo_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextFoo

View File

@ -1,6 +1,4 @@
Context: ContextBaz
contextKubeconf: ContextBaz_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextBaz

View File

@ -1,18 +1,12 @@
Context: ContextBar
contextKubeconf: ContextBar_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextBar
Context: ContextBaz
contextKubeconf: ContextBaz_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextBaz
Context: ContextFoo
contextKubeconf: ContextFoo_ephemeral
managementConfiguration: ""
manifest: Manifest_ContextFoo

View File

@ -137,36 +137,6 @@ az-target-cluster-md-0-z5lff Ready <none> 17h v1.18.2
```yaml
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:
az-target-cluster-admin@az-target-cluster:
contextKubeconf: az-target-cluster_target
@ -208,6 +178,4 @@ manifests:
url: https://opendev.org/airship/treasuremap
subPath: treasuremap/manifests/site
targetPath: /tmp/default
users:
az-target-cluster-admin: {}
```

View File

@ -30,7 +30,6 @@ airshipctl config set-context \
### Options
```
--cluster-type string set the cluster-type for the specified context
--current update the current context
--encryption-config string set the encryption config for the specified context
-h, --help help for set-context

View File

@ -37,7 +37,6 @@ airshipctl secret decrypt \
```
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
--debug enable verbose output
--kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default "$HOME/.airship/kubeconfig")
```
### SEE ALSO

View File

@ -37,7 +37,6 @@ airshipctl secret encrypt \
```
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
--debug enable verbose output
--kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default "$HOME/.airship/kubeconfig")
```
### SEE ALSO

View File

@ -20,6 +20,7 @@ import (
"opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/pkg/document"
"opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/pkg/phase"
)
// 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) {
path, err := conf.CurrentContextEntryPoint(config.ClusterctlPhase)
helper, err := phase.NewHelper(conf)
if err != nil {
return nil, err
}
return document.NewBundleByPath(path)
return document.NewBundleByPath(helper.PhaseRoot())
}
// Move runs clusterctl move

View File

@ -48,6 +48,7 @@ func TestNewCommand(t *testing.T) {
TargetPath: "testdata",
SubPath: "valid",
PhaseRepositoryName: "primary",
MetadataPath: "metadata.yaml",
Repositories: map[string]*config.Repository{
"primary": {},
},

2
pkg/clusterctl/cmd/testdata/metadata.yaml vendored Executable file
View File

@ -0,0 +1,2 @@
phase:
path: phases

View File

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

View File

@ -0,0 +1,6 @@
---
apiVersion: airshipit.org/v1alpha1
kind: Clusterctl
metadata:
name: clusterctl_init
action: init

View File

@ -0,0 +1,4 @@
resources:
- phases.yaml
- executors.yaml
- cluster-map.yaml

View File

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

View File

@ -18,7 +18,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"sort"
@ -285,7 +284,6 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context {
// Ok , I have initialized structs for the Context information
// We can use Modify to populate the correct information
c.ModifyContext(nContext, theContext)
nContext.ClusterType()
return nContext
}
@ -304,9 +302,6 @@ func (c *Config) ModifyContext(context *Context, theContext *ContextOptions) {
// GetCurrentContext methods Returns the appropriate information for the current context
// 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) {
currentContext, err := c.GetContext(c.CurrentContext)
if err != nil {
@ -326,29 +321,6 @@ func (c *Config) CurrentContextManifest() (*Manifest, error) {
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
func (c *Config) CurrentContextTargetPath() (string, error) {
ccm, err := c.CurrentContextManifest()
@ -372,24 +344,6 @@ func (c *Config) CurrentContextPhaseRepositoryDir() (string, error) {
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
func (c *Config) GetManifests() []*Manifest {
keys := make([]string, 0, len(c.Manifests))

View File

@ -337,50 +337,6 @@ func TestCurrentPhaseRepositoryDir(t *testing.T) {
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) {
expectedMeta := &config.Metadata{
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) {
conf, cleanupConfig := testutil.InitConfig(t)
defer cleanupConfig(t)

View File

@ -16,24 +16,14 @@ package config
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
const (
Ephemeral = "ephemeral"
InitinfraPhase = "initinfra"
ClusterctlPhase = InitinfraPhase
BootstrapPhase = "bootstrap"
)
// AllClusterTypes holds cluster types
var AllClusterTypes = [2]string{Ephemeral, Target}
// Constants defining default values
const (
AirshipConfig = "config"
@ -50,8 +40,6 @@ const (
AirshipDefaultManifest = "default"
AirshipDefaultManifestRepo = "treasuremap"
AirshipDefaultManifestRepoLocation = "https://opendev.org/airship/" + AirshipDefaultManifestRepo
AirshipKubeConfig = "kubeconfig"
AirshipKubeConfigEnv = "AIRSHIP_KUBECONFIG"
AirshipPluginPath = "kustomize-plugins"
AirshipPluginPathEnv = "AIRSHIP_KUSTOMIZE_PLUGINS"

View File

@ -15,9 +15,6 @@ limitations under the License.
package config
import (
"fmt"
"strings"
"sigs.k8s.io/yaml"
)
@ -49,66 +46,3 @@ func (c *Context) String() string {
}
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)
}

View File

@ -23,7 +23,6 @@ import (
// ContextOptions holds all configurable options for context
type ContextOptions struct {
Name string
ClusterType string
CurrentContext bool
Manifest string
Current bool

View File

@ -50,14 +50,6 @@ func TestContextOptionsValidate(t *testing.T) {
},
expectError: false,
},
{
name: "ValidClusterType",
testOptions: config.ContextOptions{
Name: "testContext",
ClusterType: "target",
},
expectError: false,
},
}
for _, tt := range tests {

View File

@ -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
type BundleFactoryFunc func() (Bundle, error)
// NewBundleByPath helper function that returns new document.Bundle interface based on clusterType and
// phase, example: helpers.NewBunde(airConfig, "ephemeral", "initinfra")
// NewBundleByPath is a function which builds new document.Bundle from kustomize rootPath using default FS object
// example: document.NewBundleByPath("path/to/phase-root")
func NewBundleByPath(rootPath string) (Bundle, error) {
return NewBundle(NewDocumentFs(), rootPath)
}

View File

@ -1,11 +1,4 @@
apiVersion: airshipit.org/v1alpha1
clusters:
kind-capi-azure:
clusterType:
target:
bootstrapInfo: default
clusterKubeconf: kind-capi-azure_target
managementConfiguration: default
contexts:
kind-capi-azure:
contextKubeconf: kind-capi-azure_target