From ae48233569b25bd022b3b707979c3bd2ff2c2ae3 Mon Sep 17 00:00:00 2001 From: Jaydip Gabani Date: Sat, 16 Nov 2024 00:15:22 +0000 Subject: [PATCH] adding observed generation and not wiping CT VAPgeneration status Signed-off-by: Jaydip Gabani --- apis/status/v1beta1/constrainttemplatepodstatus_types.go | 7 ++++--- apis/status/v1beta1/zz_generated.deepcopy.go | 6 +++++- ...status.gatekeeper.sh_constrainttemplatepodstatuses.yaml | 3 +++ ...nstrainttemplatepodstatus-customresourcedefinition.yaml | 3 +++ manifest_staging/deploy/gatekeeper.yaml | 3 +++ pkg/controller/constrainttemplate/constants.go | 2 +- .../constrainttemplate/constrainttemplate_controller.go | 4 +++- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apis/status/v1beta1/constrainttemplatepodstatus_types.go b/apis/status/v1beta1/constrainttemplatepodstatus_types.go index 1caa411cdcd..a06c6696417 100644 --- a/apis/status/v1beta1/constrainttemplatepodstatus_types.go +++ b/apis/status/v1beta1/constrainttemplatepodstatus_types.go @@ -34,13 +34,14 @@ type ConstraintTemplatePodStatusStatus struct { Operations []string `json:"operations,omitempty"` ObservedGeneration int64 `json:"observedGeneration,omitempty"` Errors []*templatesv1beta1.CreateCRDError `json:"errors,omitempty"` - VAPGenerationStatus VAPGenerationStatus `json:"vapGenerationStatus,omitempty"` + VAPGenerationStatus *VAPGenerationStatus `json:"vapGenerationStatus,omitempty"` } // VAPGenerationStatus represents the status of VAP generation. type VAPGenerationStatus struct { - State string `json:"state,omitempty"` - Warning string `json:"warning,omitempty"` + State string `json:"state,omitempty"` + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + Warning string `json:"warning,omitempty"` } // +kubebuilder:object:root=true diff --git a/apis/status/v1beta1/zz_generated.deepcopy.go b/apis/status/v1beta1/zz_generated.deepcopy.go index 6b165de0856..0249b331f42 100644 --- a/apis/status/v1beta1/zz_generated.deepcopy.go +++ b/apis/status/v1beta1/zz_generated.deepcopy.go @@ -293,7 +293,11 @@ func (in *ConstraintTemplatePodStatusStatus) DeepCopyInto(out *ConstraintTemplat } } } - out.VAPGenerationStatus = in.VAPGenerationStatus + if in.VAPGenerationStatus != nil { + in, out := &in.VAPGenerationStatus, &out.VAPGenerationStatus + *out = new(VAPGenerationStatus) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConstraintTemplatePodStatusStatus. diff --git a/config/crd/bases/status.gatekeeper.sh_constrainttemplatepodstatuses.yaml b/config/crd/bases/status.gatekeeper.sh_constrainttemplatepodstatuses.yaml index 29bbc7fdae7..69b04663e0a 100644 --- a/config/crd/bases/status.gatekeeper.sh_constrainttemplatepodstatuses.yaml +++ b/config/crd/bases/status.gatekeeper.sh_constrainttemplatepodstatuses.yaml @@ -77,6 +77,9 @@ spec: vapGenerationStatus: description: VAPGenerationStatus represents the status of VAP generation. properties: + observedGeneration: + format: int64 + type: integer state: type: string warning: diff --git a/manifest_staging/charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml b/manifest_staging/charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml index 238d5987dc4..09b0b9c64e8 100644 --- a/manifest_staging/charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml +++ b/manifest_staging/charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml @@ -76,6 +76,9 @@ spec: vapGenerationStatus: description: VAPGenerationStatus represents the status of VAP generation. properties: + observedGeneration: + format: int64 + type: integer state: type: string warning: diff --git a/manifest_staging/deploy/gatekeeper.yaml b/manifest_staging/deploy/gatekeeper.yaml index 744a61ce966..b98798f1955 100644 --- a/manifest_staging/deploy/gatekeeper.yaml +++ b/manifest_staging/deploy/gatekeeper.yaml @@ -2784,6 +2784,9 @@ spec: vapGenerationStatus: description: VAPGenerationStatus represents the status of VAP generation. properties: + observedGeneration: + format: int64 + type: integer state: type: string warning: diff --git a/pkg/controller/constrainttemplate/constants.go b/pkg/controller/constrainttemplate/constants.go index 7265222d568..8f4ebae888f 100644 --- a/pkg/controller/constrainttemplate/constants.go +++ b/pkg/controller/constrainttemplate/constants.go @@ -15,7 +15,7 @@ const ( const ( // ErrGenerateVAPState indicates a problem generating a VAP. - ErrGenerateVAPState = "errror" + ErrGenerateVAPState = "error" // GeneratedVAPState indicates a VAP was generated. GeneratedVAPState = "generated" ) diff --git a/pkg/controller/constrainttemplate/constrainttemplate_controller.go b/pkg/controller/constrainttemplate/constrainttemplate_controller.go index b8c6f5bab7b..df29c8e79f8 100644 --- a/pkg/controller/constrainttemplate/constrainttemplate_controller.go +++ b/pkg/controller/constrainttemplate/constrainttemplate_controller.go @@ -331,7 +331,6 @@ func (r *ReconcileConstraintTemplate) Reconcile(ctx context.Context, request rec status.Status.TemplateUID = ct.GetUID() status.Status.ObservedGeneration = ct.GetGeneration() status.Status.Errors = nil - status.Status.VAPGenerationStatus = statusv1beta1.VAPGenerationStatus{} unversionedProposedCRD, err := r.cfClient.CreateCRD(ctx, unversionedCT) if err != nil { @@ -447,6 +446,7 @@ func (r *ReconcileConstraintTemplate) handleUpdate( if generateVap { generateVap = false status.Status.VAPGenerationStatus.State = ErrGenerateVAPState + status.Status.VAPGenerationStatus.ObservedGeneration = ct.GetGeneration() status.Status.VAPGenerationStatus.Warning = fmt.Sprintf("ValidatingAdmissionPolicy is not generated: %s", err.Error()) } } @@ -858,6 +858,8 @@ func (r *ReconcileConstraintTemplate) manageVAP(ctx context.Context, ct *v1beta1 } } status.Status.VAPGenerationStatus.State = GeneratedVAPState + status.Status.VAPGenerationStatus.ObservedGeneration = ct.GetGeneration() + status.Status.VAPGenerationStatus.Warning = "" } // do not generate VAP resources // remove if exists