Skip to content

Commit

Permalink
fix : timeout issue for argocd and vault for public clouds (#363)
Browse files Browse the repository at this point in the history
* fix : timeout issue for argocd and vault

* Update Dockerfile

* Update argocd.go
  • Loading branch information
jokestax authored Jul 15, 2024
1 parent 1658dd1 commit ceed503
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
34 changes: 19 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

# Download go dependencies
COPY go.mod .
COPY go.sum .

RUN go mod download

# Copy into the container
COPY . .

# Build the application
RUN go build -o kubefirst-api .

# Build final image using nothing but the binary
FROM alpine:3.18.2

COPY --from=builder /build/kubefirst-api /
COPY --from=builder /build/docs /docs

RUN apk update && \
apk add git openssh aws-cli
apk add --no-cache \
git \
openssh \
aws-cli \
curl

RUN mkdir -p /root/.ssh
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN ssh-keyscan gitlab.com >> /root/.ssh/known_hosts
RUN mkdir -p /root/.ssh \
&& ssh-keyscan github.com >> /root/.ssh/known_hosts \
&& ssh-keyscan gitlab.com >> /root/.ssh/known_hosts

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl

COPY --from=builder /build/kubefirst-api /
COPY --from=builder /build/docs /docs

EXPOSE 8081

# Command to run
ENTRYPOINT ["/kubefirst-api"]
35 changes: 33 additions & 2 deletions internal/controller/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package controller
import (
"context"
"fmt"
"os/exec"
"time"

argocdapi "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
awsext "github.com/kubefirst/kubefirst-api/extensions/aws"
Expand Down Expand Up @@ -176,7 +178,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 @@ -196,7 +198,36 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
registryPath,
)

_, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{})

cmdStr := fmt.Sprintf("kubectl --kubeconfig=%s rollout restart -n argocd deploy/argocd-applicationset-controller", clctrl.ProviderConfig.Kubeconfig)

cmd := exec.Command("/bin/sh", "-c", cmdStr)

err = cmd.Run()
if err != nil {
fmt.Printf("Error executing kubectl command: %v\n", err)
return err
}


retryAttempts := 2
for attempt := 1; attempt <= retryAttempts; attempt++ {
log.Info().Msgf("Attempt #%d to create Argo CD application...\n", attempt)

app, err := argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{})
if err != nil {
if attempt == retryAttempts {
return err
}
log.Info().Msgf("Error creating Argo CD application on attempt number #%d: %v\n", attempt, err)
time.Sleep(5 * time.Second)
continue
}

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


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

Expand Down

0 comments on commit ceed503

Please sign in to comment.