Skip to content

Commit

Permalink
Always make sure the pull secret is in the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Oct 5, 2020
1 parent f8137b0 commit 47f6782
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 19 additions & 4 deletions pkg/crc/cluster/cluster.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/crc/pkg/crc/oc"
"github.com/code-ready/crc/pkg/crc/ssh"
"github.com/code-ready/crc/pkg/crc/validation"
"github.com/pborman/uuid"
)

Expand Down Expand Up @@ -87,7 +88,24 @@ func GetRootPartitionUsage(sshRunner *ssh.Runner) (int64, int64, error) {
return diskSize, diskUsage, nil
}

func AddPullSecretInTheCluster(ocConfig oc.Config, pullSec *PullSecret) error {
func EnsurePullSecretPresentInTheCluster(ocConfig oc.Config, pullSec *PullSecret) error {
if err := WaitForOpenshiftResource(ocConfig, "secret"); err != nil {
return err
}

stdout, _, err := ocConfig.RunOcCommandPrivate("get", "secret", "pull-secret", "-n", "openshift-config", "-o", `jsonpath="{['data']['\.dockerconfigjson']}"`)
if err != nil {
return err
}
decoded, err := base64.StdEncoding.DecodeString(stdout)
if err != nil {
return err
}
if err := validation.ImagePullSecret(string(decoded)); err == nil {
return nil
}

logging.Info("Adding user's pull secret to the cluster ...")
content, err := pullSec.Value()
if err != nil {
return err
Expand All @@ -97,9 +115,6 @@ func AddPullSecretInTheCluster(ocConfig oc.Config, pullSec *PullSecret) error {
fmt.Sprintf(`'{"data":{".dockerconfigjson":"%s"}}'`, base64OfPullSec),
"-n", "openshift-config", "--type", "merge"}

if err := WaitForOpenshiftResource(ocConfig, "secret"); err != nil {
return err
}
_, stderr, err := ocConfig.RunOcCommandPrivate(cmdArgs...)
if err != nil {
return fmt.Errorf("Failed to add Pull secret %v: %s", err, stderr)
Expand Down
7 changes: 3 additions & 4 deletions pkg/crc/machine/machine.go
Expand Up @@ -353,11 +353,10 @@ func (client *client) Start(startConfig StartConfig) (StartResult, error) {
if err := configProxyForCluster(ocConfig, sshRunner, sd, proxyConfig, instanceIP); err != nil {
return startError(startConfig.Name, "Error Setting cluster config", err)
}
}

logging.Info("Adding user's pull secret to the cluster ...")
if err := cluster.AddPullSecretInTheCluster(ocConfig, startConfig.PullSecret); err != nil {
return startError(startConfig.Name, "Failed to update user pull secret", err)
}
if err := cluster.EnsurePullSecretPresentInTheCluster(ocConfig, startConfig.PullSecret); err != nil {
return startError(startConfig.Name, "Failed to update cluster pull secret", err)
}

if err := cluster.EnsureClusterIDIsNotEmpty(ocConfig); err != nil {
Expand Down

0 comments on commit 47f6782

Please sign in to comment.