Skip to content

Commit

Permalink
Workload is no longer a reconciler, just a generator
Browse files Browse the repository at this point in the history
Basereconciler is now more capable so the things that the workload
reconciler did can now be done using just the basereconciler. Workload
is now just a package with functions to generate templates.
  • Loading branch information
roivaz committed Dec 19, 2023
1 parent 1599038 commit e343449
Show file tree
Hide file tree
Showing 38 changed files with 383 additions and 1,485 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.21.0-alpha.14
VERSION ?= 0.21.0-alpha.15

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down
8 changes: 4 additions & 4 deletions bundle/manifests/saas-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,15 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/3scale/saas-operator
createdAt: "2023-12-15T16:09:07Z"
createdAt: "2023-12-18T15:40:44Z"
description: |-
The 3scale SaaS Operator creates and maintains a SaaS-ready deployment
of the Red Hat 3scale API Management on OpenShift.
operators.operatorframework.io/builder: operator-sdk-v1.27.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/3scale-ops/saas-operator
support: Red Hat
name: saas-operator.v0.21.0-alpha.14
name: saas-operator.v0.21.0-alpha.15
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -4481,7 +4481,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
image: quay.io/3scale/saas-operator:v0.21.0-alpha.14
image: quay.io/3scale/saas-operator:v0.21.0-alpha.15
livenessProbe:
httpGet:
path: /healthz
Expand Down Expand Up @@ -5045,4 +5045,4 @@ spec:
provider:
name: Red Hat
url: https://www.3scale.net/
version: 0.21.0-alpha.14
version: 0.21.0-alpha.15
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/3scale/saas-operator
newTag: v0.21.0-alpha.14
newTag: v0.21.0-alpha.15
23 changes: 4 additions & 19 deletions controllers/apicast_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ import (
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
"github.com/3scale-ops/saas-operator/pkg/generators/apicast"
"github.com/3scale-ops/saas-operator/pkg/reconcilers/workloads"
"github.com/go-logr/logr"
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"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// ApicastReconciler reconciles a Apicast object
type ApicastReconciler struct {
workloads.WorkloadReconciler
Log logr.Logger
*reconciler.Reconciler
}

// +kubebuilder:rbac:groups=saas.3scale.net,namespace=placeholder,resources=apicasts,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -56,9 +52,8 @@ type ApicastReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
ctx = log.IntoContext(ctx, logger)

ctx, _ = r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
instance := &saasv1alpha1.Apicast{}
result := r.ManageResourceLifecycle(ctx, req, instance,
reconciler.WithInMemoryInitializationFunc(util.ResourceDefaulter(instance)))
Expand All @@ -70,20 +65,10 @@ func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if err != nil {
return ctrl.Result{}, err
}

resources := gen.Resources()

staging, err := r.NewDeploymentWorkload(&gen.Staging, gen.CanaryStaging)
resources, err := gen.Resources()
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, staging...)

production, err := r.NewDeploymentWorkload(&gen.Production, gen.CanaryProduction)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, nil
}
resources = append(resources, production...)

result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
Expand Down
26 changes: 4 additions & 22 deletions controllers/autossl_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,21 @@ import (
"context"

"github.com/3scale-ops/basereconciler/reconciler"
"github.com/3scale-ops/basereconciler/resource"
"github.com/3scale-ops/basereconciler/util"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
"github.com/3scale-ops/saas-operator/pkg/generators/autossl"
"github.com/3scale-ops/saas-operator/pkg/reconcilers/workloads"
"github.com/go-logr/logr"
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"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// AutoSSLReconciler reconciles a AutoSSL object
type AutoSSLReconciler struct {
workloads.WorkloadReconciler
Log logr.Logger
*reconciler.Reconciler
}

// +kubebuilder:rbac:groups=saas.3scale.net,namespace=placeholder,resources=autossls,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -55,36 +50,23 @@ type AutoSSLReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
ctx = log.IntoContext(ctx, logger)

ctx, _ = r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
instance := &saasv1alpha1.AutoSSL{}
result := r.ManageResourceLifecycle(ctx, req, instance,
reconciler.WithInMemoryInitializationFunc(util.ResourceDefaulter(instance)))
if result.ShouldReturn() {
return result.Values()
}

gen, err := autossl.NewGenerator(
instance.GetName(),
instance.GetNamespace(),
instance.Spec,
)
gen, err := autossl.NewGenerator(instance.GetName(), instance.GetNamespace(), instance.Spec)
if err != nil {
return ctrl.Result{}, err
}

// Shared resources
resources := []resource.TemplateInterface{
gen.GrafanaDashboard(),
}

// Workload resources
workload, err := r.NewDeploymentWorkload(&gen, gen.Canary)
resources, err := gen.Resources()
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, workload...)

