Skip to content

Commit

Permalink
Add maintenance windows handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Jan 13, 2025
1 parent 63b2a8a commit 5c06a41
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY go.sum go.sum
# Copy the go source
COPY cmd cmd/
COPY api api/
COPY maintenancewindows maintenancewindows/
COPY internal internal/
COPY pkg pkg/
COPY skr-webhook skr-webhook/
Expand Down
16 changes: 12 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
_ "ocm.software/ocm/api/ocm"
//nolint:gci // kubebuilder's scaffold imports must be appended here.
"github.com/kyma-project/lifecycle-manager/internal/maintenancewindows"
)

const (
Expand Down Expand Up @@ -136,7 +137,8 @@ func pprofStartServer(addr string, timeout time.Duration, setupLog logr.Logger)
}
}

func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *machineryruntime.Scheme, setupLog logr.Logger) { //nolint: funlen // setupManager is a main function that sets up the manager
func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *machineryruntime.Scheme,
setupLog logr.Logger) { //nolint: funlen // setupManager is a main function that sets up the manager
config := ctrl.GetConfigOrDie()
config.QPS = float32(flagVar.ClientQPS)
config.Burst = flagVar.ClientBurst
Expand Down Expand Up @@ -185,9 +187,14 @@ func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *ma
kymaMetrics := metrics.NewKymaMetrics(sharedMetrics)
mandatoryModulesMetrics := metrics.NewMandatoryModulesMetrics()
moduleMetrics := metrics.NewModuleMetrics()

// TODO: The maintenance windows policy should be passed to the manifest reconciler to be resolved: https://github.com/kyma-project/lifecycle-manager/issues/2101
_, err = maintenancewindows.InitializeMaintenanceWindowsPolicy(setupLog)
if err != nil {
setupLog.Error(err, "unable to set maintenance windows policy")
}
setupKymaReconciler(mgr, descriptorProvider, skrContextProvider, eventRecorder, flagVar, options, skrWebhookManager,
kymaMetrics, moduleMetrics,
setupLog)
kymaMetrics, moduleMetrics, setupLog)
setupManifestReconciler(mgr, flagVar, options, sharedMetrics, mandatoryModulesMetrics, moduleMetrics, setupLog,
eventRecorder)
setupMandatoryModuleReconciler(mgr, descriptorProvider, flagVar, options, mandatoryModulesMetrics, setupLog)
Expand Down Expand Up @@ -292,7 +299,8 @@ func setupKymaReconciler(mgr ctrl.Manager, descriptorProvider *provider.CachedDe
IsManagedKyma: flagVar.IsKymaManaged,
Metrics: kymaMetrics,
ModuleMetrics: moduleMetrics,
RemoteCatalog: remote.NewRemoteCatalogFromKyma(mgr.GetClient(), skrContextFactory, flagVar.RemoteSyncNamespace),
RemoteCatalog: remote.NewRemoteCatalogFromKyma(mgr.GetClient(), skrContextFactory,
flagVar.RemoteSyncNamespace),
}).SetupWithManager(
mgr, options, kyma.SetupOptions{
ListenerAddr: flagVar.KymaListenerAddr,
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module github.com/kyma-project/lifecycle-manager

go 1.23.4

replace (
github.com/kyma-project/lifecycle-manager/api => ./api
github.com/kyma-project/lifecycle-manager/maintenancewindows => ./maintenancewindows
)
replace github.com/kyma-project/lifecycle-manager/api => ./api

replace github.com/kyma-project/lifecycle-manager/maintenancewindows => ./maintenancewindows

require (
github.com/Masterminds/semver/v3 v3.3.1
Expand Down
47 changes: 47 additions & 0 deletions internal/maintenancewindows/maintenance_policy_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package maintenancewindows

import (
"fmt"
"os"

"github.com/go-logr/logr"

"github.com/kyma-project/lifecycle-manager/maintenancewindows/resolver"
)

const (
policyName = "policy"
policiesDirectory = "/etc/maintenance-policy"
)

func InitializeMaintenanceWindowsPolicy(log logr.Logger) (*resolver.MaintenanceWindowPolicy, error) {
if err := os.Setenv(resolver.PolicyPathENV, policiesDirectory); err != nil {
return nil, fmt.Errorf("failed to set the policy path env variable, %w", err)
}

policyFilePath := fmt.Sprintf("%s/%s.json", policiesDirectory, policyName)
if !maintenancePolicyFileExists(policyFilePath) {
log.Info("maintenance windows policy file does not exist")
return nil, nil

Check failure on line 25 in internal/maintenancewindows/maintenance_policy_handler.go

View workflow job for this annotation

GitHub Actions / lint

return both the `nil` error and invalid value: use a sentinel error instead (nilnil)
}

maintenancePolicyPool, err := resolver.GetMaintenancePolicyPool()
if err != nil {
return nil, fmt.Errorf("failed to get maintenance policy pool, %w", err)
}

maintenancePolicy, err := resolver.GetMaintenancePolicy(maintenancePolicyPool, policyName)
if err != nil {
return nil, fmt.Errorf("failed to get maintenance window policy, %w", err)
}

return maintenancePolicy, nil
}

func maintenancePolicyFileExists(policyFilePath string) bool {
if _, err := os.Stat(policyFilePath); os.IsNotExist(err) {
return false
}

return true
}

0 comments on commit 5c06a41

Please sign in to comment.