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

[2.9]Update rke state file #358

Merged
merged 1 commit into from
Dec 17, 2024
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
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
Loading