From f0f3baac9cb585f8fdda9d3fa0ba5106a4640ab5 Mon Sep 17 00:00:00 2001 From: Roi Vazquez Date: Mon, 4 Dec 2023 12:02:24 +0100 Subject: [PATCH] wip modify generators --- controllers/autossl_controller.go | 4 +- controllers/corsproxy_controller.go | 4 +- controllers/mappingservice_controller.go | 4 +- controllers/reconciler_config.go | 163 ++++++++++--- .../shardedredisbackup_controller_test.go | 21 +- controllers/system_controller.go | 4 +- controllers/twemproxyconfig_controller.go | 8 +- go.mod | 4 +- go.sum | 44 ++++ pkg/generators/apicast/deployment.go | 89 ++++--- pkg/generators/apicast/generator.go | 44 ++-- pkg/generators/apicast/services.go | 70 +++--- pkg/generators/autossl/deployment.go | 122 +++++----- pkg/generators/autossl/generator.go | 35 +-- pkg/generators/autossl/service.go | 32 +-- pkg/generators/backend/cron_deployment.go | 59 ++--- pkg/generators/backend/generator.go | 111 +++++---- pkg/generators/backend/listener_deployment.go | 103 ++++---- pkg/generators/backend/services.go | 79 +++--- pkg/generators/backend/worker_deployment.go | 78 +++--- pkg/generators/corsproxy/deployment.go | 78 +++--- pkg/generators/corsproxy/generator.go | 50 ++-- pkg/generators/corsproxy/service.go | 27 +-- pkg/generators/echoapi/deployment.go | 83 +++---- pkg/generators/echoapi/generator.go | 22 +- pkg/generators/echoapi/service.go | 42 ++-- pkg/generators/mappingservice/deployment.go | 80 +++--- pkg/generators/mappingservice/generator.go | 55 ++--- pkg/generators/mappingservice/service.go | 29 +-- pkg/generators/redisshard/configmaps.go | 44 ++-- pkg/generators/redisshard/generator.go | 30 +-- pkg/generators/redisshard/service.go | 31 +-- pkg/generators/redisshard/statefulset.go | 158 ++++++------ pkg/generators/sentinel/configmap.go | 32 ++- pkg/generators/sentinel/generator.go | 45 ++-- pkg/generators/sentinel/services.go | 87 +++---- pkg/generators/sentinel/statefulset.go | 229 +++++++++--------- pkg/generators/system/app_deployment.go | 154 ++++++------ pkg/generators/system/app_service.go | 29 +-- pkg/generators/system/console_statefulset.go | 122 +++++----- pkg/generators/system/generator.go | 133 ++++------ pkg/generators/system/searchd_service.go | 31 +-- pkg/generators/system/searchd_statefulset.go | 124 +++++----- pkg/generators/system/sidekiq_deployment.go | 162 ++++++------- pkg/generators/system/tekton_pipeline.go | 100 ++++---- pkg/generators/system/tekton_task.go | 150 ++++++------ pkg/generators/twemproxyconfig/configmap.go | 76 +++--- .../twemproxyconfig/configmap_test.go | 2 +- pkg/generators/twemproxyconfig/generator.go | 26 +- pkg/generators/zync/api_deployment.go | 118 +++++---- pkg/generators/zync/console_statefulset.go | 132 +++++----- pkg/generators/zync/generator.go | 89 +++---- pkg/generators/zync/que_deployment.go | 126 +++++----- pkg/generators/zync/services.go | 27 +-- .../workloads/deployment_based_workload.go | 55 +++-- .../deployment_based_workload_test.go | 182 +++++++++++++- .../workloads/test/test_controller.go | 7 +- .../grafanadashboard/resource.go | 4 - pkg/resource_builders/hpa/resource.go | 4 - pkg/resource_builders/pdb/resource.go | 4 - pkg/resource_builders/podmonitor/resource.go | 4 - test/util/assert.go | 2 +- 62 files changed, 2039 insertions(+), 2024 deletions(-) diff --git a/controllers/autossl_controller.go b/controllers/autossl_controller.go index 75f2d7ab..04d4e4b2 100644 --- a/controllers/autossl_controller.go +++ b/controllers/autossl_controller.go @@ -19,7 +19,7 @@ package controllers import ( "context" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/autossl" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" @@ -77,7 +77,7 @@ func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } // Shared resources - resources := []basereconciler.Resource{ + resources := []resource.TemplateInterface{ gen.GrafanaDashboard(), } diff --git a/controllers/corsproxy_controller.go b/controllers/corsproxy_controller.go index c996ef70..47ce8331 100644 --- a/controllers/corsproxy_controller.go +++ b/controllers/corsproxy_controller.go @@ -19,7 +19,7 @@ package controllers import ( "context" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/corsproxy" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" @@ -78,7 +78,7 @@ func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( instance.Spec, ) - resources := []basereconciler.Resource{ + resources := []resource.TemplateInterface{ gen.GrafanaDashboard(), gen.ExternalSecret(), } diff --git a/controllers/mappingservice_controller.go b/controllers/mappingservice_controller.go index f6933da4..2547bc3a 100644 --- a/controllers/mappingservice_controller.go +++ b/controllers/mappingservice_controller.go @@ -19,7 +19,7 @@ package controllers import ( "context" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/mappingservice" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" @@ -78,7 +78,7 @@ func (r *MappingServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque instance.Spec, ) - resources := []basereconciler.Resource{ + resources := []resource.TemplateInterface{ gen.GrafanaDashboard(), gen.ExternalSecret(), } diff --git a/controllers/reconciler_config.go b/controllers/reconciler_config.go index 2e68dc96..59d7ff5e 100644 --- a/controllers/reconciler_config.go +++ b/controllers/reconciler_config.go @@ -1,30 +1,139 @@ package controllers -// import ( -// basereconciler "github.com/3scale-ops/basereconciler/reconciler" -// marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" -// saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" -// externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" -// grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" -// monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" -// appsv1 "k8s.io/api/apps/v1" -// autoscalingv2 "k8s.io/api/autoscaling/v2" -// corev1 "k8s.io/api/core/v1" -// policyv1 "k8s.io/api/policy/v1" -// ) +import ( + "github.com/3scale-ops/basereconciler/config" + saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" + "k8s.io/apimachinery/pkg/runtime/schema" +) -// func init() { -// basereconciler.Config.AnnotationsDomain = saasv1alpha1.AnnotationsDomain -// basereconciler.Config.ResourcePruner = true -// basereconciler.Config.ManagedTypes = basereconciler.NewManagedTypes(). -// Register(&corev1.ServiceList{}). -// Register(&corev1.ConfigMapList{}). -// Register(&appsv1.DeploymentList{}). -// Register(&appsv1.StatefulSetList{}). -// Register(&externalsecretsv1beta1.ExternalSecretList{}). -// Register(&grafanav1alpha1.GrafanaDashboardList{}). -// Register(&autoscalingv2.HorizontalPodAutoscalerList{}). -// Register(&policyv1.PodDisruptionBudgetList{}). -// Register(&monitoringv1.PodMonitorList{}). -// Register(&marin3rv1alpha1.EnvoyConfigList{}) -// } +func init() { + config.SetAnnotationsDomain(saasv1alpha1.AnnotationsDomain) + config.EnableResourcePruner() + + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("v1", "Service"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.type", + "spec.ports", + "spec.selector", + "spec.clusterIP", + "spec.clusterIPs", + }, + // IgnoreProperties: []string{ + // "spec.externalTrafficPolicy", + // "spec.ipFamilies", + // "spec.ipFamilyPolicy", + // "spec.sessionAffinity", + // }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("v1", "ConfigMap"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "data", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("apps/v1", "Deployment"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.minReadySeconds", + "spec.replicas", + "spec.selector", + "spec.strategy", + "spec.template.metadata.labels", + "spec.template.metadata.annotations", + "spec.template.spec", + }, + IgnoreProperties: []string{ + "metadata.annotations['deployment.kubernetes.io/revision']", + "spec.template.spec.dnsPolicy", + "spec.template.spec.schedulerName", + "spec.template.spec.restartPolicy", + "spec.template.spec.securityContext", + // "spec.template.spec.terminationGracePeriodSeconds", + "spec.template.spec.containers[*].terminationMessagePath", + "spec.template.spec.containers[*].terminationMessagePolicy", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("apps/v1", "StatefulSet"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "spec.minReadySeconds", + "spec.persistentVolumeClaimRetentionPolicy", + "spec.replicas", + "spec.selector", + "spec.serviceName", + "spec.updateStrategy", + "spec.volumeClaimTemplates", + "spec.template.metadata.labels", + "spec.template.metadata.annotations", + "spec.template.spec", + }, + IgnoreProperties: []string{ + "metadata.annotations['deployment.kubernetes.io/revision']", + "spec.template.spec.dnsPolicy", + "spec.template.spec.schedulerName", + "spec.template.spec.restartPolicy", + "spec.template.spec.securityContext", + // "spec.template.spec.terminationGracePeriodSeconds", + "spec.template.spec.containers[*].terminationMessagePath", + "spec.template.spec.containers[*].terminationMessagePolicy", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("autoscaling/v2", "HorizontalPodAutoscaler"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.scaleTargetRef", + "spec.minReplicas", + "spec.maxReplicas", + "spec.metrics", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("policy/v1", "PodDisruptionBudget"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.maxUnavailable", + "spec.minAvailable", + "spec.selector", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("pipeline/v1beta1", "Pipeline"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.displayName", + "spec.description", + "spec.params", + "spec.tasks", + "spec.workspaces", + "spec.results", + "spec.finally", + }, + }) + config.SetDefaultReconcileConfigForGVK(schema.FromAPIVersionAndKind("pipeline/v1beta1", "Task"), config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec.displayName", + "spec.description", + "spec.params", + "spec.steps", + "spec.stepTemplate", + "spec.volumes", + "spec.sidecars", + "spec.workspaces", + "spec.results", + }, + }) + // default config for any GVK not explicitely declared in the config + config.SetDefaultReconcileConfigForGVK(schema.GroupVersionKind{}, config.ReconcileConfigForGVK{ + EnsureProperties: []string{ + "metadata.annotations", + "metadata.labels", + "spec", + }, + }) +} diff --git a/controllers/shardedredisbackup_controller_test.go b/controllers/shardedredisbackup_controller_test.go index 494e9a1d..9305927b 100644 --- a/controllers/shardedredisbackup_controller_test.go +++ b/controllers/shardedredisbackup_controller_test.go @@ -30,10 +30,6 @@ import ( ) func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { - type fields struct { - Reconciler basereconciler.Reconciler - Log logr.Logger - } type args struct { instance *saasv1alpha1.ShardedRedisBackup nextRun time.Time @@ -41,7 +37,6 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { } tests := []struct { name string - fields fields args args wantChanged bool wantStatus saasv1alpha1.ShardedRedisBackupStatus @@ -49,10 +44,6 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { }{ { name: "List is empty, adds a backup", - fields: fields{ - Reconciler: basereconciler.Reconciler{}, - Log: logr.Discard(), - }, args: args{ nextRun: util.MustParseRFC3339("2023-09-01T00:01:00Z"), instance: &saasv1alpha1.ShardedRedisBackup{ @@ -82,10 +73,6 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { }, { name: "No changes", - fields: fields{ - Reconciler: basereconciler.Reconciler{}, - Log: logr.Discard(), - }, args: args{ nextRun: util.MustParseRFC3339("2023-09-01T00:01:00Z"), instance: &saasv1alpha1.ShardedRedisBackup{ @@ -129,10 +116,6 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { }, { name: "Adds new backups", - fields: fields{ - Reconciler: basereconciler.Reconciler{}, - Log: logr.Discard(), - }, args: args{ nextRun: util.MustParseRFC3339("2023-09-01T00:02:00Z"), instance: &saasv1alpha1.ShardedRedisBackup{ @@ -178,8 +161,8 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &ShardedRedisBackupReconciler{ - Reconciler: tt.fields.Reconciler, - Log: tt.fields.Log, + Reconciler: basereconciler.Reconciler{}, + Log: logr.Discard(), } got, err := r.reconcileBackupList(context.TODO(), tt.args.instance, tt.args.nextRun, tt.args.shards) if (err != nil) != tt.wantErr { diff --git a/controllers/system_controller.go b/controllers/system_controller.go index 9ae529fd..f6eca48f 100644 --- a/controllers/system_controller.go +++ b/controllers/system_controller.go @@ -19,6 +19,7 @@ package controllers import ( "context" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/system" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" @@ -84,7 +85,8 @@ func (r *SystemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } // Shared resources - resources := append(gen.ExternalSecrets(), gen.GrafanaDashboard()) + resources := []resource.TemplateInterface{gen.GrafanaDashboard()} + resources = append(resources, gen.ExternalSecrets()...) // System APP app_resources, err := r.NewDeploymentWorkload(&gen.App, gen.CanaryApp) diff --git a/controllers/twemproxyconfig_controller.go b/controllers/twemproxyconfig_controller.go index 8c8fac58..7e2b487f 100644 --- a/controllers/twemproxyconfig_controller.go +++ b/controllers/twemproxyconfig_controller.go @@ -24,6 +24,7 @@ import ( "time" basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/twemproxyconfig" "github.com/3scale/saas-operator/pkg/reconcilers/threads" @@ -87,7 +88,7 @@ func (r *TwemproxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ return ctrl.Result{}, err } - cm, err := gen.ConfigMap().Build(ctx, r.Client) + cm, err := gen.ConfigMap().Build(ctx, r.Client, nil) if err != nil { return ctrl.Result{}, err } @@ -117,10 +118,7 @@ func (r *TwemproxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ } r.SentinelEvents.ReconcileThreads(ctx, instance, eventWatchers, logger.WithName("event-watcher")) - t := gen.GrafanaDashboard() - gd, _ := t.Build(ctx, r.Client) - controllerutil.SetControllerReference(instance, gd, r.Scheme) - if err := t.ResourceReconciler(ctx, r.Client, gd); err != nil { + if _, err := resource.CreateOrUpdate(ctx, r.Client, r.Scheme, instance, gen.GrafanaDashboard()); err != nil { return ctrl.Result{}, err } diff --git a/go.mod b/go.mod index d4e14ef4..03a28a73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/3scale/saas-operator go 1.20 require ( - github.com/3scale-ops/basereconciler v0.3.5 + github.com/3scale-ops/basereconciler v0.3.6-0.20231205162020-9e842177e981 github.com/3scale-ops/marin3r v0.12.2 github.com/MakeNowJust/heredoc v1.0.0 github.com/aws/aws-sdk-go-v2 v1.21.0 @@ -42,7 +42,7 @@ require ( sigs.k8s.io/yaml v1.3.0 ) -replace github.com/3scale-ops/basereconciler v0.3.5 => /home/roi/github.com/3scale/basereconciler +// replace github.com/3scale-ops/basereconciler v0.3.5 => /home/roi/github.com/3scale/basereconciler require ( contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect diff --git a/go.sum b/go.sum index bd8286e7..8d8d08bb 100644 --- a/go.sum +++ b/go.sum @@ -35,13 +35,33 @@ contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d/g contrib.go.opencensus.io/exporter/prometheus v0.4.0 h1:0QfIkj9z/iVZgK31D9H9ohjjIDApI2GOPScCKwxedbs= contrib.go.opencensus.io/exporter/prometheus v0.4.0/go.mod h1:o7cosnyfuPVK0tB8q0QmaQNhGnptITnPQB+z1+qeFB0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205114440-01c2078162ba h1:HpSF2uDUCwYfWNyY7D42rQr+KViVXczJEK4JTrzZhNk= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205114440-01c2078162ba/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205124004-0eac961fbd33 h1:s/gKWdklDeijGrBwHRBAi0VJ2vK//a4HS/EJWNoTUUM= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205124004-0eac961fbd33/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205125713-9d11df6ed422 h1:9Lf/8DN2XZFcdcnrGCUY8xhB/WBAdGUuAgXi23yyNY8= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205125713-9d11df6ed422/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205154103-b63eaafc8e3c h1:wUGCq7isLFTM6SjNsHUTq9CsFjBrNmCOZfKjiAF5yGM= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205154103-b63eaafc8e3c/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205155846-9e5092865af7 h1:OMV1sPAsEJstAGDwBoRhrh+urbQxkIqXtMuLqfGHdow= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205155846-9e5092865af7/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205160038-4b4aaa3daef3 h1:2803IruTbAY99oDoM2JaI3fSRfLYenlLwNlystxBstE= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205160038-4b4aaa3daef3/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205162020-9e842177e981 h1:ZnFnZOnYr2oQWsu8TP1LH+oCybuzCLdzT41b+uMJ14I= +github.com/3scale-ops/basereconciler v0.3.6-0.20231205162020-9e842177e981/go.mod h1:QuHsnYMbPQYKZjXjKX93efNI2VH2jVio4emJVJy7sRg= github.com/3scale-ops/marin3r v0.12.2 h1:sU4N7RZ5AQzfejrfP0KgpagmL/XD8a5NdSIv1qvaAnU= github.com/3scale-ops/marin3r v0.12.2/go.mod h1:BOU7EFv58PgPMgKgJFDd4ingfBhH6KC2AGJoD7i9SaU= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= +github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= +github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= +github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= @@ -100,6 +120,7 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE= github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= @@ -124,6 +145,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU= github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ= @@ -137,6 +160,7 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= @@ -164,6 +188,7 @@ github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl github.com/external-secrets/external-secrets v0.8.1 h1:LI7lYmR04Zi2gMVdgifTtyGKfBtYrCA380ePgds2gsY= github.com/external-secrets/external-secrets v0.8.1/go.mod h1:N5TxTxHLbCK2vVmcUAbUUorwuZiKxJqd/j8I65+44Zc= github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0= +github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= @@ -257,6 +282,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ= github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0= github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E= @@ -307,6 +333,9 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grafana-operator/grafana-operator/v4 v4.10.0 h1:+AVEPP/wflmx5ySdzt1mIw+q63ZYVInxQhF3XKNhJv4= github.com/grafana-operator/grafana-operator/v4 v4.10.0/go.mod h1:k69wJcXVrqAcZBoGuh5LSqz0ak8LlVOxxqp0W3f/4V8= +github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= @@ -321,12 +350,14 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -365,6 +396,7 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= @@ -386,8 +418,10 @@ github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1 h1:dOYG7LS/WK00RWZc8X github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/ohler55/ojg v1.20.3 h1:Z+fnElsA/GbI5oiT726qJaG4Ca9q5l7UO68Qd0PtkD4= github.com/ohler55/ojg v1.20.3/go.mod h1:uHcD1ErbErC27Zhb5Df2jUjbseLLcmOCo6oxSr3jZxo= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -407,6 +441,7 @@ github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3I github.com/openshift/api v0.0.0-20220715133027-dab5b363ebd1 h1:FzCXZdnkGLus4hHu7/d/utr3ELPiwNt2ffAqSspi6U8= github.com/openshift/api v0.0.0-20220715133027-dab5b363ebd1/go.mod h1:LEnw1IVscIxyDnltE3Wi7bQb/QzIM8BfPNKoGA1Qlxw= github.com/openshift/build-machinery-go v0.0.0-20211213093930-7e33a7eb4ce3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE= +github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -448,12 +483,15 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -474,15 +512,18 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/tektoncd/pipeline v0.49.0 h1:LxpgoPZvIDiOvPj6vtInnGG0uzuQ5CPA+h8FdJdklh4= github.com/tektoncd/pipeline v0.49.0/go.mod h1:R3Qn/oTTf1SCLrj+rCg4sqUbpx7vE+6D8Z81+zKUdqQ= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -542,6 +583,7 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= @@ -857,6 +899,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -875,6 +918,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/generators/apicast/deployment.go b/pkg/generators/apicast/deployment.go index 802010de..53fcdbdb 100644 --- a/pkg/generators/apicast/deployment.go +++ b/pkg/generators/apicast/deployment.go @@ -14,60 +14,53 @@ import ( // Deployment returns a function that will return a Deployment // resource when called -func (gen *EnvGenerator) deployment() func() *appsv1.Deployment { +func (gen *EnvGenerator) deployment() *appsv1.Deployment { - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "apicast", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("gateway", 8080), - pod.ContainerPortTCP("management", 8090), - pod.ContainerPortTCP("metrics", 9421), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - LivenessProbe: pod.TCPProbe(intstr.FromString("gateway"), *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("management"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "apicast", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("gateway", 8080), + pod.ContainerPortTCP("management", 8090), + pod.ContainerPortTCP("metrics", 9421), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + LivenessProbe: pod.TCPProbe(intstr.FromString("gateway"), *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("management"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - - if !gen.Spec.Marin3r.IsDeactivated() { - dep = marin3r.EnableSidecar(*dep, *gen.Spec.Marin3r) - } + }, + } - return dep + if !gen.Spec.Marin3r.IsDeactivated() { + dep = marin3r.EnableSidecar(*dep, *gen.Spec.Marin3r) } + + return dep } diff --git a/pkg/generators/apicast/generator.go b/pkg/generators/apicast/generator.go index 657b6ef7..05e67f27 100644 --- a/pkg/generators/apicast/generator.go +++ b/pkg/generators/apicast/generator.go @@ -4,8 +4,7 @@ import ( "fmt" mutators "github.com/3scale-ops/basereconciler/mutators" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - "github.com/3scale-ops/basereconciler/reconciler/resource" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/apicast/config" @@ -138,20 +137,20 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.ApicastSpec) (Ge } // Resources returns a list of basereconciler_v2.Resource -func (gen *Generator) Resources() []basereconciler.Resource { - return []basereconciler.Resource{ - resource.Template[*grafanav1alpha1.GrafanaDashboard]{ - Builder: grafanadashboard.New( +func (gen *Generator) Resources() []resource.TemplateInterface { + return []resource.TemplateInterface{ + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New( types.NamespacedName{Name: gen.Component, Namespace: gen.Namespace}, gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast.json.gtpl"), - IsEnabled: !gen.GrafanaDashboardSpec.IsDeactivated(), - }, - resource.Template[*grafanav1alpha1.GrafanaDashboard]{ - Builder: grafanadashboard.New( + !gen.GrafanaDashboardSpec.IsDeactivated(), + ), + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New( types.NamespacedName{Name: gen.Component + "-services", Namespace: gen.Namespace}, gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast-services.json.gtpl"), - IsEnabled: !gen.GrafanaDashboardSpec.IsDeactivated(), - }, + !gen.GrafanaDashboardSpec.IsDeactivated(), + ), } } @@ -176,14 +175,11 @@ var _ workloads.WithEnvoySidecar = &EnvGenerator{} func (gen *EnvGenerator) Labels() map[string]string { return gen.GetLabels() } -func (gen *EnvGenerator) Deployment() resource.Template[*appsv1.Deployment] { - return resource.Template[*appsv1.Deployment]{ - Builder: gen.deployment(), - IsEnabled: true, - MutatorFns: []resource.MutationFunction{ - mutators.ReconcileDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - }, - } +func (gen *EnvGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), + ) } func (gen *EnvGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -198,10 +194,10 @@ func (gen *EnvGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint podmonitor.PodMetricsEndpoint("/stats/prometheus", "envoy-metrics", 60), } } -func (gen *EnvGenerator) Services() []resource.Template[*corev1.Service] { - return []resource.Template[*corev1.Service]{ - {Builder: gen.gatewayService(), IsEnabled: true}, - {Builder: gen.mgmtService(), IsEnabled: true}, +func (gen *EnvGenerator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.gatewayService, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.mgmtService, true, mutators.SetServiceLiveValues()), } } func (gen *EnvGenerator) SendTraffic() bool { return gen.Traffic } diff --git a/pkg/generators/apicast/services.go b/pkg/generators/apicast/services.go index b8ab8a4c..e5a74393 100644 --- a/pkg/generators/apicast/services.go +++ b/pkg/generators/apicast/services.go @@ -9,52 +9,42 @@ import ( // GatewayService returns a function that will return the // gateway Service resource when called -func (gen *EnvGenerator) gatewayService() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Annotations: service.ELBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeCluster, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: func() []corev1.ServicePort { - if gen.Spec.Marin3r.IsDeactivated() { - return service.Ports( - service.TCPPort("http", 80, intstr.FromString("gateway")), - ) - } +func (gen *EnvGenerator) gatewayService() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Annotations: service.ELBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeLoadBalancer, + Ports: func() []corev1.ServicePort { + if gen.Spec.Marin3r.IsDeactivated() { return service.Ports( - service.TCPPort("gateway-http", 80, intstr.FromString("gateway-http")), - service.TCPPort("gateway-https", 443, intstr.FromString("gateway-https")), + service.TCPPort("http", 80, intstr.FromString("gateway")), ) - }(), - }, - } + } + return service.Ports( + service.TCPPort("gateway-http", 80, intstr.FromString("gateway-http")), + service.TCPPort("gateway-https", 443, intstr.FromString("gateway-https")), + ) + }(), + }, } } // MgmtService returns a function that will return the // management Service resource when called -func (gen *EnvGenerator) mgmtService() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent() + "-management", - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("management", 8090, intstr.FromString("management")), - ), - }, - } +func (gen *EnvGenerator) mgmtService() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent() + "-management", + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + SessionAffinity: corev1.ServiceAffinityNone, + Ports: service.Ports( + service.TCPPort("management", 8090, intstr.FromString("management")), + ), + }, } } diff --git a/pkg/generators/autossl/deployment.go b/pkg/generators/autossl/deployment.go index 8cb9d35c..8d0da6e2 100644 --- a/pkg/generators/autossl/deployment.go +++ b/pkg/generators/autossl/deployment.go @@ -12,80 +12,72 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for autossl -func (gen *Generator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - return &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *Generator) deployment() *appsv1.Deployment { + return &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Volumes: []corev1.Volume{ - { - Name: "autossl-cache", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Volumes: []corev1.Volume{ + { + Name: "autossl-cache", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, }, - { - Name: "nginx-cache", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, + }, + { + Name: "nginx-cache", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, }, }, - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "autossl", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 8081), - pod.ContainerPortTCP("https", 8444), - pod.ContainerPortTCP("http-no-pp", 8080), - pod.ContainerPortTCP("https-no-pp", 8443), - pod.ContainerPortTCP("metrics", 9145), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "autossl-cache", - MountPath: "/etc/resty-auto-ssl/", - }, - { - Name: "nginx-cache", - MountPath: "/var/lib/nginx", - }, + }, + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "autossl", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 8081), + pod.ContainerPortTCP("https", 8444), + pod.ContainerPortTCP("http-no-pp", 8080), + pod.ContainerPortTCP("https-no-pp", 8443), + pod.ContainerPortTCP("metrics", 9145), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "autossl-cache", + MountPath: "/etc/resty-auto-ssl/", + }, + { + Name: "nginx-cache", + MountPath: "/var/lib/nginx", }, - LivenessProbe: pod.HTTPProbe("/healthz", intstr.FromInt(9145), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/healthz", intstr.FromInt(9145), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, }, + LivenessProbe: pod.HTTPProbe("/healthz", intstr.FromInt(9145), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/healthz", intstr.FromInt(9145), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } + }, } } diff --git a/pkg/generators/autossl/generator.go b/pkg/generators/autossl/generator.go index 6e5ed3f8..462a206c 100644 --- a/pkg/generators/autossl/generator.go +++ b/pkg/generators/autossl/generator.go @@ -4,14 +4,18 @@ import ( "fmt" "strings" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/autossl/config" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" ) const ( @@ -79,9 +83,11 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.AutoSSLSpec) (Ge return generator, nil } -func (gen *Generator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *Generator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction( + gen.service, true, + mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -94,12 +100,11 @@ func (gen *Generator) TrafficSelector() map[string]string { // Validate that Generator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &Generator{} -func (gen *Generator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), + ) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -117,9 +122,9 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { } // GrafanaDashboard returns a basereconciler_resources.GrafanaDashboardTemplate -func (gen *Generator) GrafanaDashboard() basereconciler_resources.GrafanaDashboardTemplate { - return basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/autossl.json.gtpl"), - IsEnabled: !gen.Spec.GrafanaDashboard.IsDeactivated(), - } +func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { + return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/autossl.json.gtpl"), + !gen.Spec.GrafanaDashboard.IsDeactivated(), + ) } diff --git a/pkg/generators/autossl/service.go b/pkg/generators/autossl/service.go index b3930462..5abcdd70 100644 --- a/pkg/generators/autossl/service.go +++ b/pkg/generators/autossl/service.go @@ -8,24 +8,18 @@ import ( ) // service returns a function that will return the corev1.Service for autossl -func (gen *Generator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Annotations: service.ELBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeCluster, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("http", 80, intstr.FromString("http")), - service.TCPPort("https", 443, intstr.FromString("https")), - ), - }, - } +func (gen *Generator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Annotations: service.ELBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeLoadBalancer, + Ports: service.Ports( + service.TCPPort("http", 80, intstr.FromString("http")), + service.TCPPort("https", 443, intstr.FromString("https")), + ), + }, } } diff --git a/pkg/generators/backend/cron_deployment.go b/pkg/generators/backend/cron_deployment.go index 1cc73940..9c35cde7 100644 --- a/pkg/generators/backend/cron_deployment.go +++ b/pkg/generators/backend/cron_deployment.go @@ -13,44 +13,35 @@ import ( // Deployment returns a function that will return a Deployment // resource when called -func (gen *CronGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.CronSpec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *CronGenerator) deployment() *appsv1.Deployment { + return &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.CronSpec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, cron}, "-"), - Image: pod.Image(gen.Image), - Args: []string{"backend-cron"}, - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.CronSpec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, cron}, "-"), + Image: pod.Image(gen.Image), + Args: []string{"backend-cron"}, + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.CronSpec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.CronSpec.NodeAffinity), - Tolerations: gen.CronSpec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.CronSpec.NodeAffinity), + Tolerations: gen.CronSpec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - return dep + }, } } diff --git a/pkg/generators/backend/generator.go b/pkg/generators/backend/generator.go index dfa29832..aed33b6f 100644 --- a/pkg/generators/backend/generator.go +++ b/pkg/generators/backend/generator.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/backend/config" @@ -14,7 +14,11 @@ import ( "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pod" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -159,26 +163,32 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.BackendSpec) (Ge } // Resources returns functions to generate all Backend's shared resources -func (gen *Generator) Resources() []basereconciler.Resource { - return []basereconciler.Resource{ +func (gen *Generator) Resources() []resource.TemplateInterface { + return []resource.TemplateInterface{ // GrafanaDashboard - basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.grafanaDashboardSpec, "dashboards/backend.json.gtpl"), - IsEnabled: !gen.grafanaDashboardSpec.IsDeactivated(), - }, + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.grafanaDashboardSpec, "dashboards/backend.json.gtpl"), + !gen.grafanaDashboardSpec.IsDeactivated(), + ), // ExternalSecrets - basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("backend-system-events-hook", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Worker.Options), - IsEnabled: true, - }, - basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("backend-internal-api", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), - IsEnabled: true, - }, - basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("backend-error-monitoring", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), - IsEnabled: gen.config.ErrorMonitoringKey != nil, - }, + resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( + pod.GenerateExternalSecretFn("backend-system-events-hook", gen.GetNamespace(), + *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, + *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Worker.Options), + true, + ), + resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( + pod.GenerateExternalSecretFn("backend-internal-api", gen.GetNamespace(), + *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, + *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), + true, + ), + resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( + pod.GenerateExternalSecretFn("backend-error-monitoring", gen.GetNamespace(), + *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, + *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), + gen.config.ErrorMonitoringKey != nil, + ), } } @@ -205,18 +215,13 @@ var _ workloads.WithEnvoySidecar = &ListenerGenerator{} func (gen *ListenerGenerator) Labels() map[string]string { return gen.GetLabels() } -func (gen *ListenerGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: func() []basereconciler_resources.RolloutTrigger { - return []basereconciler_resources.RolloutTrigger{ - {Name: "backend-internal-api", SecretName: pointer.String("backend-internal-api")}, - {Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}, - } - }(), - EnforceReplicas: gen.ListenerSpec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *ListenerGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.ListenerSpec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "backend-internal-api", SecretName: pointer.String("backend-internal-api")}.Add(), + mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), + ) } func (gen *ListenerGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -235,10 +240,10 @@ func (gen *ListenerGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndp } return pmes } -func (gen *ListenerGenerator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, - {Template: gen.internalService(), IsEnabled: true}, +func (gen *ListenerGenerator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.internalService, true, mutators.SetServiceLiveValues()), } } func (gen *ListenerGenerator) SendTraffic() bool { return gen.Traffic } @@ -266,18 +271,13 @@ type WorkerGenerator struct { // Validate that WorkerGenerator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &WorkerGenerator{} -func (gen *WorkerGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: func() []basereconciler_resources.RolloutTrigger { - return []basereconciler_resources.RolloutTrigger{ - {Name: "backend-system-events-hook", SecretName: pointer.String("backend-system-events-hook")}, - {Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}, - } - }(), - EnforceReplicas: gen.WorkerSpec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *WorkerGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.WorkerSpec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "backend-system-events-hook", SecretName: pointer.String("backend-system-events-hook")}.Add(), + mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), + ) } func (gen *WorkerGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return gen.WorkerSpec.HPA @@ -307,15 +307,12 @@ type CronGenerator struct { // Validate that CronGenerator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &CronGenerator{} -func (gen *CronGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: []basereconciler_resources.RolloutTrigger{ - {Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}, - }, - EnforceReplicas: true, - IsEnabled: true, - } +func (gen *CronGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(true), + mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), + ) } func (gen *CronGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return &saasv1alpha1.HorizontalPodAutoscalerSpec{} diff --git a/pkg/generators/backend/listener_deployment.go b/pkg/generators/backend/listener_deployment.go index d508630d..37a59f1c 100644 --- a/pkg/generators/backend/listener_deployment.go +++ b/pkg/generators/backend/listener_deployment.go @@ -15,67 +15,60 @@ import ( // Deployment returns a function that will return a Deployment // resource when called -func (gen *ListenerGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.ListenerSpec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *ListenerGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.ListenerSpec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, listener}, "-"), - Image: pod.Image(gen.Image), - Args: func() (args []string) { - if *gen.ListenerSpec.Config.RedisAsync { - args = []string{"bin/3scale_backend", "-s", "falcon", "start"} - } else { - args = []string{"bin/3scale_backend", "start"} - } - args = append(args, "-e", "production", "-p", "3000", "-x", "/dev/stdout") - return - }(), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 3000), - pod.ContainerPortTCP("metrics", 9394), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.ListenerSpec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - LivenessProbe: pod.TCPProbe(intstr.FromString("http"), *gen.ListenerSpec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/status", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.ListenerSpec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, listener}, "-"), + Image: pod.Image(gen.Image), + Args: func() (args []string) { + if *gen.ListenerSpec.Config.RedisAsync { + args = []string{"bin/3scale_backend", "-s", "falcon", "start"} + } else { + args = []string{"bin/3scale_backend", "start"} + } + args = append(args, "-e", "production", "-p", "3000", "-x", "/dev/stdout") + return + }(), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 3000), + pod.ContainerPortTCP("metrics", 9394), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.ListenerSpec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, + LivenessProbe: pod.TCPProbe(intstr.FromString("http"), *gen.ListenerSpec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/status", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.ListenerSpec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.ListenerSpec.NodeAffinity), - Tolerations: gen.ListenerSpec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + RestartPolicy: corev1.RestartPolicyAlways, + Affinity: pod.Affinity(gen.GetSelector(), gen.ListenerSpec.NodeAffinity), + Tolerations: gen.ListenerSpec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - - if !gen.ListenerSpec.Marin3r.IsDeactivated() { - dep = marin3r.EnableSidecar(*dep, *gen.ListenerSpec.Marin3r) - } + }, + } - if gen.TwemproxySpec != nil { - dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) - } + if !gen.ListenerSpec.Marin3r.IsDeactivated() { + dep = marin3r.EnableSidecar(*dep, *gen.ListenerSpec.Marin3r) + } - return dep + if gen.TwemproxySpec != nil { + dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) } + + return dep } diff --git a/pkg/generators/backend/services.go b/pkg/generators/backend/services.go index 162f78e6..869c4930 100644 --- a/pkg/generators/backend/services.go +++ b/pkg/generators/backend/services.go @@ -9,59 +9,48 @@ import ( // service returns a function that will return the // public service resource when called -func (gen *ListenerGenerator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Annotations: service.NLBServiceAnnotations(*gen.ListenerSpec.LoadBalancer, gen.ListenerSpec.Endpoint.DNS), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeCluster, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: func() []corev1.ServicePort { - if gen.ListenerSpec.Marin3r.IsDeactivated() { - return service.Ports( - service.TCPPort("http", 80, intstr.FromString("http")), - ) - } +func (gen *ListenerGenerator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Annotations: service.NLBServiceAnnotations(*gen.ListenerSpec.LoadBalancer, gen.ListenerSpec.Endpoint.DNS), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeLoadBalancer, + Ports: func() []corev1.ServicePort { + if gen.ListenerSpec.Marin3r.IsDeactivated() { return service.Ports( - service.TCPPort("http", 80, intstr.FromString("backend-http")), - service.TCPPort("https", 443, intstr.FromString("backend-https")), + service.TCPPort("http", 80, intstr.FromString("http")), ) - }(), - }, - } + } + return service.Ports( + service.TCPPort("http", 80, intstr.FromString("backend-http")), + service.TCPPort("https", 443, intstr.FromString("backend-https")), + ) + }(), + }, } } // internalService returns a function that will return the // internal Service resource when called -func (gen *ListenerGenerator) internalService() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent() + "-internal", - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: func() []corev1.ServicePort { - if gen.ListenerSpec.Marin3r.IsDeactivated() { - return service.Ports( - service.TCPPort("http", 80, intstr.FromString("http")), - ) - } +func (gen *ListenerGenerator) internalService() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent() + "-internal", + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: func() []corev1.ServicePort { + if gen.ListenerSpec.Marin3r.IsDeactivated() { return service.Ports( - service.TCPPort("http", 80, intstr.FromString("http-internal")), + service.TCPPort("http", 80, intstr.FromString("http")), ) - }(), - }, - } + } + return service.Ports( + service.TCPPort("http", 80, intstr.FromString("http-internal")), + ) + }(), + }, } } diff --git a/pkg/generators/backend/worker_deployment.go b/pkg/generators/backend/worker_deployment.go index 264fc98a..b01fb2f6 100644 --- a/pkg/generators/backend/worker_deployment.go +++ b/pkg/generators/backend/worker_deployment.go @@ -14,54 +14,46 @@ import ( // Deployment returns a function that will return a Deployment // resource when called -func (gen *WorkerGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.WorkerSpec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *WorkerGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.WorkerSpec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, worker}, "-"), - Image: pod.Image(gen.Image), - Args: []string{"bin/3scale_backend_worker", "run"}, - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("metrics", 9421), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.WorkerSpec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.WorkerSpec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.WorkerSpec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: pod.ImagePullSecrets(gen.Image.PullSecretName), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, worker}, "-"), + Image: pod.Image(gen.Image), + Args: []string{"bin/3scale_backend_worker", "run"}, + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("metrics", 9421), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.WorkerSpec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, + LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.WorkerSpec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.WorkerSpec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.WorkerSpec.NodeAffinity), - Tolerations: gen.WorkerSpec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.WorkerSpec.NodeAffinity), + Tolerations: gen.WorkerSpec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - - if gen.TwemproxySpec != nil { - dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) - } + }, + } - return dep + if gen.TwemproxySpec != nil { + dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) } + + return dep } diff --git a/pkg/generators/corsproxy/deployment.go b/pkg/generators/corsproxy/deployment.go index 8ea26b1f..6457e5fd 100644 --- a/pkg/generators/corsproxy/deployment.go +++ b/pkg/generators/corsproxy/deployment.go @@ -12,53 +12,45 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for echo-api -func (gen *Generator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - return &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *Generator) deployment() *appsv1.Deployment { + return &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "cors-proxy", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 8080), - pod.ContainerPortTCP("metrics", 9145), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - LivenessProbe: pod.HTTPProbe("/healthz", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/healthz", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "cors-proxy", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 8080), + pod.ContainerPortTCP("metrics", 9145), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + LivenessProbe: pod.HTTPProbe("/healthz", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/healthz", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } + }, } } diff --git a/pkg/generators/corsproxy/generator.go b/pkg/generators/corsproxy/generator.go index 6e36dc71..16b228ac 100644 --- a/pkg/generators/corsproxy/generator.go +++ b/pkg/generators/corsproxy/generator.go @@ -3,7 +3,8 @@ package corsproxy import ( "fmt" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/corsproxy/config" @@ -11,7 +12,11 @@ import ( "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pod" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -51,9 +56,9 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.CORSProxySpec) G } } -func (gen *Generator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *Generator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -66,15 +71,12 @@ func (gen *Generator) TrafficSelector() map[string]string { // Validate that Generator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &Generator{} -func (gen *Generator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: []basereconciler_resources.RolloutTrigger{ - {Name: "cors-proxy-system-database", SecretName: pointer.String("cors-proxy-system-database")}, - }, - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "cors-proxy-system-database", SecretName: pointer.String("cors-proxy-system-database")}.Add(), + ) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -91,16 +93,18 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { } } -func (gen *Generator) GrafanaDashboard() basereconciler_resources.GrafanaDashboardTemplate { - return basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/cors-proxy.json.gtpl"), - IsEnabled: !gen.Spec.GrafanaDashboard.IsDeactivated(), - } +func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { + return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/cors-proxy.json.gtpl"), + !gen.Spec.GrafanaDashboard.IsDeactivated(), + ) } -func (gen *Generator) ExternalSecret() basereconciler_resources.ExternalSecretTemplate { - return basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("cors-proxy-system-database", gen.GetNamespace(), *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), - IsEnabled: true, - } +func (gen *Generator) ExternalSecret() *resource.Template[*externalsecretsv1beta1.ExternalSecret] { + return resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( + pod.GenerateExternalSecretFn("cors-proxy-system-database", gen.GetNamespace(), + *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, + *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), + true, + ) } diff --git a/pkg/generators/corsproxy/service.go b/pkg/generators/corsproxy/service.go index 70307a2c..f9c89367 100644 --- a/pkg/generators/corsproxy/service.go +++ b/pkg/generators/corsproxy/service.go @@ -8,21 +8,16 @@ import ( ) // service returns a function that will return the corev1.Service for echo-api -func (gen *Generator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("http", 80, intstr.FromString("http")), - ), - }, - } +func (gen *Generator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: service.Ports( + service.TCPPort("http", 80, intstr.FromString("http")), + ), + }, } } diff --git a/pkg/generators/echoapi/deployment.go b/pkg/generators/echoapi/deployment.go index bef3a6ab..dc9a57cf 100644 --- a/pkg/generators/echoapi/deployment.go +++ b/pkg/generators/echoapi/deployment.go @@ -13,57 +13,50 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for echo-api -func (gen *Generator) deployment() func() *appsv1.Deployment { +func (gen *Generator) deployment() *appsv1.Deployment { - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "echo-api", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 9292), - ), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - LivenessProbe: pod.TCPProbe(intstr.FromInt(9292), *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/", intstr.FromInt(9292), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "echo-api", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 9292), + ), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + LivenessProbe: pod.TCPProbe(intstr.FromInt(9292), *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/", intstr.FromInt(9292), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - - if !gen.Spec.Marin3r.IsDeactivated() { - dep = marin3r.EnableSidecar(*dep, *gen.Spec.Marin3r) - } + }, + } - return dep + if !gen.Spec.Marin3r.IsDeactivated() { + dep = marin3r.EnableSidecar(*dep, *gen.Spec.Marin3r) } + + return dep } diff --git a/pkg/generators/echoapi/generator.go b/pkg/generators/echoapi/generator.go index a03756f8..50a70e22 100644 --- a/pkg/generators/echoapi/generator.go +++ b/pkg/generators/echoapi/generator.go @@ -3,13 +3,16 @@ package echoapi import ( "fmt" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" descriptor "github.com/3scale/saas-operator/pkg/resource_builders/envoyconfig/descriptor" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" ) const ( @@ -49,9 +52,9 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.EchoAPISpec) Gen } } -func (gen *Generator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *Generator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -61,12 +64,11 @@ func (gen *Generator) TrafficSelector() map[string]string { } } -func (gen *Generator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), + ) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { diff --git a/pkg/generators/echoapi/service.go b/pkg/generators/echoapi/service.go index b69c9243..3152bd9d 100644 --- a/pkg/generators/echoapi/service.go +++ b/pkg/generators/echoapi/service.go @@ -8,31 +8,25 @@ import ( ) // service returns a function that will return the corev1.Service for echo-api -func (gen *Generator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Annotations: service.NLBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeLoadBalancer, - ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeCluster, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: func() []corev1.ServicePort { - if gen.Spec.Marin3r.IsDeactivated() { - return service.Ports( - service.TCPPort("http", 80, intstr.FromString("http")), - ) - } +func (gen *Generator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Annotations: service.NLBServiceAnnotations(*gen.Spec.LoadBalancer, gen.Spec.Endpoint.DNS), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeLoadBalancer, + Ports: func() []corev1.ServicePort { + if gen.Spec.Marin3r.IsDeactivated() { return service.Ports( - service.TCPPort("http", 80, intstr.FromString("echo-api-http")), - service.TCPPort("https", 443, intstr.FromString("echo-api-https")), + service.TCPPort("http", 80, intstr.FromString("http")), ) - }(), - }, - } + } + return service.Ports( + service.TCPPort("http", 80, intstr.FromString("echo-api-http")), + service.TCPPort("https", 443, intstr.FromString("echo-api-https")), + ) + }(), + }, } } diff --git a/pkg/generators/mappingservice/deployment.go b/pkg/generators/mappingservice/deployment.go index e6502b1b..4b9fa36b 100644 --- a/pkg/generators/mappingservice/deployment.go +++ b/pkg/generators/mappingservice/deployment.go @@ -12,54 +12,46 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for echo-api -func (gen *Generator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - return &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *Generator) deployment() *appsv1.Deployment { + return &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "mapping-service", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("mapping", 8093), - pod.ContainerPortTCP("management", 8090), - pod.ContainerPortTCP("metrics", 9421), - ), - Env: pod.BuildEnvironment(gen.Options), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - LivenessProbe: pod.TCPProbe(intstr.FromString("mapping"), *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("management"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "mapping-service", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("mapping", 8093), + pod.ContainerPortTCP("management", 8090), + pod.ContainerPortTCP("metrics", 9421), + ), + Env: pod.BuildEnvironment(gen.Options), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + LivenessProbe: pod.TCPProbe(intstr.FromString("mapping"), *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("management"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } + }, } } diff --git a/pkg/generators/mappingservice/generator.go b/pkg/generators/mappingservice/generator.go index 52e28dcc..15649c0f 100644 --- a/pkg/generators/mappingservice/generator.go +++ b/pkg/generators/mappingservice/generator.go @@ -3,7 +3,8 @@ package mappingservice import ( "fmt" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/mappingservice/config" @@ -11,8 +12,12 @@ import ( "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pod" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + "github.com/3scale/saas-operator/pkg/util" + externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - "k8s.io/utils/pointer" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" ) const ( @@ -51,9 +56,9 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.MappingServiceSp } } -func (gen *Generator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *Generator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -66,18 +71,12 @@ func (gen *Generator) TrafficSelector() map[string]string { // Validate that Generator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &Generator{} -func (gen *Generator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: []basereconciler_resources.RolloutTrigger{ - { - Name: "mapping-service-system-master-access-token", - SecretName: pointer.String("mapping-service-system-master-access-token"), - }, - }, - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "mapping-service-system-master-access-token", SecretName: util.Pointer("mapping-service-system-master-access-token")}.Add(), + ) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -94,16 +93,18 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { } } -func (gen *Generator) GrafanaDashboard() basereconciler_resources.GrafanaDashboardTemplate { - return basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/mapping-service.json.gtpl"), - IsEnabled: !gen.Spec.GrafanaDashboard.IsDeactivated(), - } +func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { + return resource.NewTemplate( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/mapping-service.json.gtpl"), + !gen.Spec.GrafanaDashboard.IsDeactivated(), + ) } -func (gen *Generator) ExternalSecret() basereconciler_resources.ExternalSecretTemplate { - return basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("mapping-service-system-master-access-token", gen.GetNamespace(), *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), - IsEnabled: true, - } +func (gen *Generator) ExternalSecret() *resource.Template[*externalsecretsv1beta1.ExternalSecret] { + return resource.NewTemplate( + pod.GenerateExternalSecretFn("mapping-service-system-master-access-token", gen.GetNamespace(), + *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, + *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), + true, + ) } diff --git a/pkg/generators/mappingservice/service.go b/pkg/generators/mappingservice/service.go index 4c41031f..79d0b425 100644 --- a/pkg/generators/mappingservice/service.go +++ b/pkg/generators/mappingservice/service.go @@ -8,22 +8,17 @@ import ( ) // service returns a function that will return the corev1.Service for echo-api -func (gen *Generator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("mapping", 80, intstr.FromString("mapping")), - service.TCPPort("management", 8090, intstr.FromString("management")), - ), - }, - } +func (gen *Generator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: service.Ports( + service.TCPPort("mapping", 80, intstr.FromString("mapping")), + service.TCPPort("management", 8090, intstr.FromString("management")), + ), + }, } } diff --git a/pkg/generators/redisshard/configmaps.go b/pkg/generators/redisshard/configmaps.go index ac770a81..4ced0af3 100644 --- a/pkg/generators/redisshard/configmaps.go +++ b/pkg/generators/redisshard/configmaps.go @@ -8,36 +8,33 @@ import ( // RedisConfigConfigMap returns a function that will return a ConfigMap // resource when called -func (gen *Generator) redisConfigConfigMap() func() *corev1.ConfigMap { - return func() *corev1.ConfigMap { - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: "redis-config-" + gen.GetInstanceName(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Data: map[string]string{ - "redis.conf": heredoc.Doc(` +func (gen *Generator) redisConfigConfigMap() *corev1.ConfigMap { + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "redis-config-" + gen.GetInstanceName(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Data: map[string]string{ + "redis.conf": heredoc.Doc(` slaveof 127.0.0.1 6379 tcp-keepalive 60 `), - }, - } + }, } } // RedisReadinessScriptConfigMap returns a function that will return a ConfigMap // resource when called -func (gen *Generator) redisReadinessScriptConfigMap() func() *corev1.ConfigMap { - return func() *corev1.ConfigMap { - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: "redis-readiness-script-" + gen.GetInstanceName(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Data: map[string]string{ - "ready.sh": heredoc.Doc(` +func (gen *Generator) redisReadinessScriptConfigMap() *corev1.ConfigMap { + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "redis-readiness-script-" + gen.GetInstanceName(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Data: map[string]string{ + "ready.sh": heredoc.Doc(` check_master(){ exit 0 @@ -66,7 +63,6 @@ func (gen *Generator) redisReadinessScriptConfigMap() func() *corev1.ConfigMap { exit 1 esac `), - }, - } + }, } } diff --git a/pkg/generators/redisshard/generator.go b/pkg/generators/redisshard/generator.go index a1ff2e90..957e2c3f 100644 --- a/pkg/generators/redisshard/generator.go +++ b/pkg/generators/redisshard/generator.go @@ -3,10 +3,11 @@ package redisshard import ( "fmt" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" ) const ( @@ -53,24 +54,11 @@ func (gen *Generator) ServiceName() string { } // Returns all the resource templates that this generator manages -func (gen *Generator) Resources() []basereconciler.Resource { - return []basereconciler.Resource{ - basereconciler_resources.StatefulSetTemplate{ - Template: gen.statefulSet(), - IsEnabled: true, - RolloutTriggers: nil, - }, - basereconciler_resources.ServiceTemplate{ - Template: gen.service(), - IsEnabled: true, - }, - basereconciler_resources.ConfigMapTemplate{ - Template: gen.redisConfigConfigMap(), - IsEnabled: true, - }, - basereconciler_resources.ConfigMapTemplate{ - Template: gen.redisReadinessScriptConfigMap(), - IsEnabled: true, - }, +func (gen *Generator) Resources() []resource.TemplateInterface { + return []resource.TemplateInterface{ + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet, true), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service, true), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisConfigConfigMap, true), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisReadinessScriptConfigMap, true), } } diff --git a/pkg/generators/redisshard/service.go b/pkg/generators/redisshard/service.go index 856eca59..62dc3ff1 100644 --- a/pkg/generators/redisshard/service.go +++ b/pkg/generators/redisshard/service.go @@ -7,23 +7,18 @@ import ( // Service returns a function that will return a Service // resource when called -func (gen *Generator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.ServiceName(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - ClusterIP: corev1.ClusterIPNone, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: []corev1.ServicePort{}, - Selector: gen.GetSelector(), - }, - } +func (gen *Generator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.ServiceName(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + ClusterIP: corev1.ClusterIPNone, + Ports: []corev1.ServicePort{}, + Selector: gen.GetSelector(), + }, } } diff --git a/pkg/generators/redisshard/statefulset.go b/pkg/generators/redisshard/statefulset.go index 92857562..24e9713a 100644 --- a/pkg/generators/redisshard/statefulset.go +++ b/pkg/generators/redisshard/statefulset.go @@ -14,93 +14,87 @@ import ( // StatefulSet returns a function that will return // a StatefulSet resource when called -func (gen *Generator) statefulSet() func() *appsv1.StatefulSet { - - return func() *appsv1.StatefulSet { - return &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-%s", gen.GetComponent(), gen.GetInstanceName()), - Namespace: gen.Namespace, - Labels: gen.GetLabels(), - }, - Spec: appsv1.StatefulSetSpec{ - PodManagementPolicy: appsv1.ParallelPodManagement, - Replicas: pointer.Int32(gen.Replicas), - RevisionHistoryLimit: pointer.Int32(1), - Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, - ServiceName: gen.ServiceName(), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: util.MergeMaps(gen.GetLabels(), gen.GetSelector()), - }, - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - RestartPolicy: corev1.RestartPolicyAlways, - Containers: []corev1.Container{ - { - Command: strings.Split(gen.Command, " "), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Name: "redis-server", - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("redis-server", 6379), - ), - ReadinessProbe: &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ - Command: strings.Split("/bin/sh /redis-readiness/ready.sh", " "), - }}, - FailureThreshold: 3, - InitialDelaySeconds: 10, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - }, - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - VolumeMounts: []corev1.VolumeMount{ - {Name: "redis-config", MountPath: "/redis"}, - {Name: "redis-readiness-script", MountPath: "/redis-readiness"}, - {Name: "redis-data", MountPath: "/data"}, - }, - }, - }, - SecurityContext: &corev1.PodSecurityContext{}, - TerminationGracePeriodSeconds: pointer.Int64(0), - Volumes: []corev1.Volume{ - { - Name: "redis-config", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), - LocalObjectReference: corev1.LocalObjectReference{Name: "redis-config-" + gen.GetInstanceName()}}, - }}, - { - Name: "redis-readiness-script", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(484), - LocalObjectReference: corev1.LocalObjectReference{Name: "redis-readiness-script-" + gen.GetInstanceName()}}, - }}, - { - Name: "redis-data", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{}, +func (gen *Generator) statefulSet() *appsv1.StatefulSet { + return &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-%s", gen.GetComponent(), gen.GetInstanceName()), + Namespace: gen.Namespace, + Labels: gen.GetLabels(), + }, + Spec: appsv1.StatefulSetSpec{ + PodManagementPolicy: appsv1.ParallelPodManagement, + Replicas: pointer.Int32(gen.Replicas), + RevisionHistoryLimit: pointer.Int32(1), + Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, + ServiceName: gen.ServiceName(), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: util.MergeMaps(gen.GetLabels(), gen.GetSelector()), + }, + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + RestartPolicy: corev1.RestartPolicyAlways, + Containers: []corev1.Container{ + { + Command: strings.Split(gen.Command, " "), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Name: "redis-server", + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("redis-server", 6379), + ), + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ + Command: strings.Split("/bin/sh /redis-readiness/ready.sh", " "), }}, + FailureThreshold: 3, + InitialDelaySeconds: 10, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + }, + ImagePullPolicy: *gen.Image.PullPolicy, + VolumeMounts: []corev1.VolumeMount{ + {Name: "redis-config", MountPath: "/redis"}, + {Name: "redis-readiness-script", MountPath: "/redis-readiness"}, + {Name: "redis-data", MountPath: "/data"}, + }, }, }, - }, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, - RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{ - Partition: pointer.Int32(0), + TerminationGracePeriodSeconds: pointer.Int64(0), + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + DefaultMode: pointer.Int32(420), + LocalObjectReference: corev1.LocalObjectReference{Name: "redis-config-" + gen.GetInstanceName()}}, + }}, + { + Name: "redis-readiness-script", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + DefaultMode: pointer.Int32(484), + LocalObjectReference: corev1.LocalObjectReference{Name: "redis-readiness-script-" + gen.GetInstanceName()}}, + }}, + { + Name: "redis-data", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }}, }, }, }, - } + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, + RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{ + Partition: pointer.Int32(0), + }, + }, + }, } } diff --git a/pkg/generators/sentinel/configmap.go b/pkg/generators/sentinel/configmap.go index 39bde8b0..73975a6c 100644 --- a/pkg/generators/sentinel/configmap.go +++ b/pkg/generators/sentinel/configmap.go @@ -8,22 +8,19 @@ import ( // configMap returns a function that will return a configMap // resource when called -func (gen *Generator) configMap() func() *corev1.ConfigMap { - - return func() *corev1.ConfigMap { - - return &corev1.ConfigMap{ - TypeMeta: metav1.TypeMeta{ - Kind: "ConfigMap", - APIVersion: corev1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent() + "-gen-config", - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Data: map[string]string{ - "generate-config.sh": heredoc.Doc(` +func (gen *Generator) configMap() *corev1.ConfigMap { + return &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + Kind: "ConfigMap", + APIVersion: corev1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent() + "-gen-config", + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Data: map[string]string{ + "generate-config.sh": heredoc.Doc(` if [ ! -f $1 ]; then echo "dir /redis" >> $1 echo "port 26379" >> $1 @@ -37,7 +34,6 @@ func (gen *Generator) configMap() func() *corev1.ConfigMap { sed -i "s/^sentinel announce-ip.*/sentinel announce-ip ${POD_IP}/g" $1 fi `), - }, - } + }, } } diff --git a/pkg/generators/sentinel/generator.go b/pkg/generators/sentinel/generator.go index 02d05aa1..d68648e7 100644 --- a/pkg/generators/sentinel/generator.go +++ b/pkg/generators/sentinel/generator.go @@ -7,14 +7,18 @@ import ( "net/url" "strings" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/sentinel/config" "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pdb" "github.com/3scale/saas-operator/pkg/util" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + policyv1 "k8s.io/api/policy/v1" ) const ( @@ -46,34 +50,23 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.SentinelSpec) Ge } // Returns all the resource templates that this generator manages -func (gen *Generator) Resources() []basereconciler.Resource { - resources := []basereconciler.Resource{ - basereconciler_resources.StatefulSetTemplate{ - Template: gen.statefulSet(), - RolloutTriggers: []basereconciler_resources.RolloutTrigger{}, - IsEnabled: true, - }, - basereconciler_resources.ServiceTemplate{ - Template: gen.statefulSetService(), - IsEnabled: true, - }, - basereconciler_resources.PodDisruptionBudgetTemplate{ - Template: pdb.New(gen.GetKey(), gen.GetLabels(), gen.GetSelector(), *gen.Spec.PDB), - IsEnabled: !gen.Spec.PDB.IsDeactivated(), - }, - basereconciler_resources.ConfigMapTemplate{ - Template: gen.configMap(), - IsEnabled: true, - }, - basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/redis-sentinel.json.gtpl"), - IsEnabled: !gen.Spec.GrafanaDashboard.IsDeactivated(), - }, +func (gen *Generator) Resources() []resource.TemplateInterface { + resources := []resource.TemplateInterface{ + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet, true), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.statefulSetService, true), + resource.NewTemplate[*policyv1.PodDisruptionBudget](pdb.New(gen.GetKey(), gen.GetLabels(), gen.GetSelector(), *gen.Spec.PDB), true), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.configMap, true), + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard](grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/redis-sentinel.json.gtpl"), + !gen.Spec.GrafanaDashboard.IsDeactivated()), } for idx := 0; idx < int(*gen.Spec.Replicas); idx++ { + i := idx resources = append(resources, - basereconciler_resources.ServiceTemplate{Template: gen.podServices(idx), IsEnabled: true}) + resource.NewTemplateFromObjectFunction( + func() *corev1.Service { return gen.podServices(i) }, true, + mutators.SetServiceLiveValues(), + )) } return resources diff --git a/pkg/generators/sentinel/services.go b/pkg/generators/sentinel/services.go index 53397995..686353b1 100644 --- a/pkg/generators/sentinel/services.go +++ b/pkg/generators/sentinel/services.go @@ -15,61 +15,52 @@ const ( // statefulSetService returns a function function that returns a Service // resource when called -func (gen *Generator) statefulSetService() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: corev1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent() + "-headless", - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - ClusterIP: corev1.ClusterIPNone, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: []corev1.ServicePort{}, - Selector: gen.GetSelector(), - }, - } +func (gen *Generator) statefulSetService() *corev1.Service { + return &corev1.Service{ + TypeMeta: metav1.TypeMeta{ + Kind: "Service", + APIVersion: corev1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent() + "-headless", + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + ClusterIP: corev1.ClusterIPNone, + Ports: []corev1.ServicePort{}, + Selector: gen.GetSelector(), + }, } } // podServices returns a function that returns a Service that points // ot a specific StatefulSet Pod when called // resource when called -func (gen *Generator) podServices(index int) func() *corev1.Service { - - return func() *corev1.Service { - return &corev1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: corev1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: gen.PodServiceName(index), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: []corev1.ServicePort{{ - Name: gen.GetComponent(), - Protocol: corev1.ProtocolTCP, - Port: int32(saasv1alpha1.SentinelPort), - TargetPort: intstr.FromString(gen.GetComponent()), - }}, - Selector: map[string]string{ - statefulsetPodSelectorLabelKey: fmt.Sprintf("%s-%d", gen.GetComponent(), index), - }, +func (gen *Generator) podServices(index int) *corev1.Service { + return &corev1.Service{ + TypeMeta: metav1.TypeMeta{ + Kind: "Service", + APIVersion: corev1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: gen.PodServiceName(index), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: []corev1.ServicePort{{ + Name: gen.GetComponent(), + Protocol: corev1.ProtocolTCP, + Port: int32(saasv1alpha1.SentinelPort), + TargetPort: intstr.FromString(gen.GetComponent()), + }}, + Selector: map[string]string{ + statefulsetPodSelectorLabelKey: fmt.Sprintf("%s-%d", gen.GetComponent(), index), }, - } + }, } } diff --git a/pkg/generators/sentinel/statefulset.go b/pkg/generators/sentinel/statefulset.go index 347e549f..275e2132 100644 --- a/pkg/generators/sentinel/statefulset.go +++ b/pkg/generators/sentinel/statefulset.go @@ -19,132 +19,125 @@ var ( // statefulSet returns a function that will return // a StatefulSet resource when called -func (gen *Generator) statefulSet() func() *appsv1.StatefulSet { - - return func() *appsv1.StatefulSet { - return &appsv1.StatefulSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "StatefulSet", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.Namespace, - Labels: gen.GetLabels(), - }, - Spec: appsv1.StatefulSetSpec{ - PodManagementPolicy: appsv1.ParallelPodManagement, - Replicas: gen.Spec.Replicas, - Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, - ServiceName: gen.GetComponent() + "-headless", - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: util.MergeMaps(gen.GetLabels(), gen.GetSelector()), - }, - Spec: corev1.PodSpec{ - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - AutomountServiceAccountToken: pointer.Bool(false), - DNSPolicy: corev1.DNSClusterFirst, - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Command: []string{"redis-server", "/redis/sentinel.conf", "--sentinel"}, - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - LivenessProbe: &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ - Command: strings.Split(healthCommand, " ")}}, - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - }, - Name: gen.GetComponent(), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP(gen.GetComponent(), int32(saasv1alpha1.SentinelPort)), - ), - ReadinessProbe: &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ - Command: strings.Split(healthCommand, " ")}}, - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - }, - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - VolumeMounts: []corev1.VolumeMount{ - {Name: gen.GetComponent() + "-config-rw", MountPath: "/redis"}, - }, +func (gen *Generator) statefulSet() *appsv1.StatefulSet { + return &appsv1.StatefulSet{ + TypeMeta: metav1.TypeMeta{ + Kind: "StatefulSet", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.Namespace, + Labels: gen.GetLabels(), + }, + Spec: appsv1.StatefulSetSpec{ + PodManagementPolicy: appsv1.ParallelPodManagement, + Replicas: gen.Spec.Replicas, + Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, + ServiceName: gen.GetComponent() + "-headless", + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: util.MergeMaps(gen.GetLabels(), gen.GetSelector()), + }, + Spec: corev1.PodSpec{ + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + AutomountServiceAccountToken: pointer.Bool(false), + DNSPolicy: corev1.DNSClusterFirst, + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Command: []string{"redis-server", "/redis/sentinel.conf", "--sentinel"}, + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ + Command: strings.Split(healthCommand, " ")}}, + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + }, + Name: gen.GetComponent(), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP(gen.GetComponent(), int32(saasv1alpha1.SentinelPort)), + ), + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{Exec: &corev1.ExecAction{ + Command: strings.Split(healthCommand, " ")}}, + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + }, + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + TerminationMessagePath: corev1.TerminationMessagePathDefault, + TerminationMessagePolicy: corev1.TerminationMessageReadFile, + VolumeMounts: []corev1.VolumeMount{ + {Name: gen.GetComponent() + "-config-rw", MountPath: "/redis"}, }, }, - InitContainers: []corev1.Container{ - { - Command: strings.Split("sh /redis-ro/generate-config.sh /redis/sentinel.conf", " "), - Env: []corev1.EnvVar{{ - Name: "POD_IP", - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "status.podIP", - APIVersion: corev1.SchemeGroupVersion.Version, - }, + }, + InitContainers: []corev1.Container{ + { + Command: strings.Split("sh /redis-ro/generate-config.sh /redis/sentinel.conf", " "), + Env: []corev1.EnvVar{{ + Name: "POD_IP", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "status.podIP", + APIVersion: corev1.SchemeGroupVersion.Version, }, - }}, - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - Name: gen.GetComponent() + "-gen-config", - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - VolumeMounts: []corev1.VolumeMount{ - {Name: gen.GetComponent() + "-gen-config", MountPath: "/redis-ro"}, - {Name: gen.GetComponent() + "-config-rw", MountPath: "/redis"}, }, + }}, + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, + Name: gen.GetComponent() + "-gen-config", + VolumeMounts: []corev1.VolumeMount{ + {Name: gen.GetComponent() + "-gen-config", MountPath: "/redis-ro"}, + {Name: gen.GetComponent() + "-config-rw", MountPath: "/redis"}, }, }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), - Volumes: []corev1.Volume{ - { - Name: gen.GetComponent() + "-gen-config", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(484), - LocalObjectReference: corev1.LocalObjectReference{Name: gen.GetComponent() + "-gen-config"}}, - }}, - }}, - }, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, - RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{ - Partition: pointer.Int32(0), }, + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), + Volumes: []corev1.Volume{ + { + Name: gen.GetComponent() + "-gen-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + DefaultMode: pointer.Int32(484), + LocalObjectReference: corev1.LocalObjectReference{Name: gen.GetComponent() + "-gen-config"}}, + }}, + }}, + }, + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, + RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{ + Partition: pointer.Int32(0), }, - VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent() + "-config-rw", - }, - Spec: corev1.PersistentVolumeClaimSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: *gen.Spec.Config.StorageSize}}, - StorageClassName: gen.Spec.Config.StorageClass, - VolumeMode: (*corev1.PersistentVolumeMode)(pointer.String(string(corev1.PersistentVolumeFilesystem))), - DataSource: &corev1.TypedLocalObjectReference{}, - }, - Status: corev1.PersistentVolumeClaimStatus{ - Phase: corev1.ClaimPending, - }, - }}, }, - } + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent() + "-config-rw", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, + Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: *gen.Spec.Config.StorageSize}}, + StorageClassName: gen.Spec.Config.StorageClass, + VolumeMode: (*corev1.PersistentVolumeMode)(pointer.String(string(corev1.PersistentVolumeFilesystem))), + DataSource: &corev1.TypedLocalObjectReference{}, + }, + Status: corev1.PersistentVolumeClaimStatus{ + Phase: corev1.ClaimPending, + }, + }}, + }, } } diff --git a/pkg/generators/system/app_deployment.go b/pkg/generators/system/app_deployment.go index 4b32f232..e592c411 100644 --- a/pkg/generators/system/app_deployment.go +++ b/pkg/generators/system/app_deployment.go @@ -14,98 +14,90 @@ import ( // Deployment returns a function that will return a Deployment // resource when called -func (gen *AppGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy(*gen.Spec.DeploymentStrategy), - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - InitContainers: []corev1.Container{ - { - Name: fmt.Sprintf("%s-k8s-deploy", gen.GetComponent()), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Args: []string{ - "bundle", "exec", "rake", "k8s:deploy", - }, - Env: pod.BuildEnvironment(gen.Options), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, +func (gen *AppGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy(*gen.Spec.DeploymentStrategy), + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + InitContainers: []corev1.Container{ + { + Name: fmt.Sprintf("%s-k8s-deploy", gen.GetComponent()), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Args: []string{ + "bundle", "exec", "rake", "k8s:deploy", }, + Env: pod.BuildEnvironment(gen.Options), + ImagePullPolicy: *gen.Image.PullPolicy, + TerminationMessagePath: corev1.TerminationMessagePathDefault, + TerminationMessagePolicy: corev1.TerminationMessageReadFile, }, - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, app}, "-"), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Args: []string{ - "env", - "PORT=3000", - "container-entrypoint", - "bundle", - "exec", - "unicorn", - "-c", - "config/unicorn.rb", - }, - Env: pod.BuildEnvironment(gen.Options), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("ui-api", 3000), - pod.ContainerPortTCP("metrics", 9394), - ), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - LivenessProbe: pod.TCPProbe(intstr.FromString("ui-api"), *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbeWithHeaders("/check.txt", intstr.FromString("ui-api"), - corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe, map[string]string{"X-Forwarded-Proto": "https"}), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, + }, + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, app}, "-"), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Args: []string{ + "env", + "PORT=3000", + "container-entrypoint", + "bundle", + "exec", + "unicorn", + "-c", + "config/unicorn.rb", }, + Env: pod.BuildEnvironment(gen.Options), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("ui-api", 3000), + pod.ContainerPortTCP("metrics", 9394), + ), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + LivenessProbe: pod.TCPProbe(intstr.FromString("ui-api"), *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbeWithHeaders("/check.txt", intstr.FromString("ui-api"), + corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe, map[string]string{"X-Forwarded-Proto": "https"}), + ImagePullPolicy: *gen.Image.PullPolicy, }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, }, - } + }, + } - dep.Spec.Template.Spec.Volumes = append( - dep.Spec.Template.Spec.Volumes, - corev1.Volume{ - Name: "system-config", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), - SecretName: gen.ConfigFilesSecret, - }, + dep.Spec.Template.Spec.Volumes = append( + dep.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: "system-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + DefaultMode: pointer.Int32(420), + SecretName: gen.ConfigFilesSecret, }, }, - ) + }, + ) - dep.Spec.Template.Spec.Containers[0].VolumeMounts = append( - dep.Spec.Template.Spec.Containers[0].VolumeMounts, - corev1.VolumeMount{ - Name: "system-config", - ReadOnly: true, - MountPath: "/opt/system-extra-configs", - }, - ) + dep.Spec.Template.Spec.Containers[0].VolumeMounts = append( + dep.Spec.Template.Spec.Containers[0].VolumeMounts, + corev1.VolumeMount{ + Name: "system-config", + ReadOnly: true, + MountPath: "/opt/system-extra-configs", + }, + ) - if gen.TwemproxySpec != nil { - dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) - } - return dep + if gen.TwemproxySpec != nil { + dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) } + return dep } diff --git a/pkg/generators/system/app_service.go b/pkg/generators/system/app_service.go index 8f25b3a7..0a3a3fae 100644 --- a/pkg/generators/system/app_service.go +++ b/pkg/generators/system/app_service.go @@ -8,22 +8,17 @@ import ( ) // service returns a function that will return the corev1.Service for system -func (gen *AppGenerator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.GetNamespace(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("http", 3000, intstr.FromString("ui-api")), - ), - }, - } +func (gen *AppGenerator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.GetNamespace(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: service.Ports( + service.TCPPort("http", 3000, intstr.FromString("ui-api")), + ), + }, } } diff --git a/pkg/generators/system/console_statefulset.go b/pkg/generators/system/console_statefulset.go index a7287760..fed3abf6 100644 --- a/pkg/generators/system/console_statefulset.go +++ b/pkg/generators/system/console_statefulset.go @@ -15,80 +15,72 @@ import ( // StatefulSet returns a basereconciler.GeneratorFunction function that will return // a StatefulSet resource when called -func (gen *ConsoleGenerator) statefulset() func() *appsv1.StatefulSet { - - return func() *appsv1.StatefulSet { - - sts := &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.Namespace, - Labels: gen.GetLabels(), +func (gen *ConsoleGenerator) statefulset() *appsv1.StatefulSet { + sts := &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.Namespace, + Labels: gen.GetLabels(), + }, + Spec: appsv1.StatefulSetSpec{ + Replicas: pointer.Int32(1), + Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, }, - Spec: appsv1.StatefulSetSpec{ - Replicas: pointer.Int32(1), - Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, + PodManagementPolicy: appsv1.ParallelPodManagement, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), }, - PodManagementPolicy: appsv1.ParallelPodManagement, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), - }, - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - RestartPolicy: "Always", - SecurityContext: &corev1.PodSecurityContext{}, - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, console}, "-"), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Args: []string{ - "sleep", - "infinity", - }, - Env: pod.BuildEnvironment(gen.Options), - Ports: nil, - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, console}, "-"), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Args: []string{ + "sleep", + "infinity", }, + Env: pod.BuildEnvironment(gen.Options), + Ports: nil, + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, }, - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } + }, + } - sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, - corev1.Volume{ - Name: "system-config", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), - SecretName: gen.ConfigFilesSecret, - }, + sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: "system-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + DefaultMode: pointer.Int32(420), + SecretName: gen.ConfigFilesSecret, }, - }) - sts.Spec.Template.Spec.Containers[0].VolumeMounts = append(sts.Spec.Template.Spec.Containers[0].VolumeMounts, - corev1.VolumeMount{ - Name: "system-config", - ReadOnly: true, - MountPath: "/opt/system-extra-configs", - }) - - if gen.TwemproxySpec != nil { - sts.Spec.Template = twemproxy.AddTwemproxySidecar(sts.Spec.Template, gen.TwemproxySpec) - } + }, + }) + sts.Spec.Template.Spec.Containers[0].VolumeMounts = append(sts.Spec.Template.Spec.Containers[0].VolumeMounts, + corev1.VolumeMount{ + Name: "system-config", + ReadOnly: true, + MountPath: "/opt/system-extra-configs", + }) - return sts + if gen.TwemproxySpec != nil { + sts.Spec.Template = twemproxy.AddTwemproxySidecar(sts.Spec.Template, gen.TwemproxySpec) } + + return sts } diff --git a/pkg/generators/system/generator.go b/pkg/generators/system/generator.go index adde6fcb..53ee024d 100644 --- a/pkg/generators/system/generator.go +++ b/pkg/generators/system/generator.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/generators/system/config" @@ -13,9 +13,13 @@ import ( "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pod" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + "github.com/3scale/saas-operator/pkg/util" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + res "k8s.io/apimachinery/pkg/api/resource" ) const ( @@ -309,13 +313,11 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.SystemSpec) (Gen } // GrafanaDashboard returns a basereconciler.GeneratorFunction -func (gen *Generator) GrafanaDashboard() basereconciler_resources.GrafanaDashboardTemplate { - return basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New( - gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/system.json.gtpl", - ), - IsEnabled: !gen.GrafanaDashboardSpec.IsDeactivated(), - } +func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { + return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/system.json.gtpl"), + !gen.GrafanaDashboardSpec.IsDeactivated(), + ) } func getSystemSecrets() []string { @@ -333,39 +335,34 @@ func getSystemSecrets() []string { } // Resources returns functions to generate all System's external secrets resources -func (gen *Generator) ExternalSecrets() []basereconciler.Resource { +func (gen *Generator) ExternalSecrets() []resource.TemplateInterface { - resources := []basereconciler.Resource{} + resources := []resource.TemplateInterface{} for _, es := range getSystemSecrets() { resources = append( resources, - basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn( - es, gen.GetNamespace(), *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options, - ), IsEnabled: true, - }, + resource.NewTemplate( + pod.GenerateExternalSecretFn(es, gen.GetNamespace(), + *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, + *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options, + ), + true, + ), ) } return resources } -func getSystemSecretsRolloutTriggers(additionalSecrets ...string) []basereconciler_resources.RolloutTrigger { - - triggers := []basereconciler_resources.RolloutTrigger{} - +func getSystemSecretsRolloutTriggers(additionalSecrets ...string) []resource.TemplateMutationFunction { + triggers := []resource.TemplateMutationFunction{} secrets := append(getSystemSecrets(), additionalSecrets...) - for _, secret := range secrets { triggers = append( triggers, - basereconciler_resources.RolloutTrigger{ - Name: secret, - SecretName: pointer.String(secret), - }, + mutators.RolloutTrigger{Name: secret, SecretName: util.Pointer(secret)}.Add(), ) } - return triggers } @@ -386,9 +383,9 @@ var _ workloads.DeploymentWorkload = &AppGenerator{} // Validate that AppGenerator implements workloads.WithTraffic interface var _ workloads.WithTraffic = &AppGenerator{} -func (gen *AppGenerator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *AppGenerator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), } } func (gen *AppGenerator) SendTraffic() bool { return gen.Traffic } @@ -398,13 +395,11 @@ func (gen *AppGenerator) TrafficSelector() map[string]string { } } -func (gen *AppGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *AppGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + append(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()))..., + ) } func (gen *AppGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -438,13 +433,11 @@ type SidekiqGenerator struct { TwemproxySpec *saasv1alpha1.TwemproxySpec } -func (gen *SidekiqGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), - EnforceReplicas: gen.Spec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *SidekiqGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + append(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()))..., + ) } func (gen *SidekiqGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -472,28 +465,15 @@ type SearchdGenerator struct { Image saasv1alpha1.ImageSpec DatabasePort int32 DatabasePath string - DatabaseStorageSize resource.Quantity + DatabaseStorageSize res.Quantity DatabaseStorageClass *string Enabled bool } -func (gen *SearchdGenerator) StatefulSetWithTraffic() []basereconciler.Resource { - return []basereconciler.Resource{ - gen.StatefulSet(), gen.Service(), - } -} - -func (gen *SearchdGenerator) StatefulSet() basereconciler_resources.StatefulSetTemplate { - return basereconciler_resources.StatefulSetTemplate{ - Template: gen.statefulset(), - IsEnabled: gen.Enabled, - } -} - -func (gen *SearchdGenerator) Service() basereconciler_resources.ServiceTemplate { - return basereconciler_resources.ServiceTemplate{ - Template: gen.service(), - IsEnabled: gen.Enabled, +func (gen *SearchdGenerator) StatefulSetWithTraffic() []resource.TemplateInterface { + return []resource.TemplateInterface{ + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulset, gen.Enabled), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service, gen.Enabled), } } @@ -508,12 +488,10 @@ type ConsoleGenerator struct { TwemproxySpec *saasv1alpha1.TwemproxySpec } -func (gen *ConsoleGenerator) StatefulSet() basereconciler_resources.StatefulSetTemplate { - return basereconciler_resources.StatefulSetTemplate{ - Template: gen.statefulset(), - RolloutTriggers: getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), - IsEnabled: gen.Enabled, - } +func (gen *ConsoleGenerator) StatefulSet() *resource.Template[*appsv1.StatefulSet] { + return resource.NewTemplateFromObjectFunction( + gen.statefulset, gen.Enabled, + getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret)...) } // SystemTektonGenerator has methods to generate resources for system tekton tasks @@ -528,22 +506,15 @@ type SystemTektonGenerator struct { } // Resources returns functions to generate all System's tekton pipeline resources -func (gen *Generator) Pipelines() []basereconciler.Resource { - - resources := []basereconciler.Resource{} +func (gen *Generator) Pipelines() []resource.TemplateInterface { + resources := []resource.TemplateInterface{} // Tekton resources for _, tr := range gen.Tekton { - tektonResource := tr + copy := tr resources = append(resources, - &basereconciler_resources.TaskTemplate{ - Template: tektonResource.task(), - IsEnabled: tektonResource.Enabled, - }, - &basereconciler_resources.PipelineTemplate{ - Template: tektonResource.pipeline(), - IsEnabled: tektonResource.Enabled, - }, + resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Task](copy.task, copy.Enabled), + resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Pipeline](copy.pipeline, copy.Enabled), ) } diff --git a/pkg/generators/system/searchd_service.go b/pkg/generators/system/searchd_service.go index e585674e..4ca7ae01 100644 --- a/pkg/generators/system/searchd_service.go +++ b/pkg/generators/system/searchd_service.go @@ -8,23 +8,18 @@ import ( ) // service returns a function that will return the corev1.Service for searchd -func (gen *SearchdGenerator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: *gen.Spec.Config.ServiceName, - Namespace: gen.GetNamespace(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("searchd", gen.DatabasePort, intstr.FromString("searchd")), - ), - Selector: gen.GetSelector(), - }, - } +func (gen *SearchdGenerator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: *gen.Spec.Config.ServiceName, + Namespace: gen.GetNamespace(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: service.Ports( + service.TCPPort("searchd", gen.DatabasePort, intstr.FromString("searchd")), + ), + Selector: gen.GetSelector(), + }, } } diff --git a/pkg/generators/system/searchd_statefulset.go b/pkg/generators/system/searchd_statefulset.go index bb8d1560..d8920ab2 100644 --- a/pkg/generators/system/searchd_statefulset.go +++ b/pkg/generators/system/searchd_statefulset.go @@ -15,77 +15,69 @@ import ( // StatefulSet returns a basereconciler.GeneratorFunction function that will return // a StatefulSet resource when called -func (gen *SearchdGenerator) statefulset() func() *appsv1.StatefulSet { - - return func() *appsv1.StatefulSet { - - return &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.Namespace, - Labels: gen.GetLabels(), +func (gen *SearchdGenerator) statefulset() *appsv1.StatefulSet { + return &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.Namespace, + Labels: gen.GetLabels(), + }, + Spec: appsv1.StatefulSetSpec{ + Replicas: pointer.Int32(1), + Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, }, - Spec: appsv1.StatefulSetSpec{ - Replicas: pointer.Int32(1), - Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, + PodManagementPolicy: appsv1.OrderedReadyPodManagement, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), }, - PodManagementPolicy: appsv1.OrderedReadyPodManagement, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), - }, - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, searchd}, "-"), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Args: []string{}, - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("searchd", gen.DatabasePort), - ), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - LivenessProbe: pod.TCPProbe(intstr.FromString("searchd"), *gen.Spec.LivenessProbe), - ReadinessProbe: pod.TCPProbe(intstr.FromString("searchd"), *gen.Spec.ReadinessProbe), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - VolumeMounts: []corev1.VolumeMount{{ - Name: "system-searchd-database", - MountPath: gen.DatabasePath, - }}, - }, + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, searchd}, "-"), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Args: []string{}, + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("searchd", gen.DatabasePort), + ), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + LivenessProbe: pod.TCPProbe(intstr.FromString("searchd"), *gen.Spec.LivenessProbe), + ReadinessProbe: pod.TCPProbe(intstr.FromString("searchd"), *gen.Spec.ReadinessProbe), + ImagePullPolicy: *gen.Image.PullPolicy, + VolumeMounts: []corev1.VolumeMount{{ + Name: "system-searchd-database", + MountPath: gen.DatabasePath, + }}, }, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, - VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "system-searchd-database", - }, - Status: corev1.PersistentVolumeClaimStatus{ - Phase: corev1.ClaimPending, - }, - Spec: corev1.PersistentVolumeClaimSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: gen.DatabaseStorageSize}}, - StorageClassName: gen.DatabaseStorageClass, - VolumeMode: (*corev1.PersistentVolumeMode)(pointer.String(string(corev1.PersistentVolumeFilesystem))), - DataSource: &corev1.TypedLocalObjectReference{}, - }, - }}, }, - } + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ + ObjectMeta: metav1.ObjectMeta{ + Name: "system-searchd-database", + }, + Status: corev1.PersistentVolumeClaimStatus{ + Phase: corev1.ClaimPending, + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, + Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: gen.DatabaseStorageSize}}, + StorageClassName: gen.DatabaseStorageClass, + VolumeMode: (*corev1.PersistentVolumeMode)(pointer.String(string(corev1.PersistentVolumeFilesystem))), + DataSource: &corev1.TypedLocalObjectReference{}, + }, + }}, + }, } } diff --git a/pkg/generators/system/sidekiq_deployment.go b/pkg/generators/system/sidekiq_deployment.go index 8f3c6c66..44668a5e 100644 --- a/pkg/generators/system/sidekiq_deployment.go +++ b/pkg/generators/system/sidekiq_deployment.go @@ -14,97 +14,89 @@ import ( // Deployment returns a basereconciler.GeneratorFunction function that will return a Deployment // resource when called -func (gen *SidekiqGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.Spec.Replicas, - Strategy: appsv1.DeploymentStrategy(*gen.Spec.DeploymentStrategy), - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: strings.Join([]string{component, sidekiq}, "-"), - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Args: func(queues []string) []string { - var args = []string{"sidekiq"} - for _, queue := range queues { - args = append(args, "--queue", queue) - } - return args - }(gen.Spec.Config.Queues), - Env: func() []corev1.EnvVar { - envVars := pod.BuildEnvironment(gen.Options) - envVars = append(envVars, - corev1.EnvVar{ - Name: "RAILS_MAX_THREADS", - Value: fmt.Sprintf("%d", *gen.Spec.Config.MaxThreads), - }, - ) - return envVars - }(), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("metrics", 9394), - ), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), - ImagePullPolicy: *gen.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - VolumeMounts: []corev1.VolumeMount{{ - Name: "system-tmp", - MountPath: "/tmp", - }}, - }, +func (gen *SidekiqGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.Spec.Replicas, + Strategy: appsv1.DeploymentStrategy(*gen.Spec.DeploymentStrategy), + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: strings.Join([]string{component, sidekiq}, "-"), + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Args: func(queues []string) []string { + var args = []string{"sidekiq"} + for _, queue := range queues { + args = append(args, "--queue", queue) + } + return args + }(gen.Spec.Config.Queues), + Env: func() []corev1.EnvVar { + envVars := pod.BuildEnvironment(gen.Options) + envVars = append(envVars, + corev1.EnvVar{ + Name: "RAILS_MAX_THREADS", + Value: fmt.Sprintf("%d", *gen.Spec.Config.MaxThreads), + }, + ) + return envVars + }(), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("metrics", 9394), + ), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.Spec.LivenessProbe), + ImagePullPolicy: *gen.Image.PullPolicy, + VolumeMounts: []corev1.VolumeMount{{ + Name: "system-tmp", + MountPath: "/tmp", + }}, }, - Volumes: []corev1.Volume{{ - Name: "system-tmp", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{ - Medium: corev1.StorageMediumMemory, - }, - }, - }}, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, + Volumes: []corev1.Volume{{ + Name: "system-tmp", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }}, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: gen.Spec.TerminationGracePeriodSeconds, }, }, - } + }, + } - dep.Spec.Template.Spec.Volumes = append(dep.Spec.Template.Spec.Volumes, - corev1.Volume{ - Name: "system-config", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), - SecretName: gen.ConfigFilesSecret, - }, + dep.Spec.Template.Spec.Volumes = append(dep.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: "system-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + DefaultMode: pointer.Int32(420), + SecretName: gen.ConfigFilesSecret, }, - }) - dep.Spec.Template.Spec.Containers[0].VolumeMounts = append(dep.Spec.Template.Spec.Containers[0].VolumeMounts, - corev1.VolumeMount{ - Name: "system-config", - ReadOnly: true, - MountPath: "/opt/system-extra-configs", - }) - - if gen.TwemproxySpec != nil { - dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) - } + }, + }) + dep.Spec.Template.Spec.Containers[0].VolumeMounts = append(dep.Spec.Template.Spec.Containers[0].VolumeMounts, + corev1.VolumeMount{ + Name: "system-config", + ReadOnly: true, + MountPath: "/opt/system-extra-configs", + }) - return dep + if gen.TwemproxySpec != nil { + dep.Spec.Template = twemproxy.AddTwemproxySidecar(dep.Spec.Template, gen.TwemproxySpec) } + + return dep } diff --git a/pkg/generators/system/tekton_pipeline.go b/pkg/generators/system/tekton_pipeline.go index 4043c582..28f2f6ef 100644 --- a/pkg/generators/system/tekton_pipeline.go +++ b/pkg/generators/system/tekton_pipeline.go @@ -9,66 +9,62 @@ import ( // pipeline returns a basereconciler.GeneratorFunction function that will return a // Tekton Pipeline resource for a Task when called -func (gen *SystemTektonGenerator) pipeline() func() *pipelinev1beta1.Pipeline { - - return func() *pipelinev1beta1.Pipeline { - - pipeline := &pipelinev1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Spec: pipelinev1beta1.PipelineSpec{ - DisplayName: gen.GetComponent(), - Description: *gen.Spec.Description, - Params: []pipelinev1beta1.ParamSpec{ - { - Name: "container-image", - Description: "Container image for the task", - Default: &pipelinev1beta1.ParamValue{ - StringVal: fmt.Sprint(*gen.Image.Name), - Type: pipelinev1beta1.ParamTypeString, - }, - Type: pipelinev1beta1.ParamTypeString, +func (gen *SystemTektonGenerator) pipeline() *pipelinev1beta1.Pipeline { + pipeline := &pipelinev1beta1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Spec: pipelinev1beta1.PipelineSpec{ + DisplayName: gen.GetComponent(), + Description: *gen.Spec.Description, + Params: []pipelinev1beta1.ParamSpec{ + { + Name: "container-image", + Description: "Container image for the task", + Default: &pipelinev1beta1.ParamValue{ + StringVal: fmt.Sprint(*gen.Image.Name), + Type: pipelinev1beta1.ParamTypeString, }, - { - Name: "container-tag", - Description: "Container tag for the task", - Default: &pipelinev1beta1.ParamValue{ - StringVal: fmt.Sprint(*gen.Image.Tag), - Type: pipelinev1beta1.ParamTypeString, - }, - Type: pipelinev1beta1.ParamTypeString, + Type: pipelinev1beta1.ParamTypeString, + }, + { + Name: "container-tag", + Description: "Container tag for the task", + Default: &pipelinev1beta1.ParamValue{ + StringVal: fmt.Sprint(*gen.Image.Tag), + Type: pipelinev1beta1.ParamTypeString, }, + Type: pipelinev1beta1.ParamTypeString, }, - Tasks: []pipelinev1beta1.PipelineTask{ - { - Name: *gen.Spec.Name, - Params: pipelinev1beta1.Params{ - pipelinev1beta1.Param{ - Name: "container-image", - Value: pipelinev1beta1.ParamValue{ - StringVal: "$(params.container-image)", - Type: pipelinev1beta1.ParamTypeString, - }, - }, - pipelinev1beta1.Param{ - Name: "container-tag", - Value: pipelinev1beta1.ParamValue{ - StringVal: "$(params.container-tag)", - Type: pipelinev1beta1.ParamTypeString, - }, + }, + Tasks: []pipelinev1beta1.PipelineTask{ + { + Name: *gen.Spec.Name, + Params: pipelinev1beta1.Params{ + pipelinev1beta1.Param{ + Name: "container-image", + Value: pipelinev1beta1.ParamValue{ + StringVal: "$(params.container-image)", + Type: pipelinev1beta1.ParamTypeString, }, }, - TaskRef: &pipelinev1beta1.TaskRef{ - Name: gen.GetComponent(), - Kind: pipelinev1beta1.NamespacedTaskKind, + pipelinev1beta1.Param{ + Name: "container-tag", + Value: pipelinev1beta1.ParamValue{ + StringVal: "$(params.container-tag)", + Type: pipelinev1beta1.ParamTypeString, + }, }, }, + TaskRef: &pipelinev1beta1.TaskRef{ + Name: gen.GetComponent(), + Kind: pipelinev1beta1.NamespacedTaskKind, + }, }, }, - } - return pipeline + }, } + return pipeline } diff --git a/pkg/generators/system/tekton_task.go b/pkg/generators/system/tekton_task.go index e2832b9a..bcd3202b 100644 --- a/pkg/generators/system/tekton_task.go +++ b/pkg/generators/system/tekton_task.go @@ -13,95 +13,91 @@ import ( // task returns a basereconciler.GeneratorFunction function that will return a // Tekton Task resource when called -func (gen *SystemTektonGenerator) task() func() *pipelinev1beta1.Task { - - return func() *pipelinev1beta1.Task { - - task := &pipelinev1beta1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Spec: pipelinev1beta1.TaskSpec{ - DisplayName: gen.GetComponent(), - Description: *gen.Spec.Description, - Params: []pipelinev1beta1.ParamSpec{ - { - Name: "container-image", - Description: "Container image for the task", - Default: &pipelinev1beta1.ParamValue{ - StringVal: fmt.Sprint(*gen.Image.Name), - Type: pipelinev1beta1.ParamTypeString, - }, - Type: pipelinev1beta1.ParamTypeString, +func (gen *SystemTektonGenerator) task() *pipelinev1beta1.Task { + task := &pipelinev1beta1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Spec: pipelinev1beta1.TaskSpec{ + DisplayName: gen.GetComponent(), + Description: *gen.Spec.Description, + Params: []pipelinev1beta1.ParamSpec{ + { + Name: "container-image", + Description: "Container image for the task", + Default: &pipelinev1beta1.ParamValue{ + StringVal: fmt.Sprint(*gen.Image.Name), + Type: pipelinev1beta1.ParamTypeString, }, - { - Name: "container-tag", - Description: "Container tag for the task", - Default: &pipelinev1beta1.ParamValue{ - StringVal: fmt.Sprint(*gen.Image.Tag), - Type: pipelinev1beta1.ParamTypeString, - }, - Type: pipelinev1beta1.ParamTypeString, + Type: pipelinev1beta1.ParamTypeString, + }, + { + Name: "container-tag", + Description: "Container tag for the task", + Default: &pipelinev1beta1.ParamValue{ + StringVal: fmt.Sprint(*gen.Image.Tag), + Type: pipelinev1beta1.ParamTypeString, }, + Type: pipelinev1beta1.ParamTypeString, }, - StepTemplate: &pipelinev1beta1.StepTemplate{ - Image: "$(params.container-image):$(params.container-tag)", - Env: func(base, extra []corev1.EnvVar) []corev1.EnvVar { - if len(extra) == 0 { - return base - } - envVars := base - for _, extraEnvVar := range extra { - found := false - for ev, envVar := range envVars { - if extraEnvVar.Name == envVar.Name { - found = true - envVars[ev].Value = extraEnvVar.Value - envVars[ev].ValueFrom = extraEnvVar.ValueFrom - } - } - if !found { - envVars = append(envVars, extraEnvVar) + }, + StepTemplate: &pipelinev1beta1.StepTemplate{ + Image: "$(params.container-image):$(params.container-tag)", + Env: func(base, extra []corev1.EnvVar) []corev1.EnvVar { + if len(extra) == 0 { + return base + } + envVars := base + for _, extraEnvVar := range extra { + found := false + for ev, envVar := range envVars { + if extraEnvVar.Name == envVar.Name { + found = true + envVars[ev].Value = extraEnvVar.Value + envVars[ev].ValueFrom = extraEnvVar.ValueFrom } } - return envVars - }(pod.BuildEnvironment(gen.Options), gen.Spec.Config.ExtraEnv), - }, - Steps: []pipelinev1beta1.Step{ - { - Name: "task-command", - Command: gen.Spec.Config.Command, - Args: gen.Spec.Config.Args, - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - VolumeMounts: []corev1.VolumeMount{ - { - Name: "system-config", - ReadOnly: true, - MountPath: "/opt/system-extra-configs", - }, + if !found { + envVars = append(envVars, extraEnvVar) + } + } + return envVars + }(pod.BuildEnvironment(gen.Options), gen.Spec.Config.ExtraEnv), + }, + Steps: []pipelinev1beta1.Step{ + { + Name: "task-command", + Command: gen.Spec.Config.Command, + Args: gen.Spec.Config.Args, + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + VolumeMounts: []corev1.VolumeMount{ + { + Name: "system-config", + ReadOnly: true, + MountPath: "/opt/system-extra-configs", }, }, }, - Volumes: []corev1.Volume{ - { - Name: "system-config", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), - SecretName: gen.ConfigFilesSecret, - }, + }, + Volumes: []corev1.Volume{ + { + Name: "system-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + DefaultMode: pointer.Int32(420), + SecretName: gen.ConfigFilesSecret, }, }, }, }, - } - - if gen.TwemproxySpec != nil { - task.Spec = twemproxy.AddTwemproxyTaskSidecar(task.Spec, gen.TwemproxySpec) - } + }, + } - return task + if gen.TwemproxySpec != nil { + task.Spec = twemproxy.AddTwemproxyTaskSidecar(task.Spec, gen.TwemproxySpec) } + + return task } diff --git a/pkg/generators/twemproxyconfig/configmap.go b/pkg/generators/twemproxyconfig/configmap.go index 8c3764f3..67b542dd 100644 --- a/pkg/generators/twemproxyconfig/configmap.go +++ b/pkg/generators/twemproxyconfig/configmap.go @@ -17,51 +17,47 @@ const ( // configMap returns a function that will return a ConfigMap // resource when called. This ConfigMap holds the twemproxy config file. -func (gen *Generator) configMap(toYAML bool) func() *corev1.ConfigMap { - - return func() *corev1.ConfigMap { - - config := make(map[string]twemproxy.ServerPoolConfig, len(gen.Spec.ServerPools)+1) - for _, pool := range gen.Spec.ServerPools { - if *pool.Target == saasv1alpha1.Masters { - config[pool.Name] = twemproxy.GenerateServerPool(pool, gen.masterTargets) - } else { - config[pool.Name] = twemproxy.GenerateServerPool(pool, gen.slaverwTargets) - } +func (gen *Generator) configMap(toYAML bool) *corev1.ConfigMap { + config := make(map[string]twemproxy.ServerPoolConfig, len(gen.Spec.ServerPools)+1) + for _, pool := range gen.Spec.ServerPools { + if *pool.Target == saasv1alpha1.Masters { + config[pool.Name] = twemproxy.GenerateServerPool(pool, gen.masterTargets) + } else { + config[pool.Name] = twemproxy.GenerateServerPool(pool, gen.slaverwTargets) } + } - config[HealthPoolName] = twemproxy.ServerPoolConfig{ - Listen: HealthBindAddress, - Redis: true, - Servers: []twemproxy.Server{{ - Address: "127.0.0.1:6379", - Priority: 1, - Name: "dummy", - }}, - } + config[HealthPoolName] = twemproxy.ServerPoolConfig{ + Listen: HealthBindAddress, + Redis: true, + Servers: []twemproxy.Server{{ + Address: "127.0.0.1:6379", + Priority: 1, + Name: "dummy", + }}, + } - var b []byte - var err error + var b []byte + var err error - if toYAML { - b, err = yaml.Marshal(config) + if toYAML { + b, err = yaml.Marshal(config) - } else { - b, err = json.Marshal(config) - } - if err != nil { - panic(err) - } + } else { + b, err = json.Marshal(config) + } + if err != nil { + panic(err) + } - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetInstanceName(), - Namespace: gen.GetNamespace(), - Labels: gen.GetLabels(), - }, - Data: map[string]string{ - "nutcracker.yml": string(b), - }, - } + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetInstanceName(), + Namespace: gen.GetNamespace(), + Labels: gen.GetLabels(), + }, + Data: map[string]string{ + "nutcracker.yml": string(b), + }, } } diff --git a/pkg/generators/twemproxyconfig/configmap_test.go b/pkg/generators/twemproxyconfig/configmap_test.go index 91b6ca51..226a1aa3 100644 --- a/pkg/generators/twemproxyconfig/configmap_test.go +++ b/pkg/generators/twemproxyconfig/configmap_test.go @@ -143,7 +143,7 @@ func TestGenerator_configMap(t *testing.T) { masterTargets: tt.fields.masterTargets, slaverwTargets: tt.fields.slaverwTargets, } - got := gen.configMap(tt.args.toYAML)() + got := gen.configMap(tt.args.toYAML) if diff := deep.Equal(got, tt.want); len(diff) > 0 { t.Errorf("Generator.configMap() = diff %v", diff) } diff --git a/pkg/generators/twemproxyconfig/generator.go b/pkg/generators/twemproxyconfig/generator.go index 2fba42ee..93603926 100644 --- a/pkg/generators/twemproxyconfig/generator.go +++ b/pkg/generators/twemproxyconfig/generator.go @@ -7,8 +7,7 @@ import ( "net/url" "strings" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" "github.com/3scale/saas-operator/pkg/redis/server" @@ -16,7 +15,9 @@ import ( "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/twemproxy" "github.com/go-logr/logr" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" "github.com/prometheus/client_golang/prometheus" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -215,19 +216,14 @@ func (gen *Generator) getMonitoredReadWriteSlavesWithFallbackToMasters(ctx conte } // Returns the twemproxy config ConfigMap -func (gen *Generator) ConfigMap() basereconciler.Resource { - return basereconciler_resources.ConfigMapTemplate{ - Template: gen.configMap(true), - IsEnabled: true, - } +func (gen *Generator) ConfigMap() *resource.Template[*corev1.ConfigMap] { + return resource.NewTemplateFromObjectFunction(func() *corev1.ConfigMap { return gen.configMap(true) }, true) } -func (gen *Generator) GrafanaDashboard() basereconciler_resources.GrafanaDashboardTemplate { - return basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(types.NamespacedName{ - Name: fmt.Sprintf("%s-%s", gen.InstanceName, gen.Component), - Namespace: gen.Namespace, - }, gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/twemproxy.json.gtpl"), - IsEnabled: !gen.Spec.GrafanaDashboard.IsDeactivated(), - } +func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { + return resource.NewTemplate( + grafanadashboard.New(types.NamespacedName{Name: fmt.Sprintf("%s-%s", gen.InstanceName, gen.Component), Namespace: gen.Namespace}, + gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/twemproxy.json.gtpl"), + !gen.Spec.GrafanaDashboard.IsDeactivated(), + ) } diff --git a/pkg/generators/zync/api_deployment.go b/pkg/generators/zync/api_deployment.go index 611fbe97..16207c0e 100644 --- a/pkg/generators/zync/api_deployment.go +++ b/pkg/generators/zync/api_deployment.go @@ -13,77 +13,69 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for zync -func (gen *APIGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.APISpec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *APIGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.APISpec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "zync", - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 8080), - pod.ContainerPortTCP("metrics", 9393), - ), - Env: func() []corev1.EnvVar { - envVars := pod.BuildEnvironment(gen.Options) - envVars = append(envVars, - corev1.EnvVar{ - Name: "POD_NAME", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.name", - APIVersion: "v1", - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "zync", + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 8080), + pod.ContainerPortTCP("metrics", 9393), + ), + Env: func() []corev1.EnvVar { + envVars := pod.BuildEnvironment(gen.Options) + envVars = append(envVars, + corev1.EnvVar{ + Name: "POD_NAME", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.name", + APIVersion: "v1", }, }, - corev1.EnvVar{ - Name: "POD_NAMESPACE", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - APIVersion: "v1", - }, + }, + corev1.EnvVar{ + Name: "POD_NAMESPACE", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + APIVersion: "v1", }, }, - ) - return envVars - }(), - Resources: corev1.ResourceRequirements(*gen.APISpec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - LivenessProbe: pod.HTTPProbe("/status/live", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.APISpec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.APISpec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + ) + return envVars + }(), + Resources: corev1.ResourceRequirements(*gen.APISpec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, + LivenessProbe: pod.HTTPProbe("/status/live", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.APISpec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("http"), corev1.URISchemeHTTP, *gen.APISpec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.APISpec.NodeAffinity), - Tolerations: gen.APISpec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.APISpec.NodeAffinity), + Tolerations: gen.APISpec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - return dep + }, } + return dep } diff --git a/pkg/generators/zync/console_statefulset.go b/pkg/generators/zync/console_statefulset.go index 7d25470c..4ab9d67b 100644 --- a/pkg/generators/zync/console_statefulset.go +++ b/pkg/generators/zync/console_statefulset.go @@ -14,85 +14,77 @@ import ( // StatefulSet returns a basereconciler.GeneratorFunction function that will return // a StatefulSet resource when called -func (gen *ConsoleGenerator) statefulset() func() *appsv1.StatefulSet { - - return func() *appsv1.StatefulSet { - - sts := &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - Namespace: gen.Namespace, - Labels: gen.GetLabels(), +func (gen *ConsoleGenerator) statefulset() *appsv1.StatefulSet { + sts := &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + Namespace: gen.Namespace, + Labels: gen.GetLabels(), + }, + Spec: appsv1.StatefulSetSpec{ + Replicas: pointer.Int32(1), + Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, }, - Spec: appsv1.StatefulSetSpec{ - Replicas: pointer.Int32(1), - Selector: &metav1.LabelSelector{MatchLabels: gen.GetSelector()}, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, + PodManagementPolicy: appsv1.ParallelPodManagement, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), }, - PodManagementPolicy: appsv1.ParallelPodManagement, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: util.MergeMaps(map[string]string{}, gen.GetLabels(), gen.GetSelector()), - }, - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Spec.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "zync", - Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), - Args: []string{ - "sleep", - "infinity", - }, - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("http", 8080), - pod.ContainerPortTCP("metrics", 9393), - ), - Env: func() []corev1.EnvVar { - envVars := pod.BuildEnvironment(gen.Options) - envVars = append(envVars, - corev1.EnvVar{ - Name: "POD_NAME", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.name", - APIVersion: "v1", - }, + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Spec.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "zync", + Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag), + Args: []string{ + "sleep", + "infinity", + }, + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("http", 8080), + pod.ContainerPortTCP("metrics", 9393), + ), + Env: func() []corev1.EnvVar { + envVars := pod.BuildEnvironment(gen.Options) + envVars = append(envVars, + corev1.EnvVar{ + Name: "POD_NAME", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.name", + APIVersion: "v1", }, }, - corev1.EnvVar{ - Name: "POD_NAMESPACE", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - APIVersion: "v1", - }, + }, + corev1.EnvVar{ + Name: "POD_NAMESPACE", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + APIVersion: "v1", }, }, - ) - return envVars - }(), - Resources: corev1.ResourceRequirements(*gen.Spec.Resources), - ImagePullPolicy: *gen.Spec.Image.PullPolicy, - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + ) + return envVars + }(), + Resources: corev1.ResourceRequirements(*gen.Spec.Resources), + ImagePullPolicy: *gen.Spec.Image.PullPolicy, }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), - Tolerations: gen.Spec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity), + Tolerations: gen.Spec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - return sts + }, } + return sts } diff --git a/pkg/generators/zync/generator.go b/pkg/generators/zync/generator.go index c22d4132..3c99838c 100644 --- a/pkg/generators/zync/generator.go +++ b/pkg/generators/zync/generator.go @@ -4,18 +4,21 @@ import ( "fmt" "strings" + "github.com/3scale-ops/basereconciler/mutators" + "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators" - - basereconciler "github.com/3scale-ops/basereconciler/reconciler" - basereconciler_resources "github.com/3scale-ops/basereconciler/resources" "github.com/3scale/saas-operator/pkg/generators/zync/config" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" "github.com/3scale/saas-operator/pkg/resource_builders/grafanadashboard" "github.com/3scale/saas-operator/pkg/resource_builders/pod" "github.com/3scale/saas-operator/pkg/resource_builders/podmonitor" + "github.com/3scale/saas-operator/pkg/util" + externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" + grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -100,18 +103,20 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.ZyncSpec) Genera } // Resources returns functions to generate all Zync's shared resources -func (gen *Generator) Resources() []basereconciler.Resource { - return []basereconciler.Resource{ +func (gen *Generator) Resources() []resource.TemplateInterface { + return []resource.TemplateInterface{ // GrafanaDashboard - basereconciler_resources.GrafanaDashboardTemplate{ - Template: grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/zync.json.gtpl"), - IsEnabled: !gen.GrafanaDashboardSpec.IsDeactivated(), - }, + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/zync.json.gtpl"), + !gen.GrafanaDashboardSpec.IsDeactivated(), + ), // ExternalSecret - basereconciler_resources.ExternalSecretTemplate{ - Template: pod.GenerateExternalSecretFn("zync", gen.GetNamespace(), *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.API.Options), - IsEnabled: true, - }, + resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( + pod.GenerateExternalSecretFn("zync", gen.GetNamespace(), + *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, + *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.API.Options), + true, + ), } } @@ -134,17 +139,12 @@ var _ workloads.WithTraffic = &APIGenerator{} func (gen *APIGenerator) Labels() map[string]string { return gen.GetLabels() } -func (gen *APIGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: func() []basereconciler_resources.RolloutTrigger { - return []basereconciler_resources.RolloutTrigger{ - {Name: "zync", SecretName: pointer.String("zync")}, - } - }(), - EnforceReplicas: gen.APISpec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *APIGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.APISpec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "zync", SecretName: util.Pointer("zync")}.Add(), + ) } func (gen *APIGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -158,9 +158,9 @@ func (gen *APIGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint podmonitor.PodMetricsEndpoint("/metrics", "metrics", 30), } } -func (gen *APIGenerator) Services() []basereconciler_resources.ServiceTemplate { - return []basereconciler_resources.ServiceTemplate{ - {Template: gen.service(), IsEnabled: true}, +func (gen *APIGenerator) Services() []*resource.Template[*corev1.Service] { + return []*resource.Template[*corev1.Service]{ + resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), } } func (gen *APIGenerator) SendTraffic() bool { return gen.Traffic } @@ -182,17 +182,12 @@ type QueGenerator struct { // Validate that QueGenerator implements workloads.DeploymentWorkload interface var _ workloads.DeploymentWorkload = &QueGenerator{} -func (gen *QueGenerator) Deployment() basereconciler_resources.DeploymentTemplate { - return basereconciler_resources.DeploymentTemplate{ - Template: gen.deployment(), - RolloutTriggers: func() []basereconciler_resources.RolloutTrigger { - return []basereconciler_resources.RolloutTrigger{ - {Name: "zync", SecretName: pointer.String("zync")}, - } - }(), - EnforceReplicas: gen.QueSpec.HPA.IsDeactivated(), - IsEnabled: true, - } +func (gen *QueGenerator) Deployment() *resource.Template[*appsv1.Deployment] { + return resource.NewTemplateFromObjectFunction( + gen.deployment, true, + mutators.SetDeploymentReplicas(gen.QueSpec.HPA.IsDeactivated()), + mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add(), + ) } func (gen *QueGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return gen.QueSpec.HPA @@ -215,14 +210,10 @@ type ConsoleGenerator struct { Enabled bool } -func (gen *ConsoleGenerator) StatefulSet() basereconciler_resources.StatefulSetTemplate { - return basereconciler_resources.StatefulSetTemplate{ - Template: gen.statefulset(), - RolloutTriggers: func() []basereconciler_resources.RolloutTrigger { - return []basereconciler_resources.RolloutTrigger{ - {Name: "zync", SecretName: pointer.String("zync")}, - } - }(), - IsEnabled: gen.Enabled, - } +func (gen *ConsoleGenerator) StatefulSet() *resource.Template[*appsv1.StatefulSet] { + return resource.NewTemplateFromObjectFunction( + gen.statefulset, gen.Enabled, + mutators.SetDeploymentReplicas(true), + mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add(), + ) } diff --git a/pkg/generators/zync/que_deployment.go b/pkg/generators/zync/que_deployment.go index a4dfa319..52a8611e 100644 --- a/pkg/generators/zync/que_deployment.go +++ b/pkg/generators/zync/que_deployment.go @@ -14,81 +14,73 @@ import ( ) // deployment returns a function that will return a *appsv1.Deployment for zync-que -func (gen *QueGenerator) deployment() func() *appsv1.Deployment { - - return func() *appsv1.Deployment { - - dep := &appsv1.Deployment{ - Spec: appsv1.DeploymentSpec{ - Replicas: gen.QueSpec.Replicas, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RollingUpdateDeploymentStrategyType, - RollingUpdate: &appsv1.RollingUpdateDeployment{ - MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), - MaxSurge: util.IntStrPtr(intstr.FromInt(1)), - }, +func (gen *QueGenerator) deployment() *appsv1.Deployment { + dep := &appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Replicas: gen.QueSpec.Replicas, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)), + MaxSurge: util.IntStrPtr(intstr.FromInt(1)), }, - Template: corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - ImagePullSecrets: func() []corev1.LocalObjectReference { - if gen.Image.PullSecretName != nil { - return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} - } - return nil - }(), - Containers: []corev1.Container{ - { - Name: "zync-que", - Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), - Command: []string{ - "/usr/bin/bash", - "-c", - "bundle exec rake 'que[--worker-count 10]'", - }, - Ports: pod.ContainerPorts( - pod.ContainerPortTCP("metrics", 9394), - ), - Env: func() []corev1.EnvVar { - envVars := pod.BuildEnvironment(gen.Options) - envVars = append(envVars, - corev1.EnvVar{ - Name: "POD_NAME", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.name", - APIVersion: "v1", - }, + }, + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + ImagePullSecrets: func() []corev1.LocalObjectReference { + if gen.Image.PullSecretName != nil { + return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}} + } + return nil + }(), + Containers: []corev1.Container{ + { + Name: "zync-que", + Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag), + Command: []string{ + "/usr/bin/bash", + "-c", + "bundle exec rake 'que[--worker-count 10]'", + }, + Ports: pod.ContainerPorts( + pod.ContainerPortTCP("metrics", 9394), + ), + Env: func() []corev1.EnvVar { + envVars := pod.BuildEnvironment(gen.Options) + envVars = append(envVars, + corev1.EnvVar{ + Name: "POD_NAME", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.name", + APIVersion: "v1", }, }, - corev1.EnvVar{ - Name: "POD_NAMESPACE", - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - APIVersion: "v1", - }, + }, + corev1.EnvVar{ + Name: "POD_NAMESPACE", + ValueFrom: &v1.EnvVarSource{ + FieldRef: &v1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + APIVersion: "v1", }, }, - ) - return envVars - }(), - Resources: corev1.ResourceRequirements(*gen.QueSpec.Resources), - ImagePullPolicy: *gen.Image.PullPolicy, - LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.QueSpec.LivenessProbe), - ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.QueSpec.ReadinessProbe), - TerminationMessagePath: corev1.TerminationMessagePathDefault, - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, + }, + ) + return envVars + }(), + Resources: corev1.ResourceRequirements(*gen.QueSpec.Resources), + ImagePullPolicy: *gen.Image.PullPolicy, + LivenessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.QueSpec.LivenessProbe), + ReadinessProbe: pod.HTTPProbe("/metrics", intstr.FromString("metrics"), corev1.URISchemeHTTP, *gen.QueSpec.ReadinessProbe), }, - RestartPolicy: corev1.RestartPolicyAlways, - SecurityContext: &corev1.PodSecurityContext{}, - Affinity: pod.Affinity(gen.GetSelector(), gen.QueSpec.NodeAffinity), - Tolerations: gen.QueSpec.Tolerations, - TerminationGracePeriodSeconds: pointer.Int64(30), }, + Affinity: pod.Affinity(gen.GetSelector(), gen.QueSpec.NodeAffinity), + Tolerations: gen.QueSpec.Tolerations, + TerminationGracePeriodSeconds: pointer.Int64(30), }, }, - } - return dep + }, } + return dep } diff --git a/pkg/generators/zync/services.go b/pkg/generators/zync/services.go index 5a03050a..bd44deef 100644 --- a/pkg/generators/zync/services.go +++ b/pkg/generators/zync/services.go @@ -9,21 +9,16 @@ import ( ) // service returns a function that will return the corev1.Service for zync -func (gen *APIGenerator) service() func() *corev1.Service { - - return func() *corev1.Service { - - return &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: gen.GetComponent(), - }, - Spec: corev1.ServiceSpec{ - Type: corev1.ServiceTypeClusterIP, - SessionAffinity: corev1.ServiceAffinityNone, - Ports: service.Ports( - service.TCPPort("http", 8080, intstr.FromString("http")), - ), - }, - } +func (gen *APIGenerator) service() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: gen.GetComponent(), + }, + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeClusterIP, + Ports: service.Ports( + service.TCPPort("http", 8080, intstr.FromString("http")), + ), + }, } } diff --git a/pkg/reconcilers/workloads/deployment_based_workload.go b/pkg/reconcilers/workloads/deployment_based_workload.go index ffcf451b..a499cabd 100644 --- a/pkg/reconcilers/workloads/deployment_based_workload.go +++ b/pkg/reconcilers/workloads/deployment_based_workload.go @@ -47,7 +47,9 @@ func (r *WorkloadReconciler) NewDeploymentWorkload( if _, ok := main.(WithTraffic); ok { for _, svct := range main.(WithTraffic).Services() { resources = append(resources, - svct.ChainTemplateBuilder(applyTrafficSelectorToService(main.(WithTraffic), toWithTraffic(canary)))) + svct.Apply(meta[*corev1.Service](main)). + Apply(trafficSelectorToService(main.(WithTraffic), toWithTraffic(canary))), + ) } } @@ -65,22 +67,24 @@ func workloadResources(workload DeploymentWorkload) []resource.TemplateInterface resources := []resource.TemplateInterface{ workload.Deployment(). - ChainTemplateBuilder(applyMeta[*appsv1.Deployment](workload)). - ChainTemplateBuilder(applySelectorToDeployment(workload)). - ChainTemplateBuilder(applyTrafficSelectorToDeployment(workload)), + Apply(meta[*appsv1.Deployment](workload)). + Apply(selector[*appsv1.Deployment](workload)). + Apply(trafficSelectorToDeployment(workload)), resource.NewTemplate[*policyv1.PodDisruptionBudget]( pdb.New(EmptyKey, EmptyLabel, EmptySelector, *workload.PDBSpec()), !workload.PDBSpec().IsDeactivated()). - ChainTemplateBuilder(applyMeta[*policyv1.PodDisruptionBudget](workload)), + Apply(meta[*policyv1.PodDisruptionBudget](workload)). + Apply(selector[*policyv1.PodDisruptionBudget](workload)), resource.NewTemplate[*autoscalingv2.HorizontalPodAutoscaler]( hpa.New(EmptyKey, EmptyLabel, *workload.HPASpec()), !workload.HPASpec().IsDeactivated()). - ChainTemplateBuilder(applyMeta[*autoscalingv2.HorizontalPodAutoscaler](workload)). - ChainTemplateBuilder(applyHPAScaleTargetRef(workload)), + Apply(meta[*autoscalingv2.HorizontalPodAutoscaler](workload)). + Apply(scaleTargetRefToHPA(workload)), resource.NewTemplate[*monitoringv1.PodMonitor]( podmonitor.New(EmptyKey, EmptyLabel, EmptySelector, workload.MonitoredEndpoints()...), len(workload.MonitoredEndpoints()) > 0). - ChainTemplateBuilder(applyMeta[*monitoringv1.PodMonitor](workload)), + Apply(meta[*monitoringv1.PodMonitor](workload)). + Apply(selector[*monitoringv1.PodMonitor](workload)), } // if workload implements WithEnvoySidecar add the EnvoyConfig @@ -88,15 +92,15 @@ func workloadResources(workload DeploymentWorkload) []resource.TemplateInterface resources = append(resources, resource.NewTemplate[*marin3rv1alpha1.EnvoyConfig]( envoyconfig.New(EmptyKey, EmptyKey.Name, factory.Default(), w.EnvoyDynamicConfigurations()...), len(w.EnvoyDynamicConfigurations()) > 0). - ChainTemplateBuilder(applyMeta[*marin3rv1alpha1.EnvoyConfig](w)). - ChainTemplateBuilder(applyNodeIdToEnvoyConfig(w)), + Apply(meta[*marin3rv1alpha1.EnvoyConfig](w)). + Apply(nodeIdToEnvoyConfig(w)), ) } return resources } -func applyMeta[T client.Object](w WithWorkloadMeta) resource.TemplateBuilderFunction[T] { +func meta[T client.Object](w WithWorkloadMeta) resource.TemplateBuilderFunction[T] { return func(o client.Object) (T, error) { switch o.(type) { @@ -114,7 +118,7 @@ func applyMeta[T client.Object](w WithWorkloadMeta) resource.TemplateBuilderFunc } } -func applyTrafficSelectorToService(main WithTraffic, canary WithTraffic) resource.TemplateBuilderFunction[*corev1.Service] { +func trafficSelectorToService(main WithTraffic, canary WithTraffic) resource.TemplateBuilderFunction[*corev1.Service] { return func(o client.Object) (*corev1.Service, error) { svc := o.(*corev1.Service) svc.Spec.Selector = trafficSwitcher(main, canary) @@ -154,7 +158,7 @@ func trafficSwitcher(main WithTraffic, canary WithTraffic) map[string]string { } } -func applyHPAScaleTargetRef(w WithWorkloadMeta) resource.TemplateBuilderFunction[*autoscalingv2.HorizontalPodAutoscaler] { +func scaleTargetRefToHPA(w WithWorkloadMeta) resource.TemplateBuilderFunction[*autoscalingv2.HorizontalPodAutoscaler] { return func(o client.Object) (*autoscalingv2.HorizontalPodAutoscaler, error) { hpa := o.(*autoscalingv2.HorizontalPodAutoscaler) hpa.Spec.ScaleTargetRef = autoscalingv2.CrossVersionObjectReference{ @@ -166,18 +170,23 @@ func applyHPAScaleTargetRef(w WithWorkloadMeta) resource.TemplateBuilderFunction } } -func applySelectorToDeployment(w DeploymentWorkload) resource.TemplateBuilderFunction[*appsv1.Deployment] { - return func(o client.Object) (*appsv1.Deployment, error) { - dep := o.(*appsv1.Deployment) - // Set the Pod selector - dep.Spec.Selector = &metav1.LabelSelector{MatchLabels: w.GetSelector()} - // Set the Pod labels - dep.Spec.Template.ObjectMeta.Labels = util.MergeMaps(map[string]string{}, dep.Spec.Template.ObjectMeta.Labels, w.GetLabels(), w.GetSelector()) - return dep, nil +func selector[T client.Object](w DeploymentWorkload) resource.TemplateBuilderFunction[T] { + return func(o client.Object) (T, error) { + + switch v := o.(type) { + case *appsv1.Deployment: + v.Spec.Selector = &metav1.LabelSelector{MatchLabels: w.GetSelector()} + v.Spec.Template.ObjectMeta.Labels = util.MergeMaps(map[string]string{}, v.Spec.Template.ObjectMeta.Labels, w.GetLabels(), w.GetSelector()) + case *policyv1.PodDisruptionBudget: + v.Spec.Selector = &metav1.LabelSelector{MatchLabels: w.GetSelector()} + case *monitoringv1.PodMonitor: + v.Spec.Selector = metav1.LabelSelector{MatchLabels: w.GetSelector()} + } + return o.(T), nil } } -func applyTrafficSelectorToDeployment(w DeploymentWorkload) resource.TemplateBuilderFunction[*appsv1.Deployment] { +func trafficSelectorToDeployment(w DeploymentWorkload) resource.TemplateBuilderFunction[*appsv1.Deployment] { return func(o client.Object) (*appsv1.Deployment, error) { dep := o.(*appsv1.Deployment) if w, ok := w.(WithTraffic); ok { @@ -187,7 +196,7 @@ func applyTrafficSelectorToDeployment(w DeploymentWorkload) resource.TemplateBui } } -func applyNodeIdToEnvoyConfig(w WithWorkloadMeta) resource.TemplateBuilderFunction[*marin3rv1alpha1.EnvoyConfig] { +func nodeIdToEnvoyConfig(w WithWorkloadMeta) resource.TemplateBuilderFunction[*marin3rv1alpha1.EnvoyConfig] { return func(o client.Object) (*marin3rv1alpha1.EnvoyConfig, error) { ec := o.(*marin3rv1alpha1.EnvoyConfig) ec.Spec.NodeID = w.GetKey().Name diff --git a/pkg/reconcilers/workloads/deployment_based_workload_test.go b/pkg/reconcilers/workloads/deployment_based_workload_test.go index c43c4048..14d908b8 100644 --- a/pkg/reconcilers/workloads/deployment_based_workload_test.go +++ b/pkg/reconcilers/workloads/deployment_based_workload_test.go @@ -6,8 +6,12 @@ import ( "testing" "github.com/3scale-ops/basereconciler/mutators" + basereconciler "github.com/3scale-ops/basereconciler/reconciler" "github.com/3scale-ops/basereconciler/resource" + reconcilerutil "github.com/3scale-ops/basereconciler/util" marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" + "github.com/3scale-ops/marin3r/pkg/envoy" + envoy_serializer "github.com/3scale-ops/marin3r/pkg/envoy/serializer" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" descriptor "github.com/3scale/saas-operator/pkg/resource_builders/envoyconfig/descriptor" "github.com/3scale/saas-operator/pkg/util" @@ -16,11 +20,14 @@ import ( appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" + policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" ) // TEST GENERATORS @@ -64,8 +71,8 @@ func (gen *TestWorkloadGenerator) Deployment() *resource.Template[*appsv1.Deploy mutators.RolloutTrigger{ Name: "secret", SecretName: pointer.String("secret"), - }.AddToDeployment(), - mutators.ReconcileDeploymentReplicas(true), + }.Add(), + mutators.SetDeploymentReplicas(true), }, IsEnabled: true, } @@ -120,6 +127,165 @@ func (gen *TestWorkloadGenerator) EnvoyDynamicConfigurations() []descriptor.Envo } // // TESTS START HERE + +func TestWorkloadReconciler_NewDeploymentWorkload(t *testing.T) { + type fields struct { + Client client.Client + Scheme *runtime.Scheme + } + type args struct { + main DeploymentWorkload + canary DeploymentWorkload + } + tests := []struct { + name string + fields fields + args args + want []client.Object + wantErr bool + }{ + { + name: "Generates the workload resources", + fields: fields{ + Client: fake.NewClientBuilder().Build(), + Scheme: func() *runtime.Scheme { + s := runtime.NewScheme() + monitoringv1.AddToScheme(s) + return s + }(), + }, + args: args{ + main: &TestWorkloadGenerator{ + TName: "my-workload", + TNamespace: "ns", + TTraffic: true, + TLabels: map[string]string{"l-key": "l-value"}, + TSelector: map[string]string{"sel-key": "sel-value"}, + TTrafficSelector: map[string]string{"traffic": "yes"}, + }, + canary: nil, + }, + want: []client.Object{ + &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-workload", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}}, + Spec: appsv1.DeploymentSpec{ + Replicas: pointer.Int32(1), + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"sel-key": "sel-value"}}, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "orig-key": "orig-value", + "l-key": "l-value", + "sel-key": "sel-value", + "traffic": "yes", + }, + Annotations: map[string]string{"basereconciler.3cale.net/secret.secret-hash": ""}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{{ + Name: "container", + Image: "example.com:latest", + Resources: corev1.ResourceRequirements{}, + }}}}}}, + &policyv1.PodDisruptionBudget{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-workload", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}, + }, + Spec: policyv1.PodDisruptionBudgetSpec{ + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"sel-key": "sel-value"}}, + MaxUnavailable: util.IntStrPtr(intstr.FromInt(1)), + }}, + &autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-workload", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}, + }, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + APIVersion: appsv1.SchemeGroupVersion.String(), + Kind: "Deployment", + Name: "my-workload", + }, + MinReplicas: pointer.Int32(1), + MaxReplicas: 2, + Metrics: []autoscalingv2.MetricSpec{{ + Type: autoscalingv2.ResourceMetricSourceType, + Resource: &autoscalingv2.ResourceMetricSource{ + Name: corev1.ResourceName("cpu"), + Target: autoscalingv2.MetricTarget{ + Type: autoscalingv2.UtilizationMetricType, + AverageUtilization: util.Pointer[int32](90), + }}}}}}, + &monitoringv1.PodMonitor{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-workload", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}, + }, + Spec: monitoringv1.PodMonitorSpec{ + PodMetricsEndpoints: nil, + Selector: metav1.LabelSelector{ + MatchLabels: map[string]string{"sel-key": "sel-value"}, + }, + }}, + &marin3rv1alpha1.EnvoyConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-workload", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}, + }, + Spec: marin3rv1alpha1.EnvoyConfigSpec{ + NodeID: "my-workload", + Serialization: util.Pointer[envoy_serializer.Serialization]("yaml"), + EnvoyAPI: util.Pointer[envoy.APIVersion]("v3"), + EnvoyResources: &marin3rv1alpha1.EnvoyResources{ + Clusters: []marin3rv1alpha1.EnvoyResource{}, + Routes: []marin3rv1alpha1.EnvoyResource{}, + Listeners: []marin3rv1alpha1.EnvoyResource{}, + Runtimes: []marin3rv1alpha1.EnvoyResource{}, + Secrets: []marin3rv1alpha1.EnvoySecretResource{}, + }}}, + &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "service", Namespace: "ns", + Labels: map[string]string{"l-key": "l-value"}, + }, + Spec: corev1.ServiceSpec{ + Selector: map[string]string{"sel-key": "sel-value", "traffic": "yes"}, + Ports: []corev1.ServicePort{{ + Name: "port", Port: 80, TargetPort: intstr.FromInt(80), Protocol: corev1.ProtocolTCP}}, + }, + }, + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r := &WorkloadReconciler{ + Reconciler: basereconciler.Reconciler{ + Client: tt.fields.Client, + Scheme: tt.fields.Scheme, + }, + } + templates, err := r.NewDeploymentWorkload(tt.args.main, tt.args.canary) + if (err != nil) != tt.wantErr { + t.Errorf("WorkloadReconciler.NewDeploymentWorkload() error = %v, wantErr %v", err, tt.wantErr) + return + } + got := make([]client.Object, 0, len(templates)) + for _, tpl := range templates { + o, _ := tpl.Build(context.TODO(), r.Client, nil) + got = append(got, o) + } + if diff := cmp.Diff(got, tt.want, reconcilerutil.IgnoreProperty("Status")); len(diff) > 0 { + t.Errorf("WorkloadReconciler.NewDeploymentWorkload() diff %v", diff) + } + }) + } +} + func Test_applyTrafficSelectorToDeployment(t *testing.T) { type args struct { w DeploymentWorkload @@ -156,7 +322,7 @@ func Test_applyTrafficSelectorToDeployment(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyTrafficSelectorToDeployment(tt.args.w)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(trafficSelectorToDeployment(tt.args.w)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyTrafficSelectorToDeployment() got diff %v", diff) } @@ -204,7 +370,7 @@ func Test_applyHPAScaleTargetRef(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyHPAScaleTargetRef(tt.args.w)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(scaleTargetRefToHPA(tt.args.w)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyHPAScaleTargetRef() got diff %v", diff) } @@ -271,7 +437,7 @@ func Test_applyMeta(t *testing.T) { } for _, tt := range tests1 { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyMeta[*corev1.ConfigMap](tt.args.w)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(meta[*corev1.ConfigMap](tt.args.w)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyMeta() got diff %v", diff) } @@ -312,7 +478,7 @@ func Test_applyMeta(t *testing.T) { } for _, tt := range tests2 { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyMeta[*corev1.Service](tt.args.w)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(meta[*corev1.Service](tt.args.w)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyMeta() got diff %v", diff) } @@ -368,7 +534,7 @@ func Test_applyTrafficSelectorToService(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyTrafficSelectorToService(tt.args.main, tt.args.canary)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(trafficSelectorToService(tt.args.main, tt.args.canary)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyTrafficSelectorToService() got diff %v", diff) } @@ -476,7 +642,7 @@ func Test_applyNodeIdToEnvoyConfig(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, _ := tt.template.C(applyNodeIdToEnvoyConfig(tt.args.w)).Build(context.TODO(), nil, nil) + got, _ := tt.template.Apply(nodeIdToEnvoyConfig(tt.args.w)).Build(context.TODO(), nil, nil) if diff := cmp.Diff(got, tt.want); len(diff) > 0 { t.Errorf("applyNodeIdToEnvoyConfig() got diff %v", diff) } diff --git a/pkg/reconcilers/workloads/test/test_controller.go b/pkg/reconcilers/workloads/test/test_controller.go index c2b0ac5b..dab69bb0 100644 --- a/pkg/reconcilers/workloads/test/test_controller.go +++ b/pkg/reconcilers/workloads/test/test_controller.go @@ -134,8 +134,7 @@ func (gen *TestWorkloadGenerator) Services() []*resource.Template[*corev1.Servic func(client.Object) (*corev1.Service, error) { return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: "service", - Namespace: gen.TNamespace, + Name: "service", }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeLoadBalancer, @@ -182,8 +181,8 @@ func (gen *TestWorkloadGenerator) Deployment() *resource.Template[*appsv1.Deploy mutators.RolloutTrigger{ Name: "secret", SecretName: pointer.String("secret"), - }.AddToDeployment(), - mutators.ReconcileDeploymentReplicas(true), + }.Add(), + mutators.SetDeploymentReplicas(true), ) } diff --git a/pkg/resource_builders/grafanadashboard/resource.go b/pkg/resource_builders/grafanadashboard/resource.go index f2b457ae..38a8e842 100644 --- a/pkg/resource_builders/grafanadashboard/resource.go +++ b/pkg/resource_builders/grafanadashboard/resource.go @@ -16,10 +16,6 @@ func New(key types.NamespacedName, labels map[string]string, cfg saasv1alpha1.Gr return func(client.Object) (*grafanav1alpha1.GrafanaDashboard, error) { return &grafanav1alpha1.GrafanaDashboard{ - TypeMeta: metav1.TypeMeta{ - Kind: "GrafanaDashboard", - APIVersion: grafanav1alpha1.GroupVersion.String(), - }, ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, diff --git a/pkg/resource_builders/hpa/resource.go b/pkg/resource_builders/hpa/resource.go index 31f5fb9f..32aa9514 100644 --- a/pkg/resource_builders/hpa/resource.go +++ b/pkg/resource_builders/hpa/resource.go @@ -16,10 +16,6 @@ func New(key types.NamespacedName, labels map[string]string, cfg saasv1alpha1.Ho return func(client.Object) (*autoscalingv2.HorizontalPodAutoscaler, error) { hpa := autoscalingv2.HorizontalPodAutoscaler{ - TypeMeta: metav1.TypeMeta{ - Kind: "HorizontalPodAutoscaler", - APIVersion: autoscalingv2.SchemeGroupVersion.String(), - }, ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, diff --git a/pkg/resource_builders/pdb/resource.go b/pkg/resource_builders/pdb/resource.go index 2788b998..92342e6f 100644 --- a/pkg/resource_builders/pdb/resource.go +++ b/pkg/resource_builders/pdb/resource.go @@ -16,10 +16,6 @@ func New(key types.NamespacedName, labels map[string]string, selector map[string return func(client.Object) (*policyv1.PodDisruptionBudget, error) { return &policyv1.PodDisruptionBudget{ - TypeMeta: metav1.TypeMeta{ - Kind: "PodDisruptionBudget", - APIVersion: policyv1.SchemeGroupVersion.String(), - }, ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, diff --git a/pkg/resource_builders/podmonitor/resource.go b/pkg/resource_builders/podmonitor/resource.go index f01a4d6c..70edc6de 100644 --- a/pkg/resource_builders/podmonitor/resource.go +++ b/pkg/resource_builders/podmonitor/resource.go @@ -17,10 +17,6 @@ func New(key types.NamespacedName, labels map[string]string, selector map[string return func(client.Object) (*monitoringv1.PodMonitor, error) { return &monitoringv1.PodMonitor{ - TypeMeta: metav1.TypeMeta{ - Kind: "PodMonitor", - APIVersion: monitoringv1.SchemeGroupVersion.String(), - }, ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, diff --git a/test/util/assert.go b/test/util/assert.go index a0530205..4bb62233 100644 --- a/test/util/assert.go +++ b/test/util/assert.go @@ -160,7 +160,7 @@ func (er *ExpectedResource) Assert(c client.Client, o client.Object, timeout, po } return func() { - By(fmt.Sprintf("%s object does exists", er.Name)) + By(fmt.Sprintf("%s object does exist", er.Name)) Eventually(func() error { return c.Get(context.Background(), types.NamespacedName{Name: er.Name, Namespace: er.Namespace}, o,