From 48ca17f6c58f93643eaed6470c9d0ad708a66b6c Mon Sep 17 00:00:00 2001
From: Ashok Siyani
Date: Thu, 21 Sep 2023 10:38:46 +0100
Subject: [PATCH] removed suspended field from crd
---
.gitignore | 1 +
README.md | 1 -
api/v1beta1/module_types.go | 10 ---
api/v1beta1/zz_generated.deepcopy.go | 5 --
.../terraform-applier.uw.systems_modules.yaml | 7 --
controllers/module_controller.go | 6 --
.../module_controller_no_runner_test.go | 82 -------------------
webserver/template_test.go | 19 ++---
webserver/templates/status.html | 7 +-
9 files changed, 9 insertions(+), 129 deletions(-)
diff --git a/.gitignore b/.gitignore
index f900c3f..9c89ee2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ terraform-applier
bin
# test state files
*.tfstate
+webserver/index.html
\ No newline at end of file
diff --git a/README.md b/README.md
index 15edc65..d7555e1 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,6 @@ spec:
repoName: terraform-applier
path: dev/hello
schedule: "00 */1 * * *"
- suspend: false
planOnly: false
pollInterval: 60
runTimeout: 900
diff --git a/api/v1beta1/module_types.go b/api/v1beta1/module_types.go
index 1c46ca1..ecec517 100644
--- a/api/v1beta1/module_types.go
+++ b/api/v1beta1/module_types.go
@@ -84,11 +84,6 @@ type ModuleSpec struct {
// +optional
Schedule string `json:"schedule,omitempty"`
- // This flag tells the controller to suspend all subsequent runs, it does
- // not apply to already started run. Defaults to false.
- // +optional
- Suspend *bool `json:"suspend,omitempty"`
-
// +optional
PlanOnly *bool `json:"planOnly,omitempty"`
@@ -195,7 +190,6 @@ type ModuleStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Schedule",type="string",JSONPath=".spec.schedule",description=""
-//+kubebuilder:printcolumn:name="Suspend",type="string",JSONPath=".spec.suspend",description=""
//+kubebuilder:printcolumn:name="PlanOnly",type="string",JSONPath=".spec.planOnly",description=""
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.currentState",description=""
//+kubebuilder:printcolumn:name="Started At",type="string",JSONPath=`.status.runStartedAt`,description=""
@@ -289,10 +283,6 @@ type Subject struct {
Name string `json:"name,omitempty"`
}
-func (m *Module) IsSuspended() bool {
- return m.Spec.Suspend != nil && *m.Spec.Suspend
-}
-
func (m *Module) IsPlanOnly() bool {
return m.Spec.PlanOnly != nil && *m.Spec.PlanOnly
}
diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go
index 833f912..7db9e18 100644
--- a/api/v1beta1/zz_generated.deepcopy.go
+++ b/api/v1beta1/zz_generated.deepcopy.go
@@ -88,11 +88,6 @@ func (in *ModuleList) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ModuleSpec) DeepCopyInto(out *ModuleSpec) {
*out = *in
- if in.Suspend != nil {
- in, out := &in.Suspend, &out.Suspend
- *out = new(bool)
- **out = **in
- }
if in.PlanOnly != nil {
in, out := &in.PlanOnly, &out.PlanOnly
*out = new(bool)
diff --git a/config/crd/bases/terraform-applier.uw.systems_modules.yaml b/config/crd/bases/terraform-applier.uw.systems_modules.yaml
index ddbe56d..b788fa6 100644
--- a/config/crd/bases/terraform-applier.uw.systems_modules.yaml
+++ b/config/crd/bases/terraform-applier.uw.systems_modules.yaml
@@ -18,9 +18,6 @@ spec:
- jsonPath: .spec.schedule
name: Schedule
type: string
- - jsonPath: .spec.suspend
- name: Suspend
- type: string
- jsonPath: .spec.planOnly
name: PlanOnly
type: string
@@ -357,10 +354,6 @@ spec:
run for a given schedule if no schedule provided then module will
only run if new PRs are added to given module path
type: string
- suspend:
- description: This flag tells the controller to suspend all subsequent
- runs, it does not apply to already started run. Defaults to false.
- type: boolean
var:
description: List of input variables passed to the Terraform execution.
items:
diff --git a/controllers/module_controller.go b/controllers/module_controller.go
index b4c55af..a1b056d 100644
--- a/controllers/module_controller.go
+++ b/controllers/module_controller.go
@@ -77,12 +77,6 @@ func (r *ModuleReconciler) Reconcile(ctx context.Context, req reconcile.Request)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
- // Do not requeue if suspended
- if module.Spec.Suspend != nil && *module.Spec.Suspend {
- log.Debug("module suspended, skipping")
- return ctrl.Result{}, nil
- }
-
// Do not requeue if module is being deleted
if !module.ObjectMeta.DeletionTimestamp.IsZero() {
// TODO: what if module is in running state?
diff --git a/integration_test/module_controller_no_runner_test.go b/integration_test/module_controller_no_runner_test.go
index 1b4baf6..b57fccb 100644
--- a/integration_test/module_controller_no_runner_test.go
+++ b/integration_test/module_controller_no_runner_test.go
@@ -317,87 +317,5 @@ var _ = Describe("Module controller without runner", func() {
// delete module to stopping requeue
Expect(k8sClient.Delete(ctx, module)).Should(Succeed())
})
-
- It("Should not trigger run for suspended module", func() {
- const (
- moduleName = "test-module5"
- repo = "modules"
- path = "dev/" + moduleName
- )
- var boolTrue = true
- // testGitSyncPool.EXPECT().HasChangesForPath(gomock.Any(), repo, path, "CommitAbc123").Return(true, nil)
-
- By("By creating a new Module")
- ctx := context.Background()
- module := &tfaplv1beta1.Module{
- TypeMeta: metav1.TypeMeta{
- APIVersion: "terraform-applier.uw.systems/v1beta1",
- Kind: "Module",
- },
- ObjectMeta: metav1.ObjectMeta{
- Name: moduleName,
- Namespace: moduleNamespace,
- },
- Spec: tfaplv1beta1.ModuleSpec{
- Schedule: "1 * * * *",
- RepoName: repo,
- Path: path,
- },
- }
- Expect(k8sClient.Create(ctx, module)).Should(Succeed())
-
- // After creating this Module, let's check that the Module's Spec fields match what we passed in.
- moduleLookupKey := types.NamespacedName{Name: moduleName, Namespace: moduleNamespace}
- fetchedModule := &tfaplv1beta1.Module{}
-
- Eventually(func() bool {
- err := k8sClient.Get(ctx, moduleLookupKey, fetchedModule)
- return err == nil
- }, time.Second*10, interval).Should(BeTrue())
-
- By("By absorbing initial run due to no run commit history and updating status with commit hash")
- Eventually(func() types.NamespacedName {
- timer := time.NewTimer(time.Second)
- for {
- select {
- case req := <-testControllerQueue:
- return req.NamespacedName
- case <-timer.C:
- return types.NamespacedName{}
- }
- }
- }, time.Second*60, interval).Should(Equal(moduleLookupKey))
- // trick controller to accept mocked test time as earliestTime as we cannot control created time
- // also add commit of initial run
- fetchedModule.Status.RunCommitHash = "CommitAbc123"
- fetchedModule.Status.RunStartedAt = &metav1.Time{Time: time.Date(2022, 02, 01, 01, 00, 30, 0000, time.UTC)}
- Expect(k8sClient.Status().Update(ctx, fetchedModule)).Should(Succeed())
-
- // let controller reschedule
- time.Sleep(10 * time.Second)
-
- By("By suspending Module")
- // moduleLookupKey := types.NamespacedName{Name: moduleName, Namespace: moduleNamespace}
- fetchedModule.Spec.Suspend = &boolTrue
- Expect(k8sClient.Update(ctx, fetchedModule)).Should(Succeed())
-
- // advance time
- By("By making sure job was never sent to jobQueue after advancing time")
- fakeClock.T = time.Date(2022, 02, 01, 01, 01, 00, 0000, time.UTC)
- Consistently(func() types.NamespacedName {
- timer := time.NewTimer(time.Second)
- for {
- select {
- case req := <-testControllerQueue:
- return req.NamespacedName
- case <-timer.C:
- return types.NamespacedName{}
- }
- }
- }, time.Second*20, interval).Should(Equal(types.NamespacedName{}))
- // delete module to stopping requeue
- Expect(k8sClient.Delete(ctx, module)).Should(Succeed())
- })
-
})
})
diff --git a/webserver/template_test.go b/webserver/template_test.go
index e784135..9117442 100644
--- a/webserver/template_test.go
+++ b/webserver/template_test.go
@@ -51,15 +51,6 @@ func Test_ExecuteTemplate(t *testing.T) {
StateMessage: `some very long error message with \n Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future`,
},
},
- {
- TypeMeta: metav1.TypeMeta{APIVersion: "terraform-applier.uw.systems/v1beta1", Kind: "Module"},
- ObjectMeta: metav1.ObjectMeta{Name: "application", Namespace: "bar"},
- Spec: tfaplv1beta1.ModuleSpec{
- Schedule: "00 06 * * *",
- Path: "dev/application",
- Suspend: &boolTrue,
- },
- },
{
TypeMeta: metav1.TypeMeta{APIVersion: "terraform-applier.uw.systems/v1beta1", Kind: "Module"},
ObjectMeta: metav1.ObjectMeta{Name: "groups", Namespace: "bar"},
@@ -160,9 +151,9 @@ Apply complete! Resources: 7 added, 0 changed, 0 destroyed.`,
return
}
- // // uncomment to load index.html file locally after running test
- // if err := os.WriteFile("index.html", rendered.Bytes(), 0666); err != nil {
- // t.Errorf("error reading test file: %v\n", err)
- // return
- // }
+ // open index.html in browser to view test output
+ if err := os.WriteFile("index.html", rendered.Bytes(), 0666); err != nil {
+ t.Errorf("error reading test file: %v\n", err)
+ return
+ }
}
diff --git a/webserver/templates/status.html b/webserver/templates/status.html
index fccd383..de4a91c 100644
--- a/webserver/templates/status.html
+++ b/webserver/templates/status.html
@@ -67,12 +67,10 @@ {{.Name}} {{ if .IsPlanOnly}}(plan only){{end}}
class='badge rounded-pill bg-primary'
{{else if eq .Status.CurrentState "Errored"}}
class='badge rounded-pill bg-danger'
- {{else if .IsSuspended}}
- class='badge rounded-pill bg-warning text-dark'
{{else}}
class='badge rounded-pill bg-light text-dark'
{{end}}>
- {{ if .IsSuspended}}Suspended{{else}}{{.Status.CurrentState}} ({{.Status.StateReason}}){{end}}
+ {{.Status.CurrentState}} ({{.Status.StateReason}})
@@ -132,7 +130,8 @@ {{.Name}} {{ if .IsPlanOnly}}(plan only){{end}}
At: {{ formattedTime .Status.LastApplyInfo.Timestamp }}
- {{.Status.LastApplyInfo.Output}}
+
+{{.Status.LastApplyInfo.Output}}