Skip to content

Commit 17849e6

Browse files
committed
enable setting the require-approval plugin image
1 parent b5160a9 commit 17849e6

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

cmd/manager/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func main() {
4343
var inheritNodeSelector bool
4444
var inheritAffinty bool
4545
var inheritTolerations bool
46+
var requireApprovalImage string
4647

4748
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
4849
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -54,6 +55,7 @@ func main() {
5455
flag.BoolVar(&inheritNodeSelector, "inherit-node-selector", false, "Use the controller's nodeSelector for every task created by the controller")
5556
flag.BoolVar(&inheritAffinty, "inherit-affinity", false, "Use the controller's affinity rules for every task created by the controller")
5657
flag.BoolVar(&inheritTolerations, "inherit-tolerations", false, "Use the controller's tolerations for every task created by the controller")
58+
flag.StringVar(&requireApprovalImage, "require-approval-image", "ghcr.io/galleybytes/require-approval:0.2.0", "Plugin image for require-approval")
5759
opts := zap.Options{
5860
Development: true,
5961
Level: zapcore.DebugLevel,
@@ -108,6 +110,7 @@ func main() {
108110
NodeSelectorCacheKey: "inherited_nodeselector",
109111
InheritTolerations: inheritTolerations,
110112
TolerationsCacheKey: "inherited_tolerations",
113+
RequireApprovalImage: requireApprovalImage,
111114
}).SetupWithManager(mgr); err != nil {
112115
setupLog.Error(err, "unable to create controller", "controller", "Cluster")
113116
os.Exit(1)

pkg/controllers/terraform_controller.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ type ReconcileTerraform struct {
7777
// Value of this field will come from the owning deployment and cached.
7878
InheritTolerations bool
7979
TolerationsCacheKey string
80+
81+
// When requireApproval is true, the require-approval plugin is injected into the plan pod
82+
// when generating the pod manifest. The require-approval image is not modifiable via the Terraform
83+
// Resource in order to ensure the highest compatibility with the other TFO projects (like
84+
// terraform-operator-api and terraform-operator-dashboard).
85+
RequireApprovalImage string
8086
}
8187

8288
// createEnvFromSources adds any of the global environment vars defined at the controller scope
@@ -318,9 +324,10 @@ type TaskOptions struct {
318324
// as the download location for the script to execute in the task.
319325
urlSource string
320326

321-
versionedName string
322-
requireApproval bool
323-
restartPolicy corev1.RestartPolicy
327+
versionedName string
328+
requireApproval bool
329+
requireApprovalImage string
330+
restartPolicy corev1.RestartPolicy
324331

325332
volumes []corev1.Volume
326333
volumeMounts []corev1.VolumeMount
@@ -329,7 +336,7 @@ type TaskOptions struct {
329336
sidecarPlugins []corev1.Pod
330337
}
331338

332-
func newTaskOptions(tf *tfv1beta1.Terraform, task tfv1beta1.TaskName, generation int64, globalEnvFrom []corev1.EnvFromSource, affinity *corev1.Affinity, nodeSelector map[string]string, tolerations []corev1.Toleration) TaskOptions {
339+
func newTaskOptions(tf *tfv1beta1.Terraform, task tfv1beta1.TaskName, generation int64, globalEnvFrom []corev1.EnvFromSource, affinity *corev1.Affinity, nodeSelector map[string]string, tolerations []corev1.Toleration, requireApprovalImage string) TaskOptions {
333340
// TODO Read the tfstate and decide IF_NEW_RESOURCE based on that
334341
// applyAction := false
335342
resourceName := tf.Name
@@ -541,6 +548,7 @@ func newTaskOptions(tf *tfv1beta1.Terraform, task tfv1beta1.TaskName, generation
541548
outputsToOmit: outputsToOmit,
542549
urlSource: urlSource,
543550
requireApproval: requireApproval,
551+
requireApprovalImage: requireApprovalImage,
544552
restartPolicy: restartPolicy,
545553
volumes: volumes,
546554
volumeMounts: volumeMounts,
@@ -725,7 +733,7 @@ func (r *ReconcileTerraform) Reconcile(ctx context.Context, request reconcile.Re
725733
podType := currentStage.TaskType
726734
generation := currentStage.Generation
727735
affinity, nodeSelector, tolerations := r.getNodeSelectorsFromCache()
728-
runOpts := newTaskOptions(tf, currentStage.TaskType, generation, globalEnvFrom, affinity, nodeSelector, tolerations)
736+
runOpts := newTaskOptions(tf, currentStage.TaskType, generation, globalEnvFrom, affinity, nodeSelector, tolerations, r.RequireApprovalImage)
729737

730738
if podType == tfv1beta1.RunNil {
731739
// podType is blank when the terraform workflow has completed for
@@ -864,7 +872,7 @@ func (r *ReconcileTerraform) Reconcile(ctx context.Context, request reconcile.Re
864872
if (podType == tfv1beta1.RunPlan || podType == tfv1beta1.RunPlanDelete) && runOpts.requireApproval {
865873
requireApprovalSidecarPlugin := tfv1beta1.Plugin{
866874
ImageConfig: tfv1beta1.ImageConfig{
867-
Image: "ghcr.io/galleybytes/require-approval:0.1.1",
875+
Image: runOpts.requireApprovalImage,
868876
ImagePullPolicy: corev1.PullIfNotPresent,
869877
},
870878
Must: true,
@@ -1518,7 +1526,7 @@ func (r ReconcileTerraform) getNodeSelectorsFromCache() (*corev1.Affinity, map[s
15181526
// Define a set of TaskOptions specific for the plugin task
15191527
func (r ReconcileTerraform) getPluginRunOpts(tf *tfv1beta1.Terraform, pluginTaskName tfv1beta1.TaskName, pluginConfig tfv1beta1.Plugin, globalEnvFrom []corev1.EnvFromSource) TaskOptions {
15201528
affinity, nodeSelector, tolerations := r.getNodeSelectorsFromCache()
1521-
pluginRunOpts := newTaskOptions(tf, pluginTaskName, tf.Generation, globalEnvFrom, affinity, nodeSelector, tolerations)
1529+
pluginRunOpts := newTaskOptions(tf, pluginTaskName, tf.Generation, globalEnvFrom, affinity, nodeSelector, tolerations, r.RequireApprovalImage)
15221530
pluginRunOpts.image = pluginConfig.Image
15231531
pluginRunOpts.imagePullPolicy = pluginConfig.ImagePullPolicy
15241532
return pluginRunOpts

0 commit comments

Comments
 (0)