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

Enable kstatus checks #784

Merged
merged 1 commit into from
Jan 27, 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
4 changes: 2 additions & 2 deletions controllers/kustomization_force_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ stringData:
}, timeout, time.Second).Should(BeTrue())
logStatus(t, resultK)

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)

t.Run("emits validation error event", func(t *testing.T) {
events := getEvents(resultK.GetName(), map[string]string{"kustomize.toolkit.fluxcd.io/revision": revision})
Expand Down Expand Up @@ -166,7 +166,7 @@ stringData:
}, timeout, time.Second).Should(BeTrue())
logStatus(t, resultK)

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)

g.Expect(apimeta.IsStatusConditionTrue(resultK.Status.Conditions, kustomizev1.HealthyCondition)).To(BeTrue())
})
Expand Down
9 changes: 5 additions & 4 deletions controllers/kustomization_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ parameters:

g.Expect(resultK.Status.ObservedGeneration).To(BeIdenticalTo(resultK.Generation))

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)
})

t.Run("reports progressing status", func(t *testing.T) {
Expand Down Expand Up @@ -164,6 +164,7 @@ parameters:
g.Expect(conditions.GetMessage(resultK, c)).To(ContainSubstring(expectedMessage))
g.Expect(conditions.GetObservedGeneration(resultK, c)).To(BeIdenticalTo(resultK.Generation))
}
kstatusInProgressCheck.CheckErr(ctx, resultK)
})

t.Run("reports unhealthy status", func(t *testing.T) {
Expand All @@ -186,7 +187,7 @@ parameters:
g.Expect(resultK.Status.LastHandledReconcileAt).To(BeIdenticalTo(reconcileRequestAt))
g.Expect(resultK.Status.ObservedGeneration).To(BeIdenticalTo(resultK.Generation - 1))

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)
})

t.Run("emits unhealthy event", func(t *testing.T) {
Expand Down Expand Up @@ -222,7 +223,7 @@ parameters:

g.Expect(resultK.Status.ObservedGeneration).To(BeIdenticalTo(resultK.Generation))

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)
})

t.Run("emits recovery event", func(t *testing.T) {
Expand Down Expand Up @@ -252,7 +253,7 @@ parameters:

g.Expect(resultK.Status.LastAttemptedRevision).To(BeIdenticalTo(resultK.Status.LastAppliedRevision))

//kstatusCheck.CheckErr(ctx, resultK)
kstatusCheck.CheckErr(ctx, resultK)
})

t.Run("emits event for the new revision", func(t *testing.T) {
Expand Down
27 changes: 17 additions & 10 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"math/rand"
"os"
"path/filepath"
"sigs.k8s.io/yaml"
"testing"
"time"

Expand All @@ -38,6 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
controllerLog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/yaml"

"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/conditions"
Expand All @@ -63,15 +63,16 @@ const (
const vaultVersion = "1.2.2"

var (
reconciler *KustomizationReconciler
k8sClient client.Client
testEnv *testenv.Environment
testServer *testserver.ArtifactServer
testMetricsH controller.Metrics
ctx = ctrl.SetupSignalHandler()
kubeConfig []byte
kstatusCheck *kcheck.Checker
debugMode = os.Getenv("DEBUG_TEST") != ""
reconciler *KustomizationReconciler
k8sClient client.Client
testEnv *testenv.Environment
testServer *testserver.ArtifactServer
testMetricsH controller.Metrics
ctx = ctrl.SetupSignalHandler()
kubeConfig []byte
kstatusCheck *kcheck.Checker
kstatusInProgressCheck *kcheck.Checker
debugMode = os.Getenv("DEBUG_TEST") != ""
)

func runInContext(registerControllers func(*testenv.Environment), run func() error, crdPath string) error {
Expand Down Expand Up @@ -166,6 +167,12 @@ func TestMain(m *testing.M) {
&kcheck.Conditions{
NegativePolarity: []string{meta.StalledCondition, meta.ReconcilingCondition},
})
// Disable fetch for the in-progress kstatus checker so that it can be
// asked to evaluate snapshot of an object. This is needed to prevent
// the object status from changing right before the checker fetches it
// for inspection.
kstatusInProgressCheck = kcheck.NewInProgressChecker(testEnv.Client)
kstatusInProgressCheck.DisableFetch = true
reconciler = &KustomizationReconciler{
ControllerName: controllerName,
Client: testEnv,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/fluxcd/pkg/apis/meta v0.18.0
github.com/fluxcd/pkg/http/fetch v0.3.0
github.com/fluxcd/pkg/kustomize v0.12.0
github.com/fluxcd/pkg/runtime v0.24.0
github.com/fluxcd/pkg/runtime v0.26.0
github.com/fluxcd/pkg/ssa v0.22.0
github.com/fluxcd/pkg/tar v0.2.0
github.com/fluxcd/pkg/testserver v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ github.com/fluxcd/pkg/http/fetch v0.3.0 h1:/mLj0IzTx+GhR09etzMJsBoNQ0qeOx9cSdeUg
github.com/fluxcd/pkg/http/fetch v0.3.0/go.mod h1:dHTDYIeL0ZAQ9mHM6ZS4VProxho+Atm73MHJ55yj0Sg=
github.com/fluxcd/pkg/kustomize v0.12.0 h1:4MQdbP3M8NTIcr8TgNMxRCN+2xZoMWtCDDS3RiOT+8M=
github.com/fluxcd/pkg/kustomize v0.12.0/go.mod h1:awHID4OKe2/WAfTFg4u0fURXZPUkrIslSZNSPX9MEFQ=
github.com/fluxcd/pkg/runtime v0.24.0 h1:rQmm5Xq8K7f8xcPj1oNOInM1x4YwmgTucZJOP51Xmr4=
github.com/fluxcd/pkg/runtime v0.24.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
github.com/fluxcd/pkg/runtime v0.26.0 h1:j78f52xzpbR8xOvvemGwbGt4BLxpn9FOzim5tngOYvo=
github.com/fluxcd/pkg/runtime v0.26.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
github.com/fluxcd/pkg/ssa v0.22.0 h1:HvJTuiYLZMxCjin7bAqBgnc2RjSqEfYrMbV5yINoM64=
github.com/fluxcd/pkg/ssa v0.22.0/go.mod h1:QND0ZNOQ5EzFxoNKfjUxE9J46AbRK3WKF8YkURwbVg0=
github.com/fluxcd/pkg/tar v0.2.0 h1:HEUHgONQYsJGeZZ4x6h5nQU9Aox1I4T3bOp1faWTqf8=
Expand Down