-
Notifications
You must be signed in to change notification settings - Fork 73
✨ Default Probes Refactor #2586
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ import ( | |
|
|
||
| "helm.sh/helm/v3/pkg/release" | ||
| "helm.sh/helm/v3/pkg/storage/driver" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
@@ -208,10 +211,12 @@ func (r *SimpleRevisionGenerator) buildClusterExtensionRevision( | |
| annotations[labels.ServiceAccountNamespaceKey] = ext.Spec.Namespace | ||
|
|
||
| phases := PhaseSort(objects) | ||
| progressionProbes := defaultProgressionProbes() | ||
|
|
||
| spec := ocv1ac.ClusterExtensionRevisionSpec(). | ||
| WithLifecycleState(ocv1.ClusterExtensionRevisionLifecycleStateActive). | ||
| WithPhases(phases...) | ||
| WithPhases(phases...). | ||
| WithProgressionProbes(progressionProbes...) | ||
| if p := ext.Spec.ProgressDeadlineMinutes; p > 0 { | ||
| spec.WithProgressDeadlineMinutes(p) | ||
| } | ||
|
|
@@ -602,6 +607,110 @@ func latestRevisionNumber(prevRevisions []ocv1.ClusterExtensionRevision) int64 { | |
| return prevRevisions[len(prevRevisions)-1].Spec.Revision | ||
| } | ||
|
|
||
| func defaultProgressionProbes() []*ocv1ac.ProgressionProbeApplyConfiguration { | ||
| crdProbe := ocv1ac.ProgressionProbe(). | ||
| WithSelector(ocv1ac.ObjectSelector(). | ||
| WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: "apiextensions.k8s.io", | ||
| Kind: "CustomResourceDefinition", | ||
| })). | ||
| WithAssertions(ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeConditionEqual). | ||
| WithConditionEqual( | ||
| ocv1ac.ConditionEqualProbe(). | ||
| WithType(string(apiextensions.Established)). | ||
| WithStatus(string(corev1.ConditionTrue)))) | ||
|
|
||
| // Checks if the Type: "Ready" Condition is "True" | ||
| readyConditionAssertion := ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeConditionEqual). | ||
| WithConditionEqual( | ||
| ocv1ac.ConditionEqualProbe(). | ||
| WithType("Ready"). | ||
| WithStatus("True")) | ||
|
|
||
| certProbe := ocv1ac.ProgressionProbe(). | ||
| WithSelector(ocv1ac.ObjectSelector(). | ||
| WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: "acme.cert-manager.io", | ||
| Kind: "Certificate", | ||
| })). | ||
|
Comment on lines
+636
to
+639
|
||
| WithAssertions(readyConditionAssertion) | ||
| issuerProbe := ocv1ac.ProgressionProbe(). | ||
| WithSelector(ocv1ac.ObjectSelector(). | ||
| WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: "acme.cert-manager.io", | ||
| Kind: "Issuer", | ||
| })). | ||
|
Comment on lines
+644
to
+647
|
||
| WithAssertions(readyConditionAssertion) | ||
|
|
||
| // namespaceActiveProbe is a probe which asserts that the namespace is in "Active" phase | ||
| namespaceActiveProbe := ocv1ac.ProgressionProbe(). | ||
| WithSelector(ocv1ac.ObjectSelector(). | ||
| WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: corev1.GroupName, | ||
| Kind: "Namespace", | ||
| })). | ||
| WithAssertions(ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeFieldValue). | ||
| WithFieldValue(ocv1ac.FieldValueProbe(). | ||
| WithFieldPath("status.phase"). | ||
| WithValue(string(corev1.NamespaceActive)))) | ||
|
|
||
| // pvcBoundProbe is a probe which asserts that the PVC is in "Bound" phase | ||
| pvcBoundProbe := ocv1ac.ProgressionProbe(). | ||
| WithSelector(ocv1ac.ObjectSelector(). | ||
| WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: corev1.GroupName, | ||
| Kind: "PersistentVolumeClaim", | ||
| })). | ||
| WithAssertions(ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeFieldValue). | ||
| WithFieldValue(ocv1ac.FieldValueProbe(). | ||
| WithFieldPath("status.phase"). | ||
| WithValue(string(corev1.ClaimBound)))) | ||
|
|
||
| // Checks if the Type: "Available" Condition is "True". | ||
| availableConditionAssertion := ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeConditionEqual). | ||
| WithConditionEqual(ocv1ac.ConditionEqualProbe(). | ||
| WithType(string(appsv1.DeploymentAvailable)). | ||
| WithStatus(string(corev1.ConditionTrue))) | ||
|
|
||
| // Checks if status.updatedReplicas == status.replicas. | ||
| // Works for StatefulSets, Deployments and ReplicaSets. | ||
| replicasUpdatedAssertion := ocv1ac.Assertion(). | ||
| WithType(ocv1.ProbeTypeFieldsEqual). | ||
| WithFieldsEqual(ocv1ac.FieldsEqualProbe(). | ||
| WithFieldA("status.updatedReplicas"). | ||
| WithFieldB("status.replicas")) | ||
|
|
||
| statefulSetProbe := ocv1ac.ProgressionProbe().WithSelector( | ||
| ocv1ac.ObjectSelector().WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: appsv1.GroupName, | ||
| Kind: "StatefulSet", | ||
| }), | ||
| ).WithAssertions(replicasUpdatedAssertion, availableConditionAssertion) | ||
|
|
||
| deploymentProbe := ocv1ac.ProgressionProbe().WithSelector( | ||
| ocv1ac.ObjectSelector().WithType(ocv1.SelectorTypeGroupKind). | ||
| WithGroupKind(metav1.GroupKind{ | ||
| Group: appsv1.GroupName, | ||
| Kind: "Deployment", | ||
| }), | ||
| ).WithAssertions(replicasUpdatedAssertion, availableConditionAssertion) | ||
|
|
||
| return []*ocv1ac.ProgressionProbeApplyConfiguration{ | ||
| deploymentProbe, statefulSetProbe, pvcBoundProbe, namespaceActiveProbe, issuerProbe, certProbe, crdProbe, | ||
| } | ||
| } | ||
|
|
||
| func splitManifestDocuments(file string) []string { | ||
| // Estimate: typical manifests have ~50-100 lines per document | ||
| // Pre-allocate for reasonable bundle size to reduce allocations | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |||||
| appsv1 "k8s.io/api/apps/v1" | ||||||
| corev1 "k8s.io/api/core/v1" | ||||||
| rbacv1 "k8s.io/api/rbac/v1" | ||||||
| "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | ||||||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||||||
| apimeta "k8s.io/apimachinery/pkg/api/meta" | ||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
|
|
@@ -143,7 +144,105 @@ func Test_SimpleRevisionGenerator_GenerateRevisionFromHelmRelease(t *testing.T) | |||||
| }, | ||||||
| }, | ||||||
| }), | ||||||
| ), | ||||||
| )). | ||||||
| WithProgressionProbes( | ||||||
| ocv1ac.ProgressionProbe().WithSelector( | ||||||
| ocv1ac.ObjectSelector().WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: appsv1.GroupName, | ||||||
| Kind: "Deployment", | ||||||
| })). | ||||||
| WithAssertions( | ||||||
| ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeFieldsEqual). | ||||||
| WithFieldsEqual(ocv1ac.FieldsEqualProbe(). | ||||||
| WithFieldA("status.updatedReplicas"). | ||||||
| WithFieldB("status.replicas")), | ||||||
| ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeConditionEqual). | ||||||
| WithConditionEqual(ocv1ac.ConditionEqualProbe(). | ||||||
| WithType(string(appsv1.DeploymentAvailable)). | ||||||
| WithStatus(string(corev1.ConditionTrue)))), | ||||||
| ocv1ac.ProgressionProbe().WithSelector( | ||||||
| ocv1ac.ObjectSelector().WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: appsv1.GroupName, | ||||||
| Kind: "StatefulSet", | ||||||
| })). | ||||||
| WithAssertions( | ||||||
| ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeFieldsEqual). | ||||||
| WithFieldsEqual(ocv1ac.FieldsEqualProbe(). | ||||||
| WithFieldA("status.updatedReplicas"). | ||||||
| WithFieldB("status.replicas")), | ||||||
| ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeConditionEqual). | ||||||
| WithConditionEqual(ocv1ac.ConditionEqualProbe(). | ||||||
| WithType(string(appsv1.DeploymentAvailable)). | ||||||
| WithStatus(string(corev1.ConditionTrue)))), | ||||||
| ocv1ac.ProgressionProbe(). | ||||||
| WithSelector(ocv1ac.ObjectSelector(). | ||||||
| WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: corev1.GroupName, | ||||||
| Kind: "PersistentVolumeClaim", | ||||||
| })). | ||||||
| WithAssertions(ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeFieldValue). | ||||||
| WithFieldValue(ocv1ac.FieldValueProbe(). | ||||||
| WithFieldPath("status.phase"). | ||||||
| WithValue(string(corev1.ClaimBound)))), | ||||||
| ocv1ac.ProgressionProbe(). | ||||||
| WithSelector(ocv1ac.ObjectSelector(). | ||||||
| WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: corev1.GroupName, | ||||||
| Kind: "Namespace", | ||||||
| })). | ||||||
| WithAssertions(ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeFieldValue). | ||||||
| WithFieldValue(ocv1ac.FieldValueProbe(). | ||||||
| WithFieldPath("status.phase"). | ||||||
| WithValue(string(corev1.NamespaceActive)))), | ||||||
| ocv1ac.ProgressionProbe(). | ||||||
| WithSelector(ocv1ac.ObjectSelector(). | ||||||
| WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: "acme.cert-manager.io", | ||||||
| Kind: "Issuer", | ||||||
| })). | ||||||
|
Comment on lines
+210
to
+213
|
||||||
| WithAssertions(ocv1ac.Assertion(). | ||||||
| WithType(ocv1.ProbeTypeConditionEqual). | ||||||
| WithConditionEqual( | ||||||
| ocv1ac.ConditionEqualProbe(). | ||||||
| WithType("Ready"). | ||||||
| WithStatus("True"))), | ||||||
| ocv1ac.ProgressionProbe(). | ||||||
| WithSelector(ocv1ac.ObjectSelector(). | ||||||
| WithType(ocv1.SelectorTypeGroupKind). | ||||||
| WithGroupKind(metav1.GroupKind{ | ||||||
| Group: "acme.cert-manager.io", | ||||||
|
||||||
| Group: "acme.cert-manager.io", | |
| Group: "cert-manager.io", |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,9 +10,6 @@ import ( | |||||||||
| "strings" | ||||||||||
| "time" | ||||||||||
|
|
||||||||||
| appsv1 "k8s.io/api/apps/v1" | ||||||||||
| corev1 "k8s.io/api/core/v1" | ||||||||||
| "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | ||||||||||
| "k8s.io/apimachinery/pkg/api/equality" | ||||||||||
| "k8s.io/apimachinery/pkg/api/meta" | ||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||
|
|
@@ -479,9 +476,7 @@ func (c *ClusterExtensionRevisionReconciler) buildBoxcutterPhases(ctx context.Co | |||||||||
|
|
||||||||||
| opts := []boxcutter.RevisionReconcileOption{ | ||||||||||
| boxcutter.WithPreviousOwners(previousObjs), | ||||||||||
| boxcutter.WithProbe(boxcutter.ProgressProbeType, probing.And{ | ||||||||||
| &namespaceActiveProbe, deploymentProbe, statefulSetProbe, crdProbe, issuerProbe, certProbe, &pvcBoundProbe, progressionProbes, | ||||||||||
| }), | ||||||||||
| boxcutter.WithProbe(boxcutter.ProgressProbeType, progressionProbes), | ||||||||||
| } | ||||||||||
dtfranz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| phases := make([]boxcutter.Phase, 0) | ||||||||||
|
|
@@ -535,10 +530,10 @@ func buildProgressionProbes(progressionProbes []ocv1.ProgressionProbe) (probing. | |||||||||
| for _, probe := range progressionProbe.Assertions { | ||||||||||
| switch probe.Type { | ||||||||||
| // Switch based on the union discriminator | ||||||||||
| case ocv1.ProbeTypeFieldCondition: | ||||||||||
| case ocv1.ProbeTypeConditionEqual: | ||||||||||
| conditionProbe := probing.ConditionProbe(probe.ConditionEqual) | ||||||||||
| assertions = append(assertions, &conditionProbe) | ||||||||||
| case ocv1.ProbeTypeFieldEqual: | ||||||||||
| case ocv1.ProbeTypeFieldsEqual: | ||||||||||
| fieldsEqualProbe := probing.FieldsEqualProbe(probe.FieldsEqual) | ||||||||||
| assertions = append(assertions, &fieldsEqualProbe) | ||||||||||
| case ocv1.ProbeTypeFieldValue: | ||||||||||
|
|
@@ -570,90 +565,13 @@ func buildProgressionProbes(progressionProbes []ocv1.ProgressionProbe) (probing. | |||||||||
| default: | ||||||||||
| return nil, fmt.Errorf("unknown progressionProbe selector type: %s", progressionProbe.Selector.Type) | ||||||||||
| } | ||||||||||
| userProbes = append(userProbes, selectorProbe) | ||||||||||
| userProbes = append(userProbes, &probing.ObservedGenerationProbe{ | ||||||||||
| Prober: selectorProbe, | ||||||||||
| }) | ||||||||||
|
Comment on lines
+568
to
+570
|
||||||||||
| userProbes = append(userProbes, &probing.ObservedGenerationProbe{ | |
| Prober: selectorProbe, | |
| }) | |
| userProbes = append(userProbes, selectorProbe) |
Uh oh!
There was an error while loading. Please reload this page.