Skip to content

Commit

Permalink
Merge pull request #359 from anupama2501/updaterkestatefile28
Browse files Browse the repository at this point in the history
[2.8]Update rke state file
  • Loading branch information
anupama2501 authored Dec 23, 2024
2 parents 1c68727 + 9867198 commit fe59e10
Show file tree
Hide file tree
Showing 3 changed files with 1,017 additions and 115 deletions.
22 changes: 10 additions & 12 deletions clients/rkecli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/rancher/shepherd/clients/rancher"
v3 "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
v1 "github.com/rancher/shepherd/clients/rancher/v1"
"github.com/rancher/shepherd/extensions/configmaps"
"github.com/rancher/shepherd/pkg/config"
"github.com/rancher/shepherd/pkg/file"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -129,7 +128,7 @@ func NewClusterFile(state *cluster.FullState, dirName string, config *Config) (c
rkeConfig.Nodes[i].SSHKeyPath = appendSSHPath(rkeConfig.Nodes[i].SSHKeyPath, config.SSHPath)
}
} else {
return "", errors.Wrap(err, "rke SSHPath or SSHKey not configured")
return "", errors.New("missing SSH configuration")
}

marshaled, err := yaml.Marshal(rkeConfig)
Expand Down Expand Up @@ -166,28 +165,27 @@ func NewStateFile(state *cluster.FullState, dirName string) (stateFilePath strin
return
}

// GetFullState is a function that gets RKE full state from "full-cluster-state" configmap.
// GetFullState is a function that gets RKE full state from "full-cluster-state" secret.
// And returns the cluster full state.
func GetFullState(client *rancher.Client) (state *cluster.FullState, err error) {
namespacedConfigmapClient := client.Steve.SteveType(configmaps.ConfigMapSteveType).NamespacedSteveClient(cluster.SystemNamespace)
if err != nil {
return
}
namespacedSecretClient := client.Steve.SteveType("secret").NamespacedSteveClient(cluster.SystemNamespace)

fullstateSecretID := fmt.Sprintf(cluster.SystemNamespace+"/%s", cluster.FullStateSecretName)

configmapResp, err := namespacedConfigmapClient.ByID(cluster.FullStateConfigMapName)
secretResp, err := namespacedSecretClient.ByID(fullstateSecretID)
if err != nil {
return
}

configmap := &corev1.ConfigMap{}
err = v1.ConvertToK8sType(configmapResp.JSONResp, configmap)
secret := &corev1.Secret{}
err = v1.ConvertToK8sType(secretResp.JSONResp, secret)
if err != nil {
return
}

rawState, ok := configmap.Data[cluster.FullStateConfigMapName]
rawState, ok := secret.Data[cluster.FullStateSecretName]
if !ok {
err = errors.Wrapf(err, "couldn't retrieve full state data in the configmap")
err = errors.Wrapf(err, "couldn't retrieve full state data in the secret")
return
}

Expand Down
46 changes: 23 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/rancher/shepherd
go 1.22

replace (
k8s.io/api => k8s.io/api v0.27.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.27.4
k8s.io/apimachinery => k8s.io/apimachinery v0.27.4
k8s.io/apiserver => k8s.io/apiserver v0.27.4
k8s.io/cli-runtime => k8s.io/cli-runtime v0.27.4
k8s.io/client-go => github.com/rancher/client-go v1.27.4-rancher1
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
k8s.io/api => k8s.io/api v0.28.6
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.28.6
k8s.io/apimachinery => k8s.io/apimachinery v0.28.6
k8s.io/apiserver => k8s.io/apiserver v0.28.6
k8s.io/cli-runtime => k8s.io/cli-runtime v0.28.6
k8s.io/client-go => github.com/rancher/client-go v1.28.6-rancher1
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9
)

require (
Expand All @@ -30,9 +30,9 @@ require (
github.com/rancher/fleet/pkg/apis v0.0.0-20231017140638-93432f288e79
github.com/rancher/gke-operator v1.2.1-rc1
github.com/rancher/lasso v0.0.0-20240123150939-7055397d6dfa
github.com/rancher/norman v0.0.0-20240205154641-a6a6cf569608
github.com/rancher/norman v0.0.0-20240206180703-6eda4bc94b4c
github.com/rancher/rancher/pkg/apis v0.0.0-20240213233515-935d309ebad4
github.com/rancher/rke v1.5.3
github.com/rancher/rke v1.5.15
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20210727200656-10b094e30007
github.com/rancher/types v0.0.0-20220328215343-4370ff10ecd5
github.com/rancher/wrangler v1.1.1
Expand All @@ -44,10 +44,10 @@ require (
k8s.io/api v0.28.6
k8s.io/apimachinery v0.28.6
k8s.io/apiserver v0.28.6
k8s.io/cli-runtime v0.27.6
k8s.io/cli-runtime v0.28.6
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-aggregator v0.28.6
k8s.io/kubectl v0.27.6
k8s.io/kubectl v0.28.6
k8s.io/utils v0.0.0-20230505201702-9f6742963106
sigs.k8s.io/cluster-api v1.5.0
sigs.k8s.io/yaml v1.4.0
Expand All @@ -59,7 +59,7 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.9.3 // indirect
github.com/Microsoft/hcsshim v0.9.10 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/apparentlymart/go-cidr v1.0.1 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
Expand All @@ -69,8 +69,8 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/containerd/containerd v1.5.18 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/containerd v1.6.27 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -84,7 +84,7 @@ require (
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-ini/ini v1.37.0 // indirect
Expand All @@ -96,7 +96,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand Down Expand Up @@ -128,8 +128,8 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/opencontainers/runc v1.1.12 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
Expand All @@ -144,7 +144,7 @@ require (
github.com/zclconf/go-cty v1.14.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.9 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
go.etcd.io/etcd/client/v2 v2.305.7 // indirect
go.etcd.io/etcd/client/v2 v2.305.9 // indirect
go.etcd.io/etcd/client/v3 v3.5.9 // indirect
go.opencensus.io v0.24.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
Expand Down Expand Up @@ -176,12 +176,12 @@ require (
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubernetes v1.27.6 // indirect
k8s.io/pod-security-admission v0.27.6 // indirect
k8s.io/kubernetes v1.28.6 // indirect
k8s.io/pod-security-admission v0.28.6 // indirect
sigs.k8s.io/cli-utils v0.28.0 // indirect
sigs.k8s.io/controller-runtime v0.15.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.4 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.2 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Loading

0 comments on commit fe59e10

Please sign in to comment.