Skip to content

Commit

Permalink
Apply basereconciler api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
roivaz committed Dec 15, 2023
1 parent aee5061 commit eb6ecd8
Show file tree
Hide file tree
Showing 40 changed files with 266 additions and 336 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY vendor/ vendor/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
Expand Down
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.11
VERSION ?= 0.21.0-alpha.12

# 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-07T17:16:07Z"
createdAt: "2023-12-14T16:25:11Z"
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/saas-operator
support: Red Hat
name: saas-operator.v0.21.0-alpha.11
name: saas-operator.v0.21.0-alpha.12
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.11
image: quay.io/3scale/saas-operator:v0.21.0-alpha.12
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.11
version: 0.21.0-alpha.12
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.11
newTag: v0.21.0-alpha.12
15 changes: 6 additions & 9 deletions controllers/apicast_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -59,10 +58,9 @@ func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.Apicast{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand All @@ -87,10 +85,9 @@ func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
resources = append(resources, production...)

err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to update owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand Down
15 changes: 6 additions & 9 deletions controllers/autossl_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -58,10 +57,9 @@ func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.AutoSSL{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand All @@ -88,10 +86,9 @@ func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
resources = append(resources, workload...)

err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to update owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand Down
17 changes: 7 additions & 10 deletions controllers/backend_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand Down Expand Up @@ -64,10 +63,9 @@ func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.Backend{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand Down Expand Up @@ -103,10 +101,9 @@ func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
resources = append(resources, cron_resources...)

// Reconcile all resources
err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to reconcile owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand All @@ -125,6 +122,6 @@ func (r *BackendReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&grafanav1alpha1.GrafanaDashboard{}).
Owns(&marin3rv1alpha1.EnvoyConfig{}).
Watches(&source.Kind{Type: &corev1.Secret{TypeMeta: metav1.TypeMeta{Kind: "Secret"}}},
r.SecretEventHandler(&saasv1alpha1.BackendList{}, r.Log)).
r.FilteredEventHandler(&saasv1alpha1.BackendList{}, nil, r.Log)).
Complete(r)
}
17 changes: 7 additions & 10 deletions controllers/corsproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand Down Expand Up @@ -63,10 +62,9 @@ func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.CORSProxy{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand All @@ -89,10 +87,9 @@ func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
resources = append(resources, workload...)

err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to reconcile owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand All @@ -110,6 +107,6 @@ func (r *CORSProxyReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&externalsecretsv1beta1.ExternalSecret{}).
Owns(&grafanav1alpha1.GrafanaDashboard{}).
Watches(&source.Kind{Type: &corev1.Secret{TypeMeta: metav1.TypeMeta{Kind: "Secret"}}},
r.SecretEventHandler(&saasv1alpha1.CORSProxyList{}, r.Log)).
r.FilteredEventHandler(&saasv1alpha1.CORSProxyList{}, nil, r.Log)).
Complete(r)
}
15 changes: 6 additions & 9 deletions controllers/echoapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -58,10 +57,9 @@ func (r *EchoAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.EchoAPI{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand All @@ -78,10 +76,9 @@ func (r *EchoAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, err
}

err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to update owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand Down
17 changes: 7 additions & 10 deletions controllers/mappingservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand Down Expand Up @@ -63,10 +62,9 @@ func (r *MappingServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque
ctx = log.IntoContext(ctx, logger)

instance := &saasv1alpha1.MappingService{}
key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace}
result, err := r.GetInstance(ctx, key, instance, nil, nil)
if result != nil || err != nil {
return *result, err
result := r.ManageResourceLifecycle(ctx, req, instance)
if result.ShouldReturn() {
return result.Values()
}

// Apply defaults for reconcile but do not store them in the API
Expand All @@ -89,10 +87,9 @@ func (r *MappingServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
resources = append(resources, workload...)

err = r.ReconcileOwnedResources(ctx, instance, resources)
if err != nil {
logger.Error(err, "unable to reconcile owned resources")
return ctrl.Result{}, err
result = r.ReconcileOwnedResources(ctx, instance, resources)
if result.ShouldReturn() {
return result.Values()
}

return ctrl.Result{}, nil
Expand All @@ -110,6 +107,6 @@ func (r *MappingServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&externalsecretsv1beta1.ExternalSecret{}).
Owns(&grafanav1alpha1.GrafanaDashboard{}).
Watches(&source.Kind{Type: &corev1.Secret{TypeMeta: metav1.TypeMeta{Kind: "Secret"}}},
r.SecretEventHandler(&saasv1alpha1.MappingServiceList{}, r.Log)).
r.FilteredEventHandler(&saasv1alpha1.MappingServiceList{}, nil, r.Log)).
Complete(r)
}
21 changes: 15 additions & 6 deletions controllers/reconciler_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ func init() {
"spec.clusterIP",
"spec.clusterIPs",
},
// IgnoreProperties: []string{
// "spec.externalTrafficPolicy",
// "spec.ipFamilies",
// "spec.ipFamilyPolicy",
// "spec.sessionAffinity",
// },
})
config.SetDefaultReconcileConfigForGVK(
schema.FromAPIVersionAndKind("v1", "ConfigMap"),
Expand Down Expand Up @@ -146,6 +140,21 @@ func init() {
"spec.results",
},
})
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",
},
})
// default config for any GVK not explicitely declared in the config
config.SetDefaultReconcileConfigForGVK(
schema.GroupVersionKind{},
Expand Down
Loading

0 comments on commit eb6ecd8

Please sign in to comment.