diff --git a/cmd/cluster/etcd_health.go b/cmd/cluster/etcd_health.go index 1edf29a7..7ebce54f 100644 --- a/cmd/cluster/etcd_health.go +++ b/cmd/cluster/etcd_health.go @@ -51,13 +51,17 @@ func (capture *logCapture) Write(p []byte) (n int, err error) { return len(p), nil } -func getKubeConfigAndClient(clusterID string) (client.Client, *rest.Config, *kubernetes.Clientset, error) { +func getKubeConfigAndClient(clusterID string, user string, elevationReason string) (client.Client, *rest.Config, *kubernetes.Clientset, error) { bp, err := bpconfig.GetBackplaneConfiguration() if err != nil { return nil, nil, nil, fmt.Errorf("failed to load backplane-cli config: %v", err) } - - kubeconfig, err := bplogin.GetRestConfigAsUser(bp, clusterID, "backplane-cluster-admin") + var kubeconfig *rest.Config + if user == "" && elevationReason == "" { + kubeconfig, err = bplogin.GetRestConfig(bp, clusterID) + } else { + kubeconfig, err = bplogin.GetRestConfigAsUser(bp, clusterID, user, elevationReason) + } if err != nil { return nil, nil, nil, err } @@ -80,7 +84,6 @@ func newCmdEtcdHealthCheck() *cobra.Command { Long: `Checks etcd component health status for member replacement`, Args: cobra.ExactArgs(1), DisableAutoGenTag: true, - Deprecated: "please use the managed-script SREP/etcd-complete-health-check to avoid backplane elevation", Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(EtcdHealthCheck(args[0])) }, @@ -94,7 +97,7 @@ func EtcdHealthCheck(clusterId string) error { } }() - kubeCli, kconfig, clientset, err := getKubeConfigAndClient(clusterId) + kubeCli, kconfig, clientset, err := getKubeConfigAndClient(clusterId, "", "") if err != nil { return err } diff --git a/cmd/cluster/etcd_replace.go b/cmd/cluster/etcd_replace.go index 9d5e602b..98abc428 100644 --- a/cmd/cluster/etcd_replace.go +++ b/cmd/cluster/etcd_replace.go @@ -53,7 +53,7 @@ func newCmdEtcdMemberReplacement() *cobra.Command { } func (opts *etcdOptions) EtcdReplaceMember(clusterId string) error { - kubeCli, kconfig, clientset, err := getKubeConfigAndClient(clusterId) + kubeCli, kconfig, clientset, err := getKubeConfigAndClient(clusterId, "backplane-cluster-admin", "Replacing unhealthy etcd member using osdctl") if err != nil { return err } diff --git a/cmd/cluster/transferowner.go b/cmd/cluster/transferowner.go index a15064b2..8a708a18 100644 --- a/cmd/cluster/transferowner.go +++ b/cmd/cluster/transferowner.go @@ -5,6 +5,10 @@ import ( "context" "encoding/json" "fmt" + "os" + "strings" + "time" + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" hiveapiv1 "github.com/openshift/hive/apis/hive/v1" hiveinternalv1alpha1 "github.com/openshift/hive/apis/hiveinternal/v1alpha1" @@ -12,10 +16,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "os" "sigs.k8s.io/controller-runtime/pkg/client" - "strings" - "time" "github.com/openshift-online/ocm-cli/pkg/arguments" sdk "github.com/openshift-online/ocm-sdk-go" @@ -302,7 +303,7 @@ func (o *transferOwnerOptions) run() error { // Find and setup all resources that are needed hiveCluster, err := utils.GetHiveCluster(o.clusterID) - hiveKubeCli, _, hivecClientset, err := getKubeConfigAndClient(hiveCluster.ID()) + hiveKubeCli, _, hivecClientset, err := getKubeConfigAndClient(hiveCluster.ID(), "backplane-cluster-admin", "Updating pull secret using osdctl") if err != nil { return fmt.Errorf("failed to retrieve Kubernetes configuration and client for Hive cluster ID %s: %w", hiveCluster.ID(), err) } @@ -353,7 +354,7 @@ func (o *transferOwnerOptions) run() error { return fmt.Errorf("failed to update pull secret for Hive cluster with ID %s: %w", o.clusterID, err) } - _, _, clientset, err := getKubeConfigAndClient(o.clusterID) + _, _, clientset, err := getKubeConfigAndClient(o.clusterID, "backplane-cluster-admin", "Updating pull secret using osdctl") if err != nil { return fmt.Errorf("failed to retrieve Kubernetes configuration and client for cluster with ID %s: %w", o.clusterID, err) }