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

Ask for confirmation before disabling OpenShift CVO #226

Merged
merged 1 commit into from
Mar 4, 2020
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
35 changes: 35 additions & 0 deletions pkg/subctl/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/spf13/cobra"
"github.com/submariner-io/submariner-operator/pkg/discovery/globalnet"

k8serrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"

submariner "github.com/submariner-io/submariner-operator/pkg/apis/submariner/v1alpha1"
Expand Down Expand Up @@ -115,6 +117,23 @@ func joinSubmarinerCluster(config *rest.Config, subctlData *datafile.SubctlData)
// Missing information
var qs = []*survey.Question{}

if subctlData.ServiceDiscovery {
cvoEnabled, err := isOpenShiftCVOEnabled(config)
exitOnError("Unable to check for the OpenShift CVO", err)
if cvoEnabled {
// Out of sequence question so we can abort early
disable := false
err = survey.AskOne(&survey.Confirm{
Message: "Enabling service discovery on OpenShift will disable OpenShift updates, do you want to continue?",
}, &disable)
// Most likely a programming error
panicOnError(err)
if !disable {
return
}
}
}

if valid, _ := isValidClusterID(clusterID); !valid {
qs = append(qs, &survey.Question{
Name: "clusterID",
Expand Down Expand Up @@ -327,6 +346,22 @@ func isValidClusterID(clusterID string) (bool, error) {
return true, nil
}

func isOpenShiftCVOEnabled(config *rest.Config) (bool, error) {
_, clientSet, err := getClients(config)
if err != nil {
return false, err
}
deployments := clientSet.AppsV1().Deployments("openshift-cluster-version")
scale, err := deployments.GetScale("cluster-version-operator", metav1.GetOptions{})
if err != nil {
if k8serrs.IsNotFound(err) {
return false, nil
}
return false, err
}
return scale.Spec.Replicas > 0, nil
}

func populateSubmarinerSpec(subctlData *datafile.SubctlData) submariner.SubmarinerSpec {
brokerURL := subctlData.BrokerURL
if idx := strings.Index(brokerURL, "://"); idx >= 0 {
Expand Down