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

Add optional built-in substitution of last attempted revision #968

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions internal/controller/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type KustomizationReconciler struct {
DefaultServiceAccount string
KubeConfigOpts runtimeClient.KubeConfigOptions
ConcurrentSSA int
ImplicitSubstitutions bool
}

// KustomizationReconcilerOptions contains options for the KustomizationReconciler.
Expand Down Expand Up @@ -617,6 +618,17 @@ func (r *KustomizationReconciler) build(ctx context.Context,
}
}

// add built-in substitutions
if r.ImplicitSubstitutions {
if obj.Spec.PostBuild == nil {
obj.Spec.PostBuild = &kustomizev1.PostBuild{}
}
if obj.Spec.PostBuild.Substitute == nil {
obj.Spec.PostBuild.Substitute = make(map[string]string)
}
obj.Spec.PostBuild.Substitute["FLUX_LAST_ATTEMPTED_REVISION"] = obj.Status.LastAttemptedRevision
}

// run variable substitutions
if obj.Spec.PostBuild != nil {
outRes, err := generator.SubstituteVariables(ctx, r.Client, u, res, false)
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func init() {

func main() {
var (
implicitSubstitutions bool
metricsAddr string
eventsAddr string
healthAddr string
Expand All @@ -101,6 +102,8 @@ func main() {
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent kustomize reconciles.")
flag.IntVar(&concurrentSSA, "concurrent-ssa", 4, "The number of concurrent server-side apply operations.")
flag.DurationVar(&requeueDependency, "requeue-dependency", 30*time.Second, "The interval at which failing dependencies are reevaluated.")
flag.BoolVar(&implicitSubstitutions, "implicit-substitutions", false,
"Perform substitutions of built-in values such as last-attempted-revision; has side effects of ALWAYS performing substitutions!")
flag.BoolVar(&noRemoteBases, "no-remote-bases", false,
"Disallow remote bases usage in Kustomize overlays. When this flag is enabled, all resources must refer to local files included in the source artifact.")
flag.IntVar(&httpRetry, "http-retry", 9, "The maximum number of retries when failing to fetch artifacts over HTTP.")
Expand Down Expand Up @@ -223,6 +226,7 @@ func main() {
Metrics: metricsH,
EventRecorder: eventRecorder,
NoCrossNamespaceRefs: aclOptions.NoCrossNamespaceRefs,
ImplicitSubstitutions: implicitSubstitutions,
NoRemoteBases: noRemoteBases,
FailFast: failFast,
ConcurrentSSA: concurrentSSA,
Expand Down