Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWX-32573: Creating namespaces as part of clusterpair creation if the input namespace does not exist. #1467

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkg/storkctl/clusterpair.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
storkops "github.com/portworx/sched-ops/k8s/stork"
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/validation"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
Expand Down Expand Up @@ -321,6 +322,13 @@

storkops.Instance().SetConfig(conf)
core.Instance().SetConfig(conf)
if len(cmdFactory.GetNamespace()) > 0 {
err = createNamespace(sFile, cmdFactory.GetNamespace())
if err != nil {
util.CheckErr(err)
return

Check warning on line 329 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L325-L329

Added lines #L325 - L329 were not covered by tests
}
}
_, err = storkops.Instance().CreateClusterPair(srcClusterPair)
if err != nil {
util.CheckErr(err)
Expand All @@ -345,6 +353,13 @@
storkops.Instance().SetConfig(conf)
core.Instance().SetConfig(conf)

if len(cmdFactory.GetNamespace()) > 0 {
err = createNamespace(dFile, cmdFactory.GetNamespace())
if err != nil {
util.CheckErr(err)
return

Check warning on line 360 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L356-L360

Added lines #L356 - L360 were not covered by tests
}
}
_, err = storkops.Instance().CreateClusterPair(destClusterPair)
if err != nil {
util.CheckErr(err)
Expand Down Expand Up @@ -488,6 +503,13 @@
return
}

if len(cmdFactory.GetNamespace()) > 0 {
err = createNamespace(sFile, cmdFactory.GetNamespace())
if err != nil {
util.CheckErr(err)
return

Check warning on line 510 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L506-L510

Added lines #L506 - L510 were not covered by tests
}
}
printMsg(fmt.Sprintf("\nCreating Secret and ObjectstoreLocation in source cluster in namespace %v...", cmdFactory.GetNamespace()), ioStreams.Out)
storkops.Instance().SetConfig(conf)
core.Instance().SetConfig(conf)
Expand Down Expand Up @@ -565,6 +587,13 @@
storkops.Instance().SetConfig(conf)
core.Instance().SetConfig(conf)

if len(cmdFactory.GetNamespace()) > 0 {
err = createNamespace(dFile, cmdFactory.GetNamespace())
if err != nil {
util.CheckErr(err)
return

Check warning on line 594 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L590-L594

Added lines #L590 - L594 were not covered by tests
}
}
printMsg(fmt.Sprintf("Creating Secret and ObjectstoreLocation in destination cluster in namespace %v...", cmdFactory.GetNamespace()), ioStreams.Out)
_, err = core.Instance().CreateSecret(secret)
if err != nil {
Expand Down Expand Up @@ -887,3 +916,23 @@
func getMissingParameterError(param string, desc string) error {
return fmt.Errorf("missing parameter %q - %s", param, desc)
}

func createNamespace(config string, namespace string) error {
conf, err := getConfig(config).ClientConfig()
if err != nil {
return err

Check warning on line 923 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L920-L923

Added lines #L920 - L923 were not covered by tests
}
coreOps, err := core.NewForConfig(conf)
if err != nil {
return err

Check warning on line 927 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L925-L927

Added lines #L925 - L927 were not covered by tests
}
_, err = coreOps.CreateNamespace(&v1.Namespace{
ObjectMeta: meta.ObjectMeta{
Name: namespace,
},
})
if err != nil && !k8serrors.IsAlreadyExists(err) {
return err

Check warning on line 935 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L929-L935

Added lines #L929 - L935 were not covered by tests
}
return nil

Check warning on line 937 in pkg/storkctl/clusterpair.go

View check run for this annotation

Codecov / codecov/patch

pkg/storkctl/clusterpair.go#L937

Added line #L937 was not covered by tests
}