result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
Expand Down
31 changes: 3 additions & 28 deletions controllers/backend_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
"github.com/3scale-ops/saas-operator/pkg/generators/backend"
"github.com/3scale-ops/saas-operator/pkg/reconcilers/workloads"
externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
"github.com/go-logr/logr"
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"
Expand All @@ -35,14 +33,12 @@ import (
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// BackendReconciler reconciles a Backend object
type BackendReconciler struct {
workloads.WorkloadReconciler
Log logr.Logger
*reconciler.Reconciler
}

// +kubebuilder:rbac:groups=saas.3scale.net,namespace=placeholder,resources=backends,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -61,9 +57,8 @@ type BackendReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
ctx = log.IntoContext(ctx, logger)

ctx, _ = r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
instance := &saasv1alpha1.Backend{}
result := r.ManageResourceLifecycle(ctx, req, instance,
reconciler.WithInMemoryInitializationFunc(util.ResourceDefaulter(instance)))
Expand All @@ -75,30 +70,10 @@ func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if err != nil {
return ctrl.Result{}, err
}

// Shared resources
resources := gen.Resources()

// Listener resources
listener_resources, err := r.NewDeploymentWorkload(&gen.Listener, gen.CanaryListener)
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, listener_resources...)

// Worker resources
worker_resources, err := r.NewDeploymentWorkload(&gen.Worker, gen.CanaryWorker)
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, worker_resources...)

// Cron resources
cron_resources, err := r.NewDeploymentWorkload(&gen.Cron, nil)
resources, err := gen.Resources()
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, cron_resources...)

// Reconcile all resources
result = r.ReconcileOwnedResources(ctx, instance, resources)
Expand Down
25 changes: 4 additions & 21 deletions controllers/corsproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ import (
"context"

"github.com/3scale-ops/basereconciler/reconciler"
"github.com/3scale-ops/basereconciler/resource"
"github.com/3scale-ops/basereconciler/util"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
"github.com/3scale-ops/saas-operator/pkg/generators/corsproxy"
"github.com/3scale-ops/saas-operator/pkg/reconcilers/workloads"
externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
"github.com/go-logr/logr"
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"
Expand All @@ -35,14 +32,12 @@ import (
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// CORSProxyReconciler reconciles a CORSProxy object
type CORSProxyReconciler struct {
workloads.WorkloadReconciler
Log logr.Logger
*reconciler.Reconciler
}

// +kubebuilder:rbac:groups=saas.3scale.net,namespace=placeholder,resources=corsproxies,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -60,32 +55,20 @@ type CORSProxyReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
ctx = log.IntoContext(ctx, logger)

ctx, _ = r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
instance := &saasv1alpha1.CORSProxy{}
result := r.ManageResourceLifecycle(ctx, req, instance,
reconciler.WithInMemoryInitializationFunc(util.ResourceDefaulter(instance)))
if result.ShouldReturn() {
return result.Values()
}

gen := corsproxy.NewGenerator(
instance.GetName(),
instance.GetNamespace(),
instance.Spec,
)

resources := []resource.TemplateInterface{
gen.GrafanaDashboard(),
gen.ExternalSecret(),
}

workload, err := r.NewDeploymentWorkload(&gen, nil)
gen := corsproxy.NewGenerator(instance.GetName(), instance.GetNamespace(), instance.Spec)
resources, err := gen.Resources()
if err != nil {
return ctrl.Result{}, err
}
resources = append(resources, workload...)

result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
Expand Down
18 changes: 4 additions & 14 deletions controllers/echoapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ import (
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
"github.com/3scale-ops/saas-operator/pkg/generators/echoapi"
"github.com/3scale-ops/saas-operator/pkg/reconcilers/workloads"
"github.com/go-logr/logr"
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"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// EchoAPIReconciler reconciles a EchoAPI object
type EchoAPIReconciler struct {
workloads.WorkloadReconciler
Log logr.Logger
*reconciler.Reconciler
}

// +kubebuilder:rbac:groups=saas.3scale.net,namespace=placeholder,resources=echoapis,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -55,23 +51,17 @@ type EchoAPIReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *EchoAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
ctx = log.IntoContext(ctx, logger)

ctx, _ = r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
instance := &saasv1alpha1.EchoAPI{}
result := r.ManageResourceLifecycle(ctx, req, instance,
reconciler.WithInMemoryInitializationFunc(util.ResourceDefaulter(instance)))
if result.ShouldReturn() {
return result.Values()
}

gen := echoapi.NewGenerator(
instance.GetName(),
instance.GetNamespace(),
instance.Spec,
)

resources, err := r.NewDeploymentWorkload(&gen, nil)
gen := echoapi.NewGenerator(instance.GetName(), instance.GetNamespace(), instance.Spec)
resources, err := gen.Resources()
if err != nil {
return ctrl.Result{}, err
}
Expand Down
Loading

0 comments on commit e343449

Please sign in to comment.