Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address miscellaneous issues throughout code base #986

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions internal/controller/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (r *KustomizationReconciler) reconcile(
conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "Reconciliation in progress")
conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg)
if err := r.patch(ctx, obj, patcher); err != nil {
return fmt.Errorf("failed to update status, error: %w", err)
return fmt.Errorf("failed to update status: %w", err)
}

// Create a snapshot of the current inventory.
Expand Down Expand Up @@ -345,7 +345,7 @@ func (r *KustomizationReconciler) reconcile(
progressingMsg = fmt.Sprintf("Building manifests for revision %s with a timeout of %s", revision, obj.GetTimeout().String())
conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg)
if err := r.patch(ctx, obj, patcher); err != nil {
return fmt.Errorf("failed to update status, error: %w", err)
return fmt.Errorf("failed to update status: %w", err)
}

// Configure the Kubernetes client for impersonation.
Expand Down Expand Up @@ -405,7 +405,7 @@ func (r *KustomizationReconciler) reconcile(
progressingMsg = fmt.Sprintf("Detecting drift for revision %s with a timeout of %s", revision, obj.GetTimeout().String())
conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg)
if err := r.patch(ctx, obj, patcher); err != nil {
return fmt.Errorf("failed to update status, error: %w", err)
return fmt.Errorf("failed to update status: %w", err)
}

// Validate and apply resources in stages.
Expand Down Expand Up @@ -747,9 +747,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
if err != nil {
return false, nil, err
}
resultSet.Append(changeSet.Entries)

if changeSet != nil && len(changeSet.Entries) > 0 {
resultSet.Append(changeSet.Entries)

log.Info("server-side apply for cluster definitions completed", "output", changeSet.ToMap())
for _, change := range changeSet.Entries {
if HasChanged(change.Action) {
Expand All @@ -772,9 +773,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
if err != nil {
return false, nil, err
}
resultSet.Append(changeSet.Entries)

if changeSet != nil && len(changeSet.Entries) > 0 {
resultSet.Append(changeSet.Entries)

log.Info("server-side apply for cluster class types completed", "output", changeSet.ToMap())
for _, change := range changeSet.Entries {
if HasChanged(change.Action) {
Expand All @@ -798,9 +800,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
if err != nil {
return false, nil, fmt.Errorf("%w\n%s", err, changeSetLog.String())
}
resultSet.Append(changeSet.Entries)

if changeSet != nil && len(changeSet.Entries) > 0 {
resultSet.Append(changeSet.Entries)

log.Info("server-side apply completed", "output", changeSet.ToMap(), "revision", revision)
for _, change := range changeSet.Entries {
if HasChanged(change.Action) {
Expand Down Expand Up @@ -865,7 +868,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
conditions.MarkReconciling(obj, meta.ProgressingReason, message)
conditions.MarkUnknown(obj, kustomizev1.HealthyCondition, meta.ProgressingReason, message)
if err := r.patch(ctx, obj, patcher); err != nil {
return fmt.Errorf("unable to update the healthy status to progressing, error: %w", err)
return fmt.Errorf("unable to update the healthy status to progressing: %w", err)
}

// Check the health with a default timeout of 30sec shorter than the reconciliation interval.
Expand All @@ -876,7 +879,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
}); err != nil {
conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
conditions.MarkFalse(obj, kustomizev1.HealthyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
return fmt.Errorf("Health check failed after %s: %w", time.Since(checkStart).String(), err)
return fmt.Errorf("health check failed after %s: %w", time.Since(checkStart).String(), err)
}

// Emit recovery event if the previous health check failed.
Expand All @@ -887,7 +890,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,

conditions.MarkTrue(obj, kustomizev1.HealthyCondition, meta.SucceededReason, msg)
if err := r.patch(ctx, obj, patcher); err != nil {
return fmt.Errorf("unable to update the healthy status to progressing, error: %w", err)
return fmt.Errorf("unable to update the healthy status to progressing: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/kustomization_indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func (r *KustomizationReconciler) requestsForRevisionChangeOf(indexKey string) h
return nil
}
var dd []dependency.Dependent
for _, d := range list.Items {
for i, d := range list.Items {
// If the Kustomization is ready and the revision of the artifact equals
// to the last attempted revision, we should not make a request for this Kustomization
if conditions.IsReady(&d) && repo.GetArtifact().HasRevision(d.Status.LastAttemptedRevision) {
if conditions.IsReady(&list.Items[i]) && repo.GetArtifact().HasRevision(d.Status.LastAttemptedRevision) {
continue
}
dd = append(dd, d.DeepCopy())
Expand Down
1 change: 1 addition & 0 deletions internal/sops/keyservice/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func TestServer_EncryptDecrypt_HCVault_Fallback(t *testing.T) {
Ciphertext: []byte("some ciphertext"),
}
_, err = s.Decrypt(context.TODO(), decReq)
g.Expect(err).To(HaveOccurred())
g.Expect(fallback.decryptReqs).To(HaveLen(1))
g.Expect(fallback.decryptReqs).To(ContainElement(decReq))
g.Expect(fallback.encryptReqs).To(HaveLen(0))
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
Expand Down Expand Up @@ -183,7 +183,7 @@ func main() {
},
Controller: ctrlcfg.Controller{
MaxConcurrentReconciles: concurrent,
RecoverPanic: pointer.Bool(true),
RecoverPanic: ptr.To(true),
},
})
if err != nil {
Expand Down