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

chore: Drop module condition metrics #2188

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
14 changes: 5 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *ma
descriptorProvider := provider.NewCachedDescriptorProvider()
kymaMetrics := metrics.NewKymaMetrics(sharedMetrics)
mandatoryModulesMetrics := metrics.NewMandatoryModulesMetrics()
moduleMetrics := metrics.NewModuleMetrics()

// The maintenance windows policy should be passed to the reconciler to be resolved: https://github.com/kyma-project/lifecycle-manager/issues/2101
_, err = maintenancewindows.InitializeMaintenanceWindowsPolicy(setupLog, maintenanceWindowPoliciesDirectory,
Expand All @@ -200,9 +199,8 @@ func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *ma
setupLog.Error(err, "unable to set maintenance windows policy")
}
setupKymaReconciler(mgr, descriptorProvider, skrContextProvider, eventRecorder, flagVar, options, skrWebhookManager,
kymaMetrics, moduleMetrics, setupLog)
setupManifestReconciler(mgr, flagVar, options, sharedMetrics, mandatoryModulesMetrics, moduleMetrics, setupLog,
eventRecorder)
kymaMetrics, setupLog)
setupManifestReconciler(mgr, flagVar, options, sharedMetrics, mandatoryModulesMetrics, setupLog, eventRecorder)
setupMandatoryModuleReconciler(mgr, descriptorProvider, flagVar, options, mandatoryModulesMetrics, setupLog)
setupMandatoryModuleDeletionReconciler(mgr, descriptorProvider, eventRecorder, flagVar, options, setupLog)
if flagVar.EnablePurgeFinalizer {
Expand Down Expand Up @@ -279,8 +277,7 @@ func scheduleMetricsCleanup(kymaMetrics *metrics.KymaMetrics, cleanupIntervalInM

func setupKymaReconciler(mgr ctrl.Manager, descriptorProvider *provider.CachedDescriptorProvider,
skrContextFactory remote.SkrContextProvider, event event.Event, flagVar *flags.FlagVar, options ctrlruntime.Options,
skrWebhookManager *watcher.SKRWebhookManifestManager, kymaMetrics *metrics.KymaMetrics,
moduleMetrics *metrics.ModuleMetrics, setupLog logr.Logger,
skrWebhookManager *watcher.SKRWebhookManifestManager, kymaMetrics *metrics.KymaMetrics, setupLog logr.Logger,
) {
options.RateLimiter = internal.RateLimiter(flagVar.FailureBaseDelay,
flagVar.FailureMaxDelay, flagVar.RateLimiterFrequency, flagVar.RateLimiterBurst)
Expand All @@ -304,7 +301,6 @@ func setupKymaReconciler(mgr ctrl.Manager, descriptorProvider *provider.CachedDe
RemoteSyncNamespace: flagVar.RemoteSyncNamespace,
IsManagedKyma: flagVar.IsKymaManaged,
Metrics: kymaMetrics,
ModuleMetrics: moduleMetrics,
RemoteCatalog: remote.NewRemoteCatalogFromKyma(mgr.GetClient(), skrContextFactory,
flagVar.RemoteSyncNamespace),
}).SetupWithManager(
Expand Down Expand Up @@ -385,7 +381,7 @@ func setupPurgeReconciler(mgr ctrl.Manager,

func setupManifestReconciler(mgr ctrl.Manager, flagVar *flags.FlagVar, options ctrlruntime.Options,
sharedMetrics *metrics.SharedMetrics, mandatoryModulesMetrics *metrics.MandatoryModulesMetrics,
moduleMetrics *metrics.ModuleMetrics, setupLog logr.Logger, event event.Event,
setupLog logr.Logger, event event.Event,
) {
options.RateLimiter = internal.RateLimiter(flagVar.FailureBaseDelay,
flagVar.FailureMaxDelay, flagVar.RateLimiterFrequency, flagVar.RateLimiterBurst)
Expand All @@ -405,7 +401,7 @@ func setupManifestReconciler(mgr ctrl.Manager, flagVar *flags.FlagVar, options c
}, manifest.SetupOptions{
ListenerAddr: flagVar.ManifestListenerAddr,
EnableDomainNameVerification: flagVar.EnableDomainNameVerification,
}, metrics.NewManifestMetrics(sharedMetrics), mandatoryModulesMetrics, moduleMetrics,
}, metrics.NewManifestMetrics(sharedMetrics), mandatoryModulesMetrics,
manifestClient,
); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Manifest")
Expand Down
4 changes: 1 addition & 3 deletions internal/controller/kyma/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ type Reconciler struct {
RemoteSyncNamespace string
IsManagedKyma bool
Metrics *metrics.KymaMetrics
ModuleMetrics *metrics.ModuleMetrics
RemoteCatalog *remote.RemoteCatalog
}

Expand Down Expand Up @@ -446,7 +445,6 @@ func (r *Reconciler) handleDeletingState(ctx context.Context, kyma *v1beta2.Kyma

func (r *Reconciler) cleanupMetrics(kymaName string) {
r.Metrics.CleanupMetrics(kymaName)
r.ModuleMetrics.CleanupMetrics(kymaName)
}

func (r *Reconciler) cleanupManifestCRs(ctx context.Context, kyma *v1beta2.Kyma) error {
Expand Down Expand Up @@ -514,7 +512,7 @@ func (r *Reconciler) reconcileManifests(ctx context.Context, kyma *v1beta2.Kyma)
if err := runner.ReconcileManifests(ctx, kyma, modules); err != nil {
return fmt.Errorf("sync failed: %w", err)
}
runner.SyncModuleStatus(ctx, kyma, modules, r.Metrics, r.ModuleMetrics)
runner.SyncModuleStatus(ctx, kyma, modules, r.Metrics)
// If module get removed from kyma, the module deletion happens here.
if err := r.DeleteNoLongerExistingModules(ctx, kyma); err != nil {
return fmt.Errorf("error while syncing conditions during deleting non exists modules: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/manifest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func NewReconciler(mgr manager.Manager, requeueIntervals queue.RequeueIntervals,
manifestMetrics *metrics.ManifestMetrics, mandatoryModulesMetrics *metrics.MandatoryModulesMetrics,
moduleMetrics *metrics.ModuleMetrics, manifestClient declarativev2.ManifestAPIClient,
manifestClient declarativev2.ManifestAPIClient,
) *declarativev2.Reconciler {
kcp := &declarativev2.ClusterInfo{
Client: mgr.GetClient(),
Expand All @@ -29,7 +29,7 @@ func NewReconciler(mgr manager.Manager, requeueIntervals queue.RequeueIntervals,
statefulChecker := statecheck.NewStatefulSetStateCheck()
deploymentChecker := statecheck.NewDeploymentStateCheck()
return declarativev2.NewFromManager(
mgr, requeueIntervals, manifestMetrics, mandatoryModulesMetrics, moduleMetrics, manifestClient,
mgr, requeueIntervals, manifestMetrics, mandatoryModulesMetrics, manifestClient,
manifest.NewSpecResolver(keyChainLookup, extractor),
declarativev2.WithCustomStateCheck(statecheck.NewManagerStateCheck(statefulChecker, deploymentChecker)),
declarativev2.WithRemoteTargetCluster(lookup.ConfigResolver),
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/manifest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ type SetupOptions struct {

func SetupWithManager(mgr manager.Manager, opts ctrlruntime.Options, requeueIntervals queue.RequeueIntervals,
settings SetupOptions, manifestMetrics *metrics.ManifestMetrics,
mandatoryModulesMetrics *metrics.MandatoryModulesMetrics, moduleMetrics *metrics.ModuleMetrics,
manifestClient declarativev2.ManifestAPIClient,
mandatoryModulesMetrics *metrics.MandatoryModulesMetrics, manifestClient declarativev2.ManifestAPIClient,
) error {
var verifyFunc watcherevent.Verify
if settings.EnableDomainNameVerification {
Expand Down Expand Up @@ -83,7 +82,7 @@ func SetupWithManager(mgr manager.Manager, opts ctrlruntime.Options, requeueInte
predicate.LabelChangedPredicate{}))).
WatchesRawSource(skrEventChannel).
WithOptions(opts).
Complete(NewReconciler(mgr, requeueIntervals, manifestMetrics, mandatoryModulesMetrics, moduleMetrics,
Complete(NewReconciler(mgr, requeueIntervals, manifestMetrics, mandatoryModulesMetrics,
manifestClient)); err != nil {
return fmt.Errorf("failed to setup manager for manifest controller: %w", err)
}
Expand Down
41 changes: 3 additions & 38 deletions internal/declarative/v2/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ const (
)

func NewFromManager(mgr manager.Manager, requeueIntervals queue.RequeueIntervals, metrics *metrics.ManifestMetrics,
mandatoryModulesMetrics *metrics.MandatoryModulesMetrics, moduleMetrics *metrics.ModuleMetrics,
manifestAPIClient ManifestAPIClient, specResolver SpecResolver, options ...Option,
mandatoryModulesMetrics *metrics.MandatoryModulesMetrics, manifestAPIClient ManifestAPIClient,
specResolver SpecResolver, options ...Option,
) *Reconciler {
reconciler := &Reconciler{}
reconciler.ManifestMetrics = metrics
reconciler.MandatoryModuleMetrics = mandatoryModulesMetrics
reconciler.ModuleMetrics = moduleMetrics
reconciler.RequeueIntervals = requeueIntervals
reconciler.specResolver = specResolver
reconciler.manifestClient = manifestAPIClient
Expand All @@ -76,7 +75,6 @@ type Reconciler struct {
*Options
ManifestMetrics *metrics.ManifestMetrics
MandatoryModuleMetrics *metrics.MandatoryModulesMetrics
ModuleMetrics *metrics.ModuleMetrics
specResolver SpecResolver
manifestClient ManifestAPIClient
managedLabelRemovalService ManagedLabelRemoval
Expand Down Expand Up @@ -319,8 +317,7 @@ func (r *Reconciler) syncManifestState(ctx context.Context, skrClient Client, ma
) error {
manifestStatus := manifest.GetStatus()

moduleCRState, err := modulecr.NewClient(skrClient).SyncModuleCR(ctx, manifest)
if err != nil {
if err := modulecr.NewClient(skrClient).SyncModuleCR(ctx, manifest); err != nil {
manifest.SetStatus(manifestStatus.WithState(shared.StateError).WithErr(err))
return err
}
Expand All @@ -329,12 +326,6 @@ func (r *Reconciler) syncManifestState(ctx context.Context, skrClient Client, ma
return err
}
if !manifest.GetDeletionTimestamp().IsZero() {
if moduleCRState == shared.StateWarning {
if err := r.RecordModuleCRWarningCondition(manifest); err != nil {
return err
}
status.ConfirmModuleCRCondition(manifest)
}
if status.RequireManifestStateUpdateAfterSyncResource(manifest, shared.StateDeleting) {
return errStateRequireUpdate
}
Expand All @@ -352,32 +343,6 @@ func (r *Reconciler) syncManifestState(ctx context.Context, skrClient Client, ma
return nil
}

func (r *Reconciler) RecordModuleCRWarningCondition(manifest *v1beta2.Manifest) error {
kymaName, err := manifest.GetKymaName()
if err != nil {
return fmt.Errorf("failed to get kyma name: %w", err)
}
moduleName, err := manifest.GetModuleName()
if err != nil {
return fmt.Errorf("failed to get module name: %w", err)
}
r.ModuleMetrics.SetModuleCRWarningCondition(kymaName, moduleName)
return nil
}

func (r *Reconciler) RemoveModuleCRWarningCondition(manifest *v1beta2.Manifest) error {
kymaName, err := manifest.GetKymaName()
if err != nil {
return fmt.Errorf("failed to get kyma name: %w", err)
}
moduleName, err := manifest.GetModuleName()
if err != nil {
return fmt.Errorf("failed to get module name: %w", err)
}
r.ModuleMetrics.RemoveModuleCRWarningCondition(kymaName, moduleName)
return nil
}

func (r *Reconciler) checkManagerState(ctx context.Context, clnt Client, target []*resource.Info) (shared.State,
error,
) {
Expand Down
12 changes: 5 additions & 7 deletions internal/manifest/modulecr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func (c *Client) deleteCR(ctx context.Context, manifest *v1beta2.Manifest) (bool

// SyncModuleCR sync the manifest default custom resource status in the cluster, if not available it created the resource.
// It is used to provide the controller with default data in the Runtime.
func (c *Client) SyncModuleCR(ctx context.Context, manifest *v1beta2.Manifest) (shared.State, error) {
func (c *Client) SyncModuleCR(ctx context.Context, manifest *v1beta2.Manifest) error {
if manifest.Spec.Resource == nil {
return "", nil
return nil
}

resource := manifest.Spec.Resource.DeepCopy()
Expand All @@ -117,14 +117,12 @@ func (c *Client) SyncModuleCR(ctx context.Context, manifest *v1beta2.Manifest) (

if err := c.Get(ctx, client.ObjectKeyFromObject(resource), resource); err != nil && util.IsNotFound(err) {
if !manifest.GetDeletionTimestamp().IsZero() {
return "", nil
return nil
}
if err := c.Create(ctx, resource,
client.FieldOwner(finalizer.CustomResourceManagerFinalizer)); err != nil && !apierrors.IsAlreadyExists(err) {
return "", fmt.Errorf("failed to create resource: %w", err)
return fmt.Errorf("failed to create resource: %w", err)
}
}

stateFromCR, _, err := unstructured.NestedString(resource.Object, "status", "state")
return shared.State(stateFromCR), err
return nil
}
4 changes: 2 additions & 2 deletions internal/manifest/modulecr/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestClient_SyncModuleCR(t *testing.T) {
manifest.Spec.Resource = &moduleCR

// When syncing the module CR
_, err = skrClient.SyncModuleCR(ctx, manifest)
err = skrClient.SyncModuleCR(ctx, manifest)
require.NoError(t, err)

// Then the resource CR should be created
Expand All @@ -118,7 +118,7 @@ func TestClient_SyncModuleCR(t *testing.T) {
require.NoError(t, err)

// And syncing again, it should recreate the resource
_, err = skrClient.SyncModuleCR(ctx, manifest)
err = skrClient.SyncModuleCR(ctx, manifest)
require.NoError(t, err)

err = skrClient.Get(ctx, client.ObjectKey{Name: moduleName, Namespace: shared.DefaultRemoteNamespace}, resource)
Expand Down
21 changes: 0 additions & 21 deletions internal/manifest/status/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@ func initResourcesCondition(manifest *v1beta2.Manifest) apimetav1.Condition {
}
}

func initModuleCRCondition(manifest *v1beta2.Manifest) apimetav1.Condition {
return apimetav1.Condition{
Type: string(ConditionTypeModuleCR),
Reason: string(ConditionReasonModuleCRWarning),
Status: apimetav1.ConditionFalse,
Message: "Module CR is in Warning state",
ObservedGeneration: manifest.GetGeneration(),
}
}

func ConfirmModuleCRCondition(manifest *v1beta2.Manifest) {
status := manifest.GetStatus()
moduleCRCondition := initModuleCRCondition(manifest)

if !meta.IsStatusConditionTrue(status.Conditions, moduleCRCondition.Type) {
moduleCRCondition.Status = apimetav1.ConditionTrue
meta.SetStatusCondition(&status.Conditions, moduleCRCondition)
manifest.SetStatus(status.WithOperation(moduleCRCondition.Message))
}
}

func ConfirmResourcesCondition(manifest *v1beta2.Manifest) {
status := manifest.GetStatus()
resourceCondition := initResourcesCondition(manifest)
Expand Down
1 change: 0 additions & 1 deletion internal/manifest/status/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func Initialize(manifest *v1beta2.Manifest) error {
for _, condition := range []apimetav1.Condition{
initResourcesCondition(manifest),
initInstallationCondition(manifest),
initModuleCRCondition(manifest),
} {
if meta.FindStatusCondition(status.Conditions, condition.Type) == nil {
meta.SetStatusCondition(&status.Conditions, condition)
Expand Down
51 changes: 0 additions & 51 deletions internal/pkg/metrics/module.go

This file was deleted.

9 changes: 3 additions & 6 deletions pkg/module/sync/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,10 @@ func (r *Runner) setupModule(module *common.Module, kyma *v1beta2.Kyma) error {
}

func (r *Runner) SyncModuleStatus(ctx context.Context, kyma *v1beta2.Kyma, modules common.Modules,
kymaMetrics *metrics.KymaMetrics, moduleMetrics *metrics.ModuleMetrics,
kymaMetrics *metrics.KymaMetrics,
) {
updateModuleStatusFromExistingModules(kyma, modules)
DeleteNoLongerExistingModuleStatus(ctx, kyma, r.getModule, kymaMetrics.RemoveModuleStateMetrics,
moduleMetrics.RemoveModuleCRWarningCondition)
DeleteNoLongerExistingModuleStatus(ctx, kyma, r.getModule, kymaMetrics.RemoveModuleStateMetrics)
}

func updateModuleStatusFromExistingModules(
Expand Down Expand Up @@ -363,23 +362,21 @@ func stateFromManifest(obj client.Object) shared.State {
}

func DeleteNoLongerExistingModuleStatus(ctx context.Context, kyma *v1beta2.Kyma, moduleFunc GetModuleFunc,
kymaMetricsRemoveMetrics, moduleMetricsRemoveMetrics RemoveMetricsFunc,
kymaMetricsRemoveMetrics RemoveMetricsFunc,
) {
moduleStatusMap := kyma.GetModuleStatusMap()
moduleStatusesToBeDeletedFromKymaStatus := kyma.GetNoLongerExistingModuleStatus()
for idx := range moduleStatusesToBeDeletedFromKymaStatus {
moduleStatus := moduleStatusesToBeDeletedFromKymaStatus[idx]
if moduleStatus.Manifest == nil {
kymaMetricsRemoveMetrics(kyma.Name, moduleStatus.Name)
moduleMetricsRemoveMetrics(kyma.Name, moduleStatus.Name)
delete(moduleStatusMap, moduleStatus.Name)
continue
}
manifestCR := moduleStatus.GetManifestCR()
err := moduleFunc(ctx, manifestCR)
if util.IsNotFound(err) {
kymaMetricsRemoveMetrics(kyma.Name, moduleStatus.Name)
moduleMetricsRemoveMetrics(kyma.Name, moduleStatus.Name)
delete(moduleStatusMap, moduleStatus.Name)
} else {
moduleStatus.State = stateFromManifest(manifestCR)
Expand Down
Loading
Loading