Skip to content

Commit

Permalink
[RHCLOUD-20340] Config/Secret restarter (#776)
Browse files Browse the repository at this point in the history
* Secret/Config restarter
  • Loading branch information
psav authored Mar 3, 2023
1 parent 1c06352 commit 97d1820
Show file tree
Hide file tree
Showing 33 changed files with 1,294 additions and 49 deletions.
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ issues:
- goimports
exclude:
- "G108: Profiling endpoint is automatically"
linters:
enable:
- errcheck
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- revive
- staticcheck
- typecheck
- unused
- bodyclose
33 changes: 18 additions & 15 deletions controllers/cloud.redhat.com/clowdapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/hashcache"

// These imports are to register the providers with the provider registration system
_ "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/autoscaler"
Expand Down Expand Up @@ -120,9 +121,10 @@ func (rm *ReconciliationMetrics) stop() {
// ClowdAppReconciler reconciles a ClowdApp object
type ClowdAppReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
Recorder record.EventRecorder
Log logr.Logger
Scheme *runtime.Scheme
Recorder record.EventRecorder
HashCache *hashcache.HashCache
}

// Reconcile fn
Expand All @@ -139,13 +141,14 @@ func (r *ClowdAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
log.Info("Reconciliation started")

reconciliation := ClowdAppReconciliation{
ctx: ctx,
client: r.Client,
recorder: r.Recorder,
app: &app,
log: &log,
req: &req,
config: &config.AppConfig{},
ctx: ctx,
client: r.Client,
recorder: r.Recorder,
app: &app,
log: &log,
req: &req,
config: &config.AppConfig{},
hashCache: r.HashCache,
}
res, err := reconciliation.Reconcile()
if err != nil {
Expand All @@ -161,7 +164,7 @@ func (r *ClowdAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

// SetupWithManager sets up with Manager
func (r *ClowdAppReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *ClowdAppReconciler) SetupWithManager(mgr ctrl.Manager, hashCache *hashcache.HashCache) error {
r.Log.Info("Setting up manager")
utils.Log = r.Log.WithValues("name", "util")
r.Recorder = mgr.GetEventRecorderFor("app")
Expand All @@ -181,10 +184,10 @@ func (r *ClowdAppReconciler) SetupWithManager(mgr ctrl.Manager) error {
handler.EnqueueRequestsFromMapFunc(r.appsToEnqueueUponEnvUpdate),
builder.WithPredicates(environmentPredicate(r.Log, "app")),
)
ctrlr.Watches(&source.Kind{Type: &apps.Deployment{}}, createNewHandler(deploymentFilter, r.Log, "app", &crd.ClowdApp{}))
ctrlr.Watches(&source.Kind{Type: &core.Service{}}, createNewHandler(generationOnlyFilter, r.Log, "app", &crd.ClowdApp{}))
ctrlr.Watches(&source.Kind{Type: &core.ConfigMap{}}, createNewHandler(generationOnlyFilter, r.Log, "app", &crd.ClowdApp{}))
ctrlr.Watches(&source.Kind{Type: &core.Secret{}}, createNewHandler(alwaysFilter, r.Log, "app", &crd.ClowdApp{}))
ctrlr.Watches(&source.Kind{Type: &apps.Deployment{}}, createNewHandler(deploymentFilter, r.Log, "app", &crd.ClowdApp{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &core.Service{}}, createNewHandler(generationOnlyFilter, r.Log, "app", &crd.ClowdApp{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &core.ConfigMap{}}, createNewHandler(generationOnlyFilter, r.Log, "app", &crd.ClowdApp{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &core.Secret{}}, createNewHandler(alwaysFilter, r.Log, "app", &crd.ClowdApp{}, r.HashCache))
ctrlr.WithOptions(controller.Options{
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(time.Duration(500*time.Millisecond), time.Duration(60*time.Second)),
})
Expand Down
18 changes: 12 additions & 6 deletions controllers/cloud.redhat.com/clowdapp_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/hashcache"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers"
provutils "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/utils"
rc "github.com/RedHatInsights/rhc-osdk-utils/resourceCache"
Expand All @@ -35,6 +36,7 @@ type ClowdAppReconciliation struct {
reconciliationMetrics ReconciliationMetrics
config *config.AppConfig
oldStatus *crd.ClowdAppStatus
hashCache *hashcache.HashCache
}

func (r *ClowdAppReconciliation) steps() []func() (ctrl.Result, error) {
Expand Down Expand Up @@ -255,13 +257,17 @@ func (r *ClowdAppReconciliation) createCache() (ctrl.Result, error) {
}

func (r *ClowdAppReconciliation) runProviders() (ctrl.Result, error) {

r.hashCache.RemoveClowdObjectFromObjects(r.app)

provider := providers.Provider{
Client: r.client,
Ctx: r.ctx,
Env: r.env,
Cache: r.cache,
Log: *r.log,
Config: r.config,
Client: r.client,
Ctx: r.ctx,
Env: r.env,
Cache: r.cache,
Log: *r.log,
Config: r.config,
HashCache: r.hashCache,
}

if provErr := r.runProvidersImplementation(&provider); provErr != nil {
Expand Down
26 changes: 15 additions & 11 deletions controllers/cloud.redhat.com/clowdenvironment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

// Import the providers to initialize them
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/hashcache"

// These blank imports make the providers go wheeeeee
_ "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/confighash"
_ "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/cronjob"
_ "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/database"
Expand Down Expand Up @@ -82,9 +85,10 @@ const (
// ClowdEnvironmentReconciler reconciles a ClowdEnvironment object
type ClowdEnvironmentReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
Recorder record.EventRecorder
Log logr.Logger
Scheme *runtime.Scheme
Recorder record.EventRecorder
HashCache *hashcache.HashCache
}

// +kubebuilder:rbac:groups=cloud.redhat.com,resources=clowdenvironments,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -212,25 +216,25 @@ func runProvidersForEnvFinalize(log logr.Logger, provider providers.Provider) er
}

// SetupWithManager sets up with manager
func (r *ClowdEnvironmentReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *ClowdEnvironmentReconciler) SetupWithManager(mgr ctrl.Manager, hashCache *hashcache.HashCache) error {
r.Recorder = mgr.GetEventRecorderFor("env")

ctrlr := ctrl.NewControllerManagedBy(mgr).For(&crd.ClowdEnvironment{})

ctrlr.Watches(&source.Kind{Type: &apps.Deployment{}}, createNewHandler(deploymentFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &core.Service{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &core.Secret{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &apps.Deployment{}}, createNewHandler(deploymentFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &core.Service{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &core.Secret{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(
&source.Kind{Type: &crd.ClowdApp{}},
handler.EnqueueRequestsFromMapFunc(r.envToEnqueueUponAppUpdate),
builder.WithPredicates(predicate.GenerationChangedPredicate{}),
)

if clowderconfig.LoadedConfig.Features.WatchStrimziResources {
ctrlr.Watches(&source.Kind{Type: &strimzi.Kafka{}}, createNewHandler(kafkaFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaConnect{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaUser{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaTopic{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}))
ctrlr.Watches(&source.Kind{Type: &strimzi.Kafka{}}, createNewHandler(kafkaFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaConnect{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaUser{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
ctrlr.Watches(&source.Kind{Type: &strimzi.KafkaTopic{}}, createNewHandler(alwaysFilter, r.Log, "env", &crd.ClowdEnvironment{}, r.HashCache))
}

ctrlr.WithOptions(controller.Options{
Expand Down
7 changes: 6 additions & 1 deletion controllers/cloud.redhat.com/clowderconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ClowderConfig struct {
DebugOptions struct {
Logging struct {
DebugLogging bool `json:"debugLogging"`
}
} `json:"logging"`
Trigger struct {
Diff bool `json:"diff"`
} `json:"trigger"`
Expand Down Expand Up @@ -46,6 +46,7 @@ type ClowderConfig struct {
} `json:"features"`
Settings struct {
ManagedKafkaEphemDeleteRegex string `json:"managedKafkaEphemDeleteRegex"`
RestarterAnnotationName string `json:"restarterAnnotation"`
} `json:"settings"`
}

Expand Down Expand Up @@ -73,6 +74,10 @@ func getConfig() ClowderConfig {
return ClowderConfig{}
}

if clowderConfig.Settings.RestarterAnnotationName == "" {
clowderConfig.Settings.RestarterAnnotationName = "qontract.recycle"
}

return clowderConfig
}

Expand Down
4 changes: 4 additions & 0 deletions controllers/cloud.redhat.com/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
"BOPURL": {
"description": "Defines the path to the BOPURL.",
"type": "string"
},
"hashCache": {
"description": "A set of config/secret hashes",
"type": "string"
}
},
"required": [
Expand Down
3 changes: 3 additions & 0 deletions controllers/cloud.redhat.com/config/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97d1820

Please sign in to comment.