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 status diff for routing #516

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
25 changes: 25 additions & 0 deletions api/v1alpha1/routing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/nais/liberator/pkg/namegen"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"
"time"
)

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -117,3 +118,27 @@ func (in *Routing) GetDefaultLabels() map[string]string {
func (in *Routing) GetCommonSpec() *CommonSpec {
panic("common spec not available for routing resource type")
}

func (in *Routing) SetDefaultStatus() {
var msg string

if in.Status.Summary.Status == "" {
msg = "Default Routing status, it has not initialized yet"
} else {
msg = "Routing is trying to reconcile"
}

in.Status.Summary = Status{
Status: PENDING,
Message: msg,
TimeStamp: time.Now().String(),
}

if in.Status.SubResources == nil {
in.Status.SubResources = make(map[string]Status)
}

if len(in.Status.Conditions) == 0 {
in.Status.Conditions = make([]metav1.Condition, 0)
}
}
2 changes: 1 addition & 1 deletion api/v1alpha1/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ApplicationStatus
// SkiperatorStatus
//
// A status field shown on a Skiperator resource which contains information regarding deployment of the resource.
// +kubebuilder:object:generate=true
Expand Down
2 changes: 1 addition & 1 deletion config/crd/skiperator.kartverket.no_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ spec:
type: object
status:
description: |-
ApplicationStatus
SkiperatorStatus

A status field shown on a Skiperator resource which contains information regarding deployment of the resource.
properties:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/skiperator.kartverket.no_routings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ spec:
type: object
status:
description: |-
ApplicationStatus
SkiperatorStatus

A status field shown on a Skiperator resource which contains information regarding deployment of the resource.
properties:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/skiperator.kartverket.no_skipjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ spec:
type: object
status:
description: |-
ApplicationStatus
SkiperatorStatus

A status field shown on a Skiperator resource which contains information regarding deployment of the resource.
properties:
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *ApplicationReconciler) Reconcile(ctx context.Context, req reconcile.Req
return common.RequeueWithError(err)
}

//TODO do we need this actually?
// TODO do we need this actually?
isApplicationMarkedToBeDeleted := application.GetDeletionTimestamp() != nil
if isApplicationMarkedToBeDeleted {
if err = r.finalizeApplication(application, ctx); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions internal/controllers/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ func (r *RoutingReconciler) Reconcile(ctx context.Context, req reconcile.Request
return common.DoNotRequeue()
}

tmpStatus := routing.GetStatus().DeepCopy()

routing.SetDefaultStatus()
statusDiff, err := common.GetObjectDiff(tmpStatus, routing.GetStatus())
if err != nil {
return common.RequeueWithError(err)
}

if len(statusDiff) > 0 {
rLog.Info("Status has changed", "diff", statusDiff)
err = r.GetClient().Status().Update(ctx, routing)
return reconcile.Result{Requeue: true}, err
}

if err := r.setDefaultSpec(ctx, routing); err != nil {
rLog.Error(err, "error when trying to set default spec")
r.SetErrorState(ctx, routing, err, "error when trying to set default spec", "DefaultSpecFailure")
Expand Down