Skip to content

Commit

Permalink
Merge pull request #501 from devppratik/revert-etcd-health-check
Browse files Browse the repository at this point in the history
OSD-20407: Fix osdctl cluster etcd related commands
  • Loading branch information
openshift-merge-bot[bot] authored Jan 19, 2024
2 parents 4e50dd9 + 83153e0 commit 53837b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions cmd/cluster/etcd_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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]))
},
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster/etcd_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/cluster/transferowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ 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"
"github.com/openshift/osdctl/cmd/servicelog"
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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 53837b8

Please sign in to comment.