-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #615 - have PackageVariant set readiness gate on PackageRevisions
- PackageVariant controller now uses a readiness gate to allow a PackageRevision to complete its mutation pipeline before it is allowed to be proposed/approved - refactored conversion of Kptfiles to YAML since readiness condition information is stored in the package Kptfile - unified all cases to the same kyaml/yaml-based method (KptFile.ToYamlString() and ToYamlString(*fn.KubeObject)) - this ensures consistency in the YAML (indentation, field order etc.) - and reduces the chances of Git conflicts when setting and updating readiness conditions - added more info to error message in case of Git conflict when applying a patch nephio-project/nephio#615
- Loading branch information
1 parent
6d34cf8
commit bd38163
Showing
11 changed files
with
152 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,8 +56,24 @@ type PackageVariantReconciler struct { | |
const ( | ||
workspaceNamePrefix = "packagevariant-" | ||
|
||
ConditionTypeStalled = "Stalled" // whether or not the packagevariant object is making progress or not | ||
ConditionTypeReady = "Ready" // whether or not the reconciliation succeeded | ||
ConditionTypeStalled = "Stalled" // whether or not the packagevariant object is making progress or not | ||
ConditionTypeReady = "Ready" // whether or not the reconciliation succeeded | ||
ConditionTypePipelinePassed = "MutationPipelinePassed" // whether or not the mutation pipeline has completed successufully | ||
) | ||
|
||
var ( | ||
conditionPipelineNotPassed = porchapi.Condition{ | ||
Type: ConditionTypePipelinePassed, | ||
Status: porchapi.ConditionFalse, | ||
Reason: "WaitingOnPipeline", | ||
Message: "waiting for mutation pipeline to pass", | ||
} | ||
conditionPipelinePassed = porchapi.Condition{ | ||
Type: ConditionTypePipelinePassed, | ||
Status: porchapi.ConditionTrue, | ||
Reason: "PipelinePassed", | ||
Message: "mutation pipeline completed successfully", | ||
} | ||
) | ||
|
||
//go:generate go run sigs.k8s.io/controller-tools/cmd/[email protected] rbac:headerFile=../../../../../scripts/boilerplate.yaml.txt,roleName=porch-controllers-packagevariants webhook paths="." output:rbac:artifacts:config=../../../config/rbac | ||
|
@@ -334,6 +350,13 @@ func (r *PackageVariantReconciler) ensurePackageVariant(ctx context.Context, | |
if err = r.Client.Create(ctx, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
setPrReadinessGate(newPR, ConditionTypePipelinePassed) | ||
setPrStatusCondition(newPR, conditionPipelineNotPassed) | ||
if err := r.Client.Update(ctx, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
klog.Infoln(fmt.Sprintf("package variant %q created package revision %q", pv.Name, newPR.Name)) | ||
|
||
prr, changed, err := r.calculateDraftResources(ctx, pv, newPR) | ||
|
@@ -347,6 +370,29 @@ func (r *PackageVariantReconciler) ensurePackageVariant(ctx context.Context, | |
} | ||
} | ||
|
||
// TODO: remove if OK to exclude PackageRevision from cache of r.Client | ||
// | ||
// var tmpClient client.Client | ||
// if tmpClient, err = client.New(config.GetConfigOrDie(), client.Options{ | ||
// Cache: &client.CacheOptions{ | ||
// DisableFor: []client.Object{ | ||
// &porchapi.PackageRevisionResources{}}, | ||
// }, | ||
// }); err != nil { | ||
// return nil, err | ||
// } | ||
var refreshedPR porchapi.PackageRevision | ||
if err := r.Client.Get(ctx, types.NamespacedName{Name: newPR.GetName(), Namespace: newPR.GetNamespace()}, &refreshedPR); err != nil { | ||
return nil, err | ||
} | ||
newPR.ResourceVersion = refreshedPR.ResourceVersion | ||
newPR.Spec.Tasks = refreshedPR.Spec.Tasks | ||
|
||
setPrStatusCondition(newPR, conditionPipelinePassed) | ||
if err := r.Client.Update(ctx, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
return []*porchapi.PackageRevision{newPR}, nil | ||
} | ||
|
||
|
@@ -716,10 +762,33 @@ func setTargetStatusConditions(pv *api.PackageVariant, targets []*porchapi.Packa | |
Type: ConditionTypeReady, | ||
Status: "True", | ||
Reason: "NoErrors", | ||
Message: "successfully ensured downstream package variant", | ||
Message: "successfully ensured downstream target package revision", | ||
}) | ||
} | ||
|
||
func setPrReadinessGate(pr *porchapi.PackageRevision, conditionType string) { | ||
for _, aGate := range pr.Spec.ReadinessGates { | ||
if aGate.ConditionType == conditionType { | ||
return | ||
} | ||
} | ||
|
||
pr.Spec.ReadinessGates = append(pr.Spec.ReadinessGates, porchapi.ReadinessGate{ | ||
ConditionType: conditionType, | ||
}) | ||
} | ||
|
||
func setPrStatusCondition(pr *porchapi.PackageRevision, condition porchapi.Condition) { | ||
for index, aCondition := range pr.Status.Conditions { | ||
if aCondition.Type == condition.Type { | ||
pr.Status.Conditions[index] = condition | ||
return | ||
} | ||
} | ||
|
||
pr.Status.Conditions = append(pr.Status.Conditions, condition) | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func (r *PackageVariantReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
if err := api.AddToScheme(mgr.GetScheme()); err != nil { | ||
|
@@ -1011,7 +1080,11 @@ func ensureKRMFunctions(pv *api.PackageVariant, | |
} | ||
|
||
// update kptfile | ||
prr.Spec.Resources[kptfilev1.KptFileName] = kptfile.String() | ||
kptfileYaml, err := kptfilev1.ToYamlString(kptfile) | ||
if err != nil { | ||
return err | ||
} | ||
prr.Spec.Resources[kptfilev1.KptFileName] = kptfileYaml | ||
|
||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters