Skip to content

Commit

Permalink
chore: rename row Images Age to Last-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
dmicheneau committed Oct 22, 2024
1 parent acf4c9c commit f469f6f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
12 changes: 6 additions & 6 deletions api/v1alpha1/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ type (
ImageStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Tag string `json:"tag"`
Result string `json:"result"`
Age string `json:"age"`
Tag string `json:"tag"`
Result ImageStatusLastSync `json:"result"`
Time string `json:"time"`
}
)

Expand All @@ -114,7 +114,7 @@ type (
// +kubebuilder:printcolumn:name="Image",type=string,JSONPath=`.spec.image`
// +kubebuilder:printcolumn:name="Tag",type=string,JSONPath=`.status.tag`
// +kubebuilder:printcolumn:name="Last-Result",type=string,JSONPath=`.status.result`
// +kubebuilder:printcolumn:name="Last-Sync",type=date,JSONPath=`.status.age`
// +kubebuilder:printcolumn:name="Last-Sync",type=date,JSONPath=`.status.time`
type Image struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -142,13 +142,13 @@ func (i *Image) SetStatusTag(tag string) {
}

// SetStatusExecution sets the status execution of the image
func (i *Image) SetStatusResult(result string) {
func (i *Image) SetStatusResult(result ImageStatusLastSync) {
i.Status.Result = result
}

// SetStatusTime sets the status time of the image
func (i *Image) SetStatusTime(time string) {
i.Status.Age = time
i.Status.Time = time
}

// GetImageWithTag returns the image name with the tag
Expand Down
19 changes: 11 additions & 8 deletions cmd/kimup/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
defer cancel()

image, err := k.Image().Get(ctx, e.Data()["namespace"].(string), e.Data()["image"].(string))
// TODO - Add a defer function to update the status of kind Image
defer func() {
// update the status of the image
image.SetStatusTime(time.Now().Format(time.RFC3339))
err := k.Image().UpdateStatus(ctx, image)
if err != nil {
log.Errorf("Error updating status of image %s in namespace %s: %v", e.Data()["image"], e.Data()["namespace"], err)
log.WithError(err).
WithFields(log.Fields{
"Namespace": e.Data()["namespace"],
"Image": e.Data()["image"],
}).Error("Error updating status of image")
}
}()
if err != nil {
image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncErrorGetImage))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncErrorGetImage)
if err := crontab.RemoveJob(crontab.BuildKey(e.Data()["namespace"].(string), e.Data()["image"].(string))); err != nil {
return err
}
Expand All @@ -75,7 +78,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {

if image.Spec.ImagePullSecrets != nil {
auths, err = k.GetPullSecretsForImage(ctx, image)
image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncErrorPullSecrets))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncErrorPullSecrets)
if err != nil {
return err
}
Expand Down Expand Up @@ -106,7 +109,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
if err != nil {
// Prometheus metrics - Increment the counter for the registry with error
metrics.Registry().TotalErr().Inc()
image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncErrorRegistry))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncErrorRegistry)
return err
}

Expand All @@ -128,7 +131,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
for _, rule := range image.Spec.Rules {
r, err := rules.GetRule(rule.Type)
if err != nil {
image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncErrorGetRule))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncErrorGetRule)
log.Errorf("Error getting rule: %v", err)
continue
}
Expand Down Expand Up @@ -160,7 +163,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
if match {
for _, action := range rule.Actions {
a, err := actions.GetActionWithUntypedName(action.Type)
image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncErrorAction))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncErrorAction)
if err != nil {
log.Errorf("Error getting action: %v", err)
continue
Expand Down Expand Up @@ -193,7 +196,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
}
}

image.SetStatusResult(string(v1alpha1.ImageStatusLastSyncSuccess))
image.SetStatusResult(v1alpha1.ImageStatusLastSyncSuccess)
return k.Image().Update(ctx, image)
})

Expand Down
8 changes: 4 additions & 4 deletions config/crd/bases/kimup.cloudavenue.io_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- jsonPath: .status.result
name: Last-Result
type: string
- jsonPath: .status.age
- jsonPath: .status.time
name: Last-Sync
type: date
name: v1alpha1
Expand Down Expand Up @@ -219,19 +219,19 @@ spec:
status:
description: ImageStatus defines the observed state of Image
properties:
age:
type: string
result:
type: string
tag:
description: |-
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Important: Run "make" to regenerate code after modifying this file
type: string
time:
type: string
required:
- age
- result
- tag
- time
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *ImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
equal, err := an.CheckSum().IsEqual(image.Spec)
if err != nil || !equal {
an.Action().Set(annotations.ActionReload)
image.SetStatusResult(string(kimupv1alpha1.ImageStatusLastSyncScheduled))
image.SetStatusResult(kimupv1alpha1.ImageStatusLastSyncScheduled)
r.Recorder.Event(&image, "Normal", string(ImageUpdate), "Image configuration has changed. Reloading image.")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/kubeclient/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (i *ImageObj) Watch(ctx context.Context) (chan WatchInterface[v1alpha1.Imag
}

// UpdateStatus updates the status of the image object.
// It takes a context and a pointer to the image object as parameters.
// It takes a context and a image object as parameters.
// Returns an error if the operation fails; otherwise, it returns nil.
func (i *ImageObj) UpdateStatus(ctx context.Context, image v1alpha1.Image) error {
u, err := encodeUnstructured(image)
Expand Down

0 comments on commit f469f6f

Please sign in to comment.