-
Notifications
You must be signed in to change notification settings - Fork 18
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
Have PackageVariant set readiness gate on PackageRevisions #156
Open
JamesMcDermott
wants to merge
5
commits into
nephio-project:main
Choose a base branch
from
Nordix:pv-pipeline-readiness-gates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a01dd05
Issue #615 - have PackageVariant set readiness gate on PackageRevisions
JamesMcDermott aa7a45f
Issue #615 - fixed readiness-gate Git conflicts
JamesMcDermott 60cb107
Issue #615 - adjusted test data missed in previous commit
JamesMcDermott d854e74
Merge branch 'nephio-project:main' into pv-pipeline-readiness-gates
JamesMcDermott bd30aac
Issue #615 - skip pipeline on PackageRevision update if only updating…
JamesMcDermott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2023-2024 The kpt and Nephio Authors | ||
// Copyright 2022, 2024 The kpt and Nephio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -28,6 +28,7 @@ import ( | |
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" | ||
kptfilev1 "github.com/nephio-project/porch/pkg/kpt/api/kptfile/v1" | ||
"github.com/nephio-project/porch/pkg/kpt/kptfileutil" | ||
"github.com/nephio-project/porch/pkg/util" | ||
|
||
"golang.org/x/mod/semver" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
|
@@ -56,8 +57,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 | ||
ConditionTypeReady = "Ready" // whether or not the reconciliation succeeded | ||
ConditionTypePipelinePassed = "PackagePipelinePassed" // whether or not the package's pipeline has completed successfully | ||
) | ||
|
||
var ( | ||
conditionPipelineNotPassed = porchapi.Condition{ | ||
Type: ConditionTypePipelinePassed, | ||
Status: porchapi.ConditionFalse, | ||
Reason: "WaitingOnPipeline", | ||
Message: "waiting for package pipeline to pass", | ||
} | ||
conditionPipelinePassed = porchapi.Condition{ | ||
Type: ConditionTypePipelinePassed, | ||
Status: porchapi.ConditionTrue, | ||
Reason: "PipelinePassed", | ||
Message: "package 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 +351,13 @@ func (r *PackageVariantReconciler) ensurePackageVariant(ctx context.Context, | |
if err = r.Client.Create(ctx, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
setPrReadinessGate(newPR, ConditionTypePipelinePassed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. I'd be interested to see how this works in a full test-infra e2e run. |
||
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 +371,15 @@ func (r *PackageVariantReconciler) ensurePackageVariant(ctx context.Context, | |
} | ||
} | ||
|
||
if err := r.Client.Get(ctx, types.NamespacedName{Name: newPR.GetName(), Namespace: newPR.GetNamespace()}, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
setPrStatusCondition(newPR, conditionPipelinePassed) | ||
if err := r.Client.Update(ctx, newPR); err != nil { | ||
return nil, err | ||
} | ||
|
||
return []*porchapi.PackageRevision{newPR}, nil | ||
} | ||
|
||
|
@@ -369,10 +402,18 @@ func (r *PackageVariantReconciler) findAndUpdateExistingRevisions(ctx context.Co | |
downstream.Spec.Lifecycle = porchapi.PackageRevisionLifecyclePublished | ||
// We update this now, because later we may use a Porch call to clone or update | ||
// and we want to make sure the server is in sync with us | ||
|
||
setPrReadinessGate(downstream, ConditionTypePipelinePassed) | ||
setPrStatusCondition(downstream, conditionPipelineNotPassed) | ||
if err := r.Client.Update(ctx, downstream); err != nil { | ||
klog.Errorf("error updating package revision lifecycle: %v", err) | ||
return nil, err | ||
} | ||
|
||
setPrStatusCondition(downstream, conditionPipelinePassed) | ||
if err := r.Client.Update(ctx, downstream); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// see if the package needs updating due to an upstream change | ||
|
@@ -423,9 +464,20 @@ func (r *PackageVariantReconciler) findAndUpdateExistingRevisions(ctx context.Co | |
|
||
} | ||
// Save the updated PackageRevisionResources | ||
|
||
setPrReadinessGate(downstream, ConditionTypePipelinePassed) | ||
setPrStatusCondition(downstream, conditionPipelineNotPassed) | ||
if err := r.Client.Update(ctx, downstream); err != nil { | ||
return nil, err | ||
} | ||
if err := r.updatePackageResources(ctx, prr, pv); err != nil { | ||
return nil, err | ||
} | ||
|
||
setPrStatusCondition(downstream, conditionPipelinePassed) | ||
if err := r.Client.Update(ctx, downstream); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
return downstreams, nil | ||
|
@@ -694,8 +746,15 @@ func (r *PackageVariantReconciler) updateDraft(ctx context.Context, | |
updateTask.Update.Upstream.UpstreamRef.Name = newUpstreamPR.Name | ||
draft.Spec.Tasks = append(tasks, updateTask) | ||
|
||
err := r.Client.Update(ctx, draft) | ||
if err != nil { | ||
setPrReadinessGate(draft, ConditionTypePipelinePassed) | ||
setPrStatusCondition(draft, conditionPipelineNotPassed) | ||
|
||
if err := r.Client.Update(ctx, draft); err != nil { | ||
return nil, err | ||
} | ||
|
||
setPrStatusCondition(draft, conditionPipelinePassed) | ||
if err := r.Client.Update(ctx, draft); err != nil { | ||
return nil, err | ||
} | ||
return draft, nil | ||
|
@@ -724,10 +783,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 { | ||
|
@@ -1019,7 +1101,7 @@ func ensureKRMFunctions(pv *api.PackageVariant, | |
} | ||
|
||
// update kptfile | ||
prr.Spec.Resources[kptfilev1.KptFileName] = kptfile.String() | ||
prr.Spec.Resources[kptfilev1.KptFileName] = util.KubeObjectToYaml(kptfile) | ||
|
||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
findAndUpdateExistingRevisions()
method, at line 473:The pipeline will also be executed here, so the Condition should be set according to the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in
updateDraft()
at line 736:this is tricky, but technically this Update() call will also result in the re-execution of the pipeline, so we should record the results in the Condition. The tricky part is that I don't know how to get the rendering results, and without it, the best we can do is to report the error or success of Update() itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done both:
findAndUpdateExistingRevisions()
one could be a bit better by including the initial set of the Condition directly inprr
instead of doing a separater.Client.Update()
- I want to look into automated (and a few more manual) tests first thoughupdateDraft()
one took more time to work around to avoid ending up in an endless loop where doing theUpdate()
to set the Condition would trigger the pipeline, resulting in a rendering result which we'd need to record in the Condition by doing anUpdate()
, triggering the pipeline... you get the idea. :)