Skip to content

Commit

Permalink
feat: introduce 2 new status fields and show them in kubectl get comm…
Browse files Browse the repository at this point in the history
…and (#52)

* feat(layer): introduce 2 new status fields and show them in kubectl get command

* refactor(state): move getStateString to states.go
  • Loading branch information
Alan-pad authored Feb 21, 2023
1 parent b05ebc2 commit d0867ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ bin
testbin/*
Dockerfile.cross

*.lock.hcl
*.tfstate
*.tfstate.backup

.terraform/

# Test binary, build with `go test -c`
*.test

Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/terraformlayer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/terraformlayer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/controllers/terraformlayer/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)]
}

0 comments on commit d0867ab

Please sign in to comment.