From 846898edef63082c847304f7749973f1e92a6400 Mon Sep 17 00:00:00 2001 From: Gazza7205 Date: Tue, 26 Sep 2023 01:25:40 +0100 Subject: [PATCH] repository endpoints can now be updated --- Makefile | 2 +- pkg/gateway/reconcile/l7repositories.go | 17 +++++++++++++++-- pkg/gateway/reconcile/status.go | 3 ++- pkg/util/git.go | 20 ++++++++++++++++---- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 77a26902..6cf5ca7f 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,7 @@ build: generate fmt vet ## Build manager binary. .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go + go run ./main.go --zap-log-level=10 .PHONY: docker-build docker-build: #test ## Build docker image with the manager. diff --git a/pkg/gateway/reconcile/l7repositories.go b/pkg/gateway/reconcile/l7repositories.go index 71c0e76a..bbf83e77 100644 --- a/pkg/gateway/reconcile/l7repositories.go +++ b/pkg/gateway/reconcile/l7repositories.go @@ -24,7 +24,7 @@ func syncRepository(ctx context.Context, params Params) { cntr := 0 for _, repoRef := range gateway.Spec.App.RepositoryReferences { - if repoRef.Enabled && repoRef.Type == "dynamic" { + if repoRef.Enabled { cntr++ } } @@ -34,7 +34,7 @@ func syncRepository(ctx context.Context, params Params) { } for _, repoRef := range gateway.Spec.App.RepositoryReferences { - if repoRef.Enabled && repoRef.Type == "dynamic" { + if repoRef.Enabled { err := reconcileDynamicRepository(ctx, params, gateway, repoRef) if err != nil { params.Log.Error(err, "failed to reconcile repository reference", "name", gateway.Name, "repository", repoRef.Name, "namespace", gateway.Namespace) @@ -65,6 +65,7 @@ func reconcileDynamicRepository(ctx context.Context, params Params, gateway *sec if err != nil { params.Log.Info("failed to apply commit", "name", gateway.Name, "namespace", gateway.Namespace, "error", err.Error()) } + } else { err = applyDbBacked(ctx, params, gateway, repository, repoRef, commit) if err != nil { @@ -72,7 +73,19 @@ func reconcileDynamicRepository(ctx context.Context, params Params, gateway *sec return err } } + //case "static": + } + + for _, sRepo := range gateway.Status.RepositoryStatus { + if sRepo.Name == repoRef.Name { + if sRepo.Commit != commit { + params.Instance = gateway + _ = GatewayStatus(ctx, params) + } + } + } + return nil } diff --git a/pkg/gateway/reconcile/status.go b/pkg/gateway/reconcile/status.go index bec29693..6af58a13 100644 --- a/pkg/gateway/reconcile/status.go +++ b/pkg/gateway/reconcile/status.go @@ -95,7 +95,8 @@ func GatewayStatus(ctx context.Context, params Params) error { params.Instance.Status = gatewayStatus err = params.Client.Status().Update(ctx, params.Instance) if err != nil { - params.Log.Info("failed to update gateway status", "name", params.Instance.Name, "namespace", params.Instance.Namespace, "message", err.Error()) + params.Log.V(2).Info("failed to update gateway status", "name", params.Instance.Name, "namespace", params.Instance.Namespace, "message", err.Error()) + return err } } return nil diff --git a/pkg/util/git.go b/pkg/util/git.go index 58228af1..f0d8e01a 100644 --- a/pkg/util/git.go +++ b/pkg/util/git.go @@ -65,10 +65,22 @@ func CloneRepository(url string, username string, token string, branch string, t return commit.Hash.String(), nil } - _ = w.Pull(&pullOpts) - // if err != nil { - // return "", err - // } + gbytes, _ := os.ReadFile("/tmp/" + name + "-" + ext + "/.git/config") + if !strings.Contains(string(gbytes), cloneOpts.URL) { + err = os.RemoveAll("/tmp/" + name + "-" + ext) + if err != nil { + return "", err + } + return "", errors.New("repository endpoint updated, flushing temp storage") + } + + err = w.Pull(&pullOpts) + if err != nil { + if err == git.NoErrAlreadyUpToDate { + return commit.Hash.String(), nil + } + return "", err + } return commit.Hash.String(), nil }