Skip to content

Commit

Permalink
Merge pull request #11 from CAAPIM/cron_update
Browse files Browse the repository at this point in the history
fixed deregister of jobs for background sync tasks
  • Loading branch information
Gazza7205 committed Sep 23, 2023
2 parents 1f2e465 + 75cc5e6 commit c2bc124
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ deploy.sh
.dockerconfigjson
dev
license.xml
.DS_Store
2 changes: 1 addition & 1 deletion pkg/gateway/reconcile/externalkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func syncExternalKeys(ctx context.Context, params Params) {
}
}
if cntr == 0 {
_ = s.RemoveByTag("sync-external-keys")
_ = s.RemoveByTag(params.Instance.Name + "-sync-external-keys")
}

err := reconcileExternalKeys(ctx, params)
Expand Down
4 changes: 3 additions & 1 deletion pkg/gateway/reconcile/externalsecrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func syncExternalSecrets(ctx context.Context, params Params) error {
err := params.Client.Get(ctx, types.NamespacedName{Name: params.Instance.Name, Namespace: params.Instance.Namespace}, gateway)
if err != nil && k8serrors.IsNotFound(err) {
params.Log.Error(err, "gateway not found", "Name", params.Instance.Name, "namespace", params.Instance.Namespace)
_ = s.RemoveByTag(params.Instance.Name + "-sync-external-secrets")
return nil
}

cntr := 0
Expand All @@ -33,7 +35,7 @@ func syncExternalSecrets(ctx context.Context, params Params) error {
}
}
if cntr == 0 {
_ = s.RemoveByTag("sync-external-secrets")
_ = s.RemoveByTag(params.Instance.Name + "-sync-external-secrets")
return nil
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/gateway/reconcile/l7repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func syncRepository(ctx context.Context, params Params) {
err := params.Client.Get(ctx, types.NamespacedName{Name: params.Instance.Name, Namespace: params.Instance.Namespace}, gateway)
if err != nil && k8serrors.IsNotFound(err) {
params.Log.Error(err, "gateway not found", "name", params.Instance.Name, "namespace", params.Instance.Namespace)
_ = removeJob(params.Instance.Name + "-sync-repository-references")
return
}

cntr := 0
Expand All @@ -28,11 +30,7 @@ func syncRepository(ctx context.Context, params Params) {
}
if cntr == 0 {
_ = removeJob(params.Instance.Name + "-sync-repository-references")
}

err = params.Client.Get(ctx, types.NamespacedName{Name: params.Instance.Name, Namespace: params.Instance.Namespace}, gateway)
if err != nil && k8serrors.IsNotFound(err) {
params.Log.Error(err, "gateway not found", "name", params.Instance.Name, "namespace", params.Instance.Namespace)
return
}

for _, repoRef := range gateway.Spec.App.RepositoryReferences {
Expand Down
3 changes: 3 additions & 0 deletions pkg/gateway/reconcile/pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
)

func PodDisruptionBudget(ctx context.Context, params Params) error {
if !params.Instance.Spec.App.PodDisruptionBudget.Enabled {
return nil
}
desiredPdb := gateway.NewPDB(params.Instance)
currentPdb := &policyv1.PodDisruptionBudget{}

Expand Down
6 changes: 3 additions & 3 deletions pkg/repository/reconcile/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func syncRepository(ctx context.Context, params Params) error {
repository, err := getRepository(ctx, params)
if err != nil {
params.Log.Info("repository unavailable", "name", params.Instance.Name, "namespace", params.Instance.Namespace, "error", err.Error())
_ = s.RemoveByTag(params.Instance.Name + "-sync-repository")
return nil
}

Expand All @@ -30,7 +31,7 @@ func syncRepository(ctx context.Context, params Params) error {

repoStatus := repository.Status
if !repository.Spec.Enabled {
params.Log.Info("repository not enabled", "name", repository.Name, "namespace", repository.Namespace)
params.Log.V(2).Info("repository not enabled", "name", repository.Name, "namespace", repository.Namespace)
return nil
}

Expand All @@ -57,7 +58,6 @@ func syncRepository(ctx context.Context, params Params) error {

if err != nil {
params.Log.V(2).Info("repository error", "name", repository.Name, "namespace", repository.Namespace, "error", err.Error())
//return err
return nil
}

Expand All @@ -77,7 +77,7 @@ func syncRepository(ctx context.Context, params Params) error {
repoStatus.StorageSecretName = storageSecretName

if !reflect.DeepEqual(repoStatus, repository.Status) {
params.Log.Info("syncing repository", "name", repository.Name, "namespace", repository.Namespace)
params.Log.V(2).Info("syncing repository", "name", repository.Name, "namespace", repository.Namespace)

repoStatus.Updated = time.Now().String()
repository.Status = repoStatus
Expand Down

0 comments on commit c2bc124

Please sign in to comment.