Skip to content

Commit

Permalink
fix:digitalocean k8s version upgrade (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokestax authored Aug 15, 2024
1 parent 0559e3b commit f9a076f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions internal/argocd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func GetArgoCDToken(username string, password string) (string, error) {
return "", err
}

req.Header.Set("Content-Type", "application/json")

res, err := httpClient.Do(req)
if err != nil {
return "", err
Expand Down
45 changes: 24 additions & 21 deletions internal/controller/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package controller
import (
"context"
"fmt"
"time"
"time"

argocdapi "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
awsext "github.com/kubefirst/kubefirst-api/extensions/aws"
Expand Down Expand Up @@ -46,7 +46,13 @@ func (clctrl *ClusterController) InstallArgoCD() error {
}
}

argoCDInstallPath := fmt.Sprintf("github.com:kubefirst/manifests/argocd/cloud?ref=%s", pkg.KubefirstManifestRepoRef)
var argoCDInstallPath string
if clctrl.CloudProvider == "digitalocean" {
argoCDInstallPath = "github.com:konstructio/manifests/argocd/cloud?ref=v1.1.0"
} else {
argoCDInstallPath = fmt.Sprintf("github.com:kubefirst/manifests/argocd/cloud?ref=%s", pkg.KubefirstManifestRepoRef)
}

log.Info().Msg("installing argocd")

telemetry.SendEvent(clctrl.TelemetryEvent, telemetry.ArgoCDInstallStarted, "")
Expand Down Expand Up @@ -129,9 +135,11 @@ func (clctrl *ClusterController) InitializeArgoCD() error {
8080,
argoCDStopChannel,
)

argoCDToken, err = argocd.GetArgoCDToken("admin", argocdPassword)

if err != nil {
return err
return fmt.Errorf("error getting argoCDToken : %w", err)
}
}

Expand All @@ -150,22 +158,21 @@ func (clctrl *ClusterController) InitializeArgoCD() error {
return nil
}

func RestartDeployment(ctx context.Context, clientset kubernetes.Interface, namespace string, deployment_name string) error {

func RestartDeployment(ctx context.Context,clientset kubernetes.Interface,namespace string,deployment_name string) error {
deploy, err := clientset.AppsV1().Deployments(namespace).Get(ctx, deployment_name, metav1.GetOptions{})

deploy,err := clientset.AppsV1().Deployments(namespace).Get(ctx,deployment_name,metav1.GetOptions{})

if err != nil {
return err
}

if deploy.Spec.Template.ObjectMeta.Annotations == nil {
deploy.Spec.Template.ObjectMeta.Annotations = make(map[string]string)
}
deploy.Spec.Template.ObjectMeta.Annotations = make(map[string]string)
}

deploy.Spec.Template.ObjectMeta.Annotations["kubectl.kubernetes.io/restartedAt"] = time.Now().Format(time.RFC3339)

_,err = clientset.AppsV1().Deployments(namespace).Update(ctx,deploy,metav1.UpdateOptions{})
_, err = clientset.AppsV1().Deployments(namespace).Update(ctx, deploy, metav1.UpdateOptions{})

if err != nil {
return fmt.Errorf("unable to update deployment %q: %w", deploy, err)
Expand All @@ -174,7 +181,6 @@ func RestartDeployment(ctx context.Context,clientset kubernetes.Interface,namesp
return nil
}


// DeployRegistryApplication
func (clctrl *ClusterController) DeployRegistryApplication() error {
cl, err := secrets.GetCluster(clctrl.KubernetesClient, clctrl.ClusterName)
Expand Down Expand Up @@ -203,7 +209,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
if err != nil {
return err
}

log.Info().Msg("applying the registry application to argocd")

registryURL, err := clctrl.GetRepoURL()
Expand All @@ -223,18 +229,16 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
registryPath,
)


if clctrl.Kcfg == nil{
clctrl.Kcfg = k8s.CreateKubeConfig(false,clctrl.ProviderConfig.Kubeconfig)
if clctrl.Kcfg == nil {
clctrl.Kcfg = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig)
}

err = RestartDeployment(context.Background(),clctrl.Kcfg.Clientset,"argocd","argocd-applicationset-controller")
if err!= nil {
err = RestartDeployment(context.Background(), clctrl.Kcfg.Clientset, "argocd", "argocd-applicationset-controller")

if err != nil {
return err
}


retryAttempts := 2
for attempt := 1; attempt <= retryAttempts; attempt++ {
log.Info().Msgf("Attempt #%d to create Argo CD application...\n", attempt)
Expand All @@ -246,14 +250,13 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
}
log.Info().Msgf("Error creating Argo CD application on attempt number #%d: %v\n", attempt, err)
time.Sleep(5 * time.Second)
continue
continue
}

log.Info().Msgf("Argo CD application created successfully on attempt #%d: %s\n", attempt, app.Name)
break
break
}


telemetry.SendEvent(clctrl.TelemetryEvent, telemetry.CreateRegistryCompleted, "")

clctrl.Cluster.ArgoCDCreateRegistryCheck = true
Expand Down

0 comments on commit f9a076f

Please sign in to comment.