Skip to content

Commit

Permalink
toBeAppend validation with current kubectlConfig (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
btungut authored Feb 25, 2024
1 parent f3ddd08 commit fd65612
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ func ParseKubeConfig(path string) (*KubectlConfig, error) {
return &kubeConfig, nil
}

func validate(kubectlConfig KubectlConfig, name string) error {
func validate(toBeAppend KubectlConfig, kubectlConfig KubectlConfig, name string) error {

if len(kubectlConfig.Clusters) != 1 {
if len(toBeAppend.Clusters) != 1 {
return errors.New("only one cluster can be merged into original kubeconfig")
}

if len(kubectlConfig.Users) != 1 {
if len(toBeAppend.Users) != 1 {
return errors.New("only one user can be merged into original kubeconfig")
}

if len(kubectlConfig.Contexts) != 1 {
if len(toBeAppend.Contexts) != 1 {
return errors.New("only one context can be merged into original kubeconfig")
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func Merge(kubeConfig KubectlConfig, toBeAppend KubectlConfig, name, toBeAppendF
newName = name
}

var err = validate(toBeAppend, toBeAppendFileName)
var err = validate(toBeAppend, kubeConfig, toBeAppendFileName)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fd65612

Please sign in to comment.