diff --git a/pkg/config/authinfo.go b/pkg/config/authinfo.go index c28088e93..fa53eebc1 100644 --- a/pkg/config/authinfo.go +++ b/pkg/config/authinfo.go @@ -21,6 +21,7 @@ import ( "sigs.k8s.io/yaml" ) +// AuthInfo contains kubeConfig AuthInfo Object type AuthInfo struct { // KubeConfig AuthInfo Object authInfo *api.AuthInfo @@ -36,9 +37,12 @@ func (c *AuthInfo) String() string { return string(kyaml) } +// KubeAuthInfo returns kubeConfig AuthInfo Object func (c *AuthInfo) KubeAuthInfo() *api.AuthInfo { return c.authInfo } + +// SetKubeAuthInfo sets kubeConfig in AuthInfo func (c *AuthInfo) SetKubeAuthInfo(kc *api.AuthInfo) { c.authInfo = kc } diff --git a/pkg/config/cluster.go b/pkg/config/cluster.go index 045cdb9fe..9e4de83b8 100644 --- a/pkg/config/cluster.go +++ b/pkg/config/cluster.go @@ -66,22 +66,29 @@ func (c *Cluster) String() string { return fmt.Sprintf("%s\n%s", string(cyaml), string(kyaml)) } +// PrettyString returns cluster information in a formatted string func (c *Cluster) PrettyString() string { clusterName := NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf) return fmt.Sprintf("Cluster: %s\n%s:\n%s", clusterName.Name, clusterName.Type, c) } +// KubeCluster returns KubeConfig Cluster Object func (c *Cluster) KubeCluster() *api.Cluster { return c.cluster } + +// SetKubeCluster sets cluster in KubeConfig func (c *Cluster) SetKubeCluster(kc *api.Cluster) { c.cluster = kc } +// String returns cluster's complex name, formed by combining name and type with a delimiter('_') func (c *ClusterComplexName) String() string { return strings.Join([]string{c.Name, c.Type}, AirshipClusterNameSeparator) } +// ValidClusterType checks for the possible options for cluster type +// Returns error when invalid cluster type is given func ValidClusterType(clusterType string) error { for _, validType := range AllClusterTypes { if clusterType == validType { diff --git a/pkg/config/config.go b/pkg/config/config.go index 5e1cb9e5c..cd3603588 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -684,6 +684,7 @@ func (c *Config) CurrentContextTargetPath() (string, error) { return ccm.TargetPath, nil } +// CurrentContextClusterType returns cluster type of current context func (c *Config) CurrentContextClusterType() (string, error) { context, err := c.GetCurrentContext() if err != nil { @@ -692,6 +693,7 @@ func (c *Config) CurrentContextClusterType() (string, error) { return context.ClusterType(), nil } +// CurrentContextClusterName returns cluster name of current context func (c *Config) CurrentContextClusterName() (string, error) { context, err := c.GetCurrentContext() if err != nil { diff --git a/pkg/config/config_helper.go b/pkg/config/config_helper.go index 776d4bde8..a4f15e777 100644 --- a/pkg/config/config_helper.go +++ b/pkg/config/config_helper.go @@ -20,6 +20,7 @@ import ( "errors" ) +// RunSetAuthInfo validates the given command line options and invokes AddAuthInfo/ModifyAuthInfo func RunSetAuthInfo(o *AuthInfoOptions, airconfig *Config, writeToStorage bool) (bool, error) { modified := false err := o.Validate() @@ -54,6 +55,7 @@ func RunSetAuthInfo(o *AuthInfoOptions, airconfig *Config, writeToStorage bool) return modified, nil } +// RunSetCluster validates the given command line options and invokes AddCluster/ModifyCluster func RunSetCluster(o *ClusterOptions, airconfig *Config, writeToStorage bool) (bool, error) { modified := false err := o.Validate() @@ -98,6 +100,7 @@ func RunSetCluster(o *ClusterOptions, airconfig *Config, writeToStorage bool) (b return modified, nil } +// RunSetContext validates the given command line options and invokes AddContext/ModifyContext func RunSetContext(o *ContextOptions, airconfig *Config, writeToStorage bool) (bool, error) { modified := false err := o.Validate() @@ -148,6 +151,7 @@ func RunSetContext(o *ContextOptions, airconfig *Config, writeToStorage bool) (b return modified, nil } +// RunUseContext validates the given context name and updates it as current context func RunUseContext(desiredContext string, airconfig *Config) error { if _, err := airconfig.GetContext(desiredContext); err != nil { return err diff --git a/pkg/config/context.go b/pkg/config/context.go index 3844564c3..cd31a655e 100644 --- a/pkg/config/context.go +++ b/pkg/config/context.go @@ -72,6 +72,8 @@ 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 }