Skip to content

Commit

Permalink
wip modify generators
Browse files Browse the repository at this point in the history
  • Loading branch information
roivaz committed Dec 5, 2023
1 parent b84bf50 commit f0f3baa
Show file tree
Hide file tree
Showing 62 changed files with 2,039 additions and 2,024 deletions.
4 changes: 2 additions & 2 deletions controllers/autossl_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/corsproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/mappingservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}
Expand Down
163 changes: 136 additions & 27 deletions controllers/reconciler_config.go
Original file line number Diff line number Diff line change
@@ -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",
},
})
}
21 changes: 2 additions & 19 deletions controllers/shardedredisbackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,20 @@ 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
shards []string
}
tests := []struct {
name string
fields fields
args args
wantChanged bool
wantStatus saasv1alpha1.ShardedRedisBackupStatus
wantErr bool
}{
{
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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion controllers/system_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions controllers/twemproxyconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit f0f3baa

Please sign in to comment.