diff --git a/.gitignore b/.gitignore index b3c0f2f7..564841d0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,12 @@ bin testbin/* Dockerfile.cross +*.lock.hcl +*.tfstate +*.tfstate.backup + +.terraform/ + # Test binary, build with `go test -c` *.test diff --git a/api/v1alpha1/terraformlayer_types.go b/api/v1alpha1/terraformlayer_types.go index 2a5c637b..95499753 100644 --- a/api/v1alpha1/terraformlayer_types.go +++ b/api/v1alpha1/terraformlayer_types.go @@ -46,6 +46,10 @@ type TerraformLayerRepository struct { // TerraformLayerStatus defines the observed state of TerraformLayer type TerraformLayerStatus struct { Conditions []metav1.Condition `json:"conditions,omitempty"` + //+kubebuilder:printcolumn + State string `json:"state,omitempty"` + //+kubebuilder:printcolumn + LastResult string `json:"lastResult,omitempty"` } //+kubebuilder:object:root=true diff --git a/internal/controllers/terraformlayer/controller.go b/internal/controllers/terraformlayer/controller.go index 46990825..372260d3 100644 --- a/internal/controllers/terraformlayer/controller.go +++ b/internal/controllers/terraformlayer/controller.go @@ -89,7 +89,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{RequeueAfter: r.Config.Controller.Timers.OnError}, err } state, conditions := r.GetState(ctx, layer) - layer.Status = configv1alpha1.TerraformLayerStatus{Conditions: conditions} + layer.Status = configv1alpha1.TerraformLayerStatus{Conditions: conditions, State: getStateString(state)} result := state.getHandler()(ctx, r, layer, repository) err = r.Client.Status().Update(ctx, layer) if err != nil { diff --git a/internal/controllers/terraformlayer/states.go b/internal/controllers/terraformlayer/states.go index b4ae0ff2..d0fecd9b 100644 --- a/internal/controllers/terraformlayer/states.go +++ b/internal/controllers/terraformlayer/states.go @@ -2,6 +2,8 @@ package terraformlayer import ( "context" + "fmt" + "strings" configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" "github.com/padok-team/burrito/internal/lock" @@ -102,3 +104,8 @@ func getRemediationStrategy(repo *configv1alpha1.TerraformRepository, layer *con } return result } + +func getStateString(state State) string { + t := strings.Split(fmt.Sprintf("%T", state), "/") + return t[len(t)] +}