Skip to content

Commit

Permalink
fix: k3d retry
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 committed Oct 23, 2024
1 parent 2b92a57 commit 02d7f3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
54 changes: 30 additions & 24 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,34 +1187,40 @@ func runK3d(cmd *cobra.Command, _ []string) error {
progressPrinter.AddTracker("wrapping-up", "Wrapping up", 2)
progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false)

if err := k3d.PostRunPrepareGitopsRepository(config.GitopsDir); err != nil {
return fmt.Errorf("error detokenizing post run: %w", err)
}
executionControl = viper.GetBool("kubefirst-checks.post-detokenize")
if !executionControl {

Check failure on line 1191 in cmd/k3d/create.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)

gitopsRepo, err := git.PlainOpen(config.GitopsDir)
if err != nil {
return fmt.Errorf("error opening repo at %q: %w", config.GitopsDir, err)
}
_, err = os.Stat(fmt.Sprintf("%s/terraform/%s/remote-backend.md", config.GitopsDir, config.GitProvider))
if err == nil {
err = os.Rename(fmt.Sprintf("%s/terraform/%s/remote-backend.md", config.GitopsDir, config.GitProvider), fmt.Sprintf("%s/terraform/%s/remote-backend.tf", config.GitopsDir, config.GitProvider))
if err := k3d.PostRunPrepareGitopsRepository(config.GitopsDir); err != nil {
return fmt.Errorf("error detokenizing post run: %w", err)
}

gitopsRepo, err := git.PlainOpen(config.GitopsDir)
if err != nil {
return fmt.Errorf("failed to rename remote-backend.md to remote-backend.tf: %w", err)
return fmt.Errorf("error opening repo at %q: %w", config.GitopsDir, err)
}
_, err = os.Stat(fmt.Sprintf("%s/terraform/%s/remote-backend.md", config.GitopsDir, config.GitProvider))
if err == nil {
err = os.Rename(fmt.Sprintf("%s/terraform/%s/remote-backend.md", config.GitopsDir, config.GitProvider), fmt.Sprintf("%s/terraform/%s/remote-backend.tf", config.GitopsDir, config.GitProvider))
if err != nil {
return fmt.Errorf("failed to rename remote-backend.md to remote-backend.tf: %w", err)
}
}
}
viper.Set("kubefirst-checks.post-detokenize", true)
viper.WriteConfig()

err = gitClient.Commit(gitopsRepo, "committing initial detokenized gitops-template repo content post run")
if err != nil {
return fmt.Errorf("failed to commit initial detokenized gitops-template repo content: %w", err)
}
err = gitopsRepo.Push(&git.PushOptions{
RemoteName: config.GitProvider,
Auth: httpAuth,
})
if err != nil {
return fmt.Errorf("failed to push initial detokenized gitops-template repo content: %w", err)
err = gitClient.Commit(gitopsRepo, "committing initial detokenized gitops-template repo content post run")
if err != nil {
return fmt.Errorf("failed to commit initial detokenized gitops-template repo content: %w", err)
}
err = gitopsRepo.Push(&git.PushOptions{
RemoteName: config.GitProvider,
Auth: httpAuth,
})
if err != nil {
return fmt.Errorf("failed to push initial detokenized gitops-template repo content: %w", err)
}
viper.Set("kubefirst-checks.post-detokenize", true)
viper.WriteConfig()
} else {
log.Info().Msg("already detokenized post run")
}

progressPrinter.IncrementTracker("wrapping-up")
Expand Down
13 changes: 11 additions & 2 deletions internal/gitShim/containerRegistryAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/konstructio/kubefirst-api/pkg/gitlab"
"github.com/konstructio/kubefirst-api/pkg/k8s"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -48,12 +49,20 @@ func CreateContainerRegistrySecret(obj *ContainerRegistryAuth) (string, error) {
usernamePasswordStringB64,
)

data := map[string][]byte{"config.json": []byte(dockerConfigString)}
argoDeployTokenSecret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: secretName, Namespace: "argo"},
Data: map[string][]byte{"config.json": []byte(dockerConfigString)},
Data: data,
Type: "Opaque",
}
if err := k8s.CreateSecretV2(obj.Clientset, argoDeployTokenSecret); err != nil {
err := k8s.CreateSecretV2(obj.Clientset, argoDeployTokenSecret)
if errors.IsAlreadyExists(err) {
if err := k8s.UpdateSecretV2(obj.Clientset, "argo", secretName, data); err != nil {
return "", fmt.Errorf("error while updating secret for GitHub container registry auth: %w", err)
}
}

if err != nil && !errors.IsAlreadyExists(err) {
return "", fmt.Errorf("error while creating secret for GitHub container registry auth: %w", err)
}

Expand Down

0 comments on commit 02d7f3e

Please sign in to comment.