Skip to content

Commit

Permalink
Merge pull request #12 from CAAPIM/repo_sync_update
Browse files Browse the repository at this point in the history
repository endpoints can now be updated
  • Loading branch information
Gazza7205 committed Sep 26, 2023
2 parents c2bc124 + 846898e commit cbb8b08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 15 additions & 2 deletions pkg/gateway/reconcile/l7repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -65,14 +65,27 @@ 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 {
params.Log.Info("failed to apply commit", "name", gateway.Name, "namespace", gateway.Namespace, "error", err.Error())
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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/gateway/reconcile/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions pkg/util/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cbb8b08

Please sign in to comment.