Skip to content

Commit d001b4a

Browse files
authored
Merge pull request #217 from 3scale-ops/upgrade/libs
Upgrade/libs
2 parents f6ff635 + e9ccc78 commit d001b4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+789
-1818
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.20.10 as builder
2+
FROM golang:1.20.13 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif
5050
IMG ?= $(IMAGE_TAG_BASE):v$(VERSION)
5151

5252
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
53-
ENVTEST_K8S_VERSION = 1.26
53+
ENVTEST_K8S_VERSION = 1.27
5454

5555
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5656
ifeq (,$(shell go env GOBIN))
@@ -337,7 +337,7 @@ catalog-push: ## Push a catalog image.
337337

338338
kind-create: export KUBECONFIG = $(PWD)/kubeconfig
339339
kind-create: tmp docker-build kind ## Runs a k8s kind cluster with a local registry in "localhost:5000" and ports 1080 and 1443 exposed to the host
340-
$(KIND) create cluster --wait 5m --config test/kind.yaml --image kindest/node:v1.25.2
340+
$(KIND) create cluster --wait 5m --config test/kind.yaml --image kindest/node:v1.27.10
341341
$(MAKE) deploy-cert-manager
342342
$(KIND) load docker-image quay.io/3scale/marin3r:test --name kind
343343

apis/marin3r/v1alpha1/envoyconfig_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
reconcilerutil "github.com/3scale-ops/basereconciler/util"
2121
"github.com/3scale-ops/marin3r/pkg/envoy"
2222
envoy_serializer "github.com/3scale-ops/marin3r/pkg/envoy/serializer"
23+
"github.com/3scale-ops/marin3r/pkg/util/pointer"
2324
corev1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
)
@@ -168,6 +169,13 @@ func (ec *EnvoyConfig) GetEnvoyResourcesVersion() string {
168169
return reconcilerutil.Hash(ec.Spec.Resources)
169170
}
170171

172+
// Default implements defaulting for the EnvoyConfig resource
173+
func (ec *EnvoyConfig) Default() {
174+
if ec.Spec.EnvoyAPI == nil {
175+
ec.Spec.EnvoyAPI = pointer.New(ec.GetEnvoyAPIVersion())
176+
}
177+
}
178+
171179
// +kubebuilder:object:root=true
172180

173181
// EnvoyConfigList contains a list of EnvoyConfig

apis/marin3r/v1alpha1/envoyconfigrevision_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1alpha1
1919
import (
2020
"github.com/3scale-ops/marin3r/pkg/envoy"
2121
envoy_serializer "github.com/3scale-ops/marin3r/pkg/envoy/serializer"
22+
"github.com/3scale-ops/marin3r/pkg/util/pointer"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

@@ -170,6 +171,13 @@ func (ecr *EnvoyConfigRevision) GetSerialization() envoy_serializer.Serializatio
170171
return envoy_serializer.Serialization(*ecr.Spec.Serialization)
171172
}
172173

174+
// Default implements defaulting for the EnvoyConfigRevision resource
175+
func (ecr *EnvoyConfigRevision) Default() {
176+
if ecr.Spec.EnvoyAPI == nil {
177+
ecr.Spec.EnvoyAPI = pointer.New(ecr.GetEnvoyAPIVersion())
178+
}
179+
}
180+
173181
// +kubebuilder:object:root=true
174182

175183
// EnvoyConfigRevisionList contains a list of EnvoyConfigRevision

apis/operator.marin3r/v1alpha1/discoveryservice_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"time"
2222

23-
"github.com/3scale-ops/basereconciler/status"
23+
"github.com/3scale-ops/basereconciler/reconciler"
2424
"github.com/3scale-ops/marin3r/pkg/image"
2525
appsv1 "k8s.io/api/apps/v1"
2626
corev1 "k8s.io/api/core/v1"
@@ -122,7 +122,7 @@ type DiscoveryServiceStatus struct {
122122
// +optional
123123
*appsv1.DeploymentStatus `json:"deploymentStatus,omitempty"`
124124
// internal fields
125-
status.UnimplementedStatefulSetStatus `json:"-"`
125+
reconciler.UnimplementedStatefulSetStatus `json:"-"`
126126
}
127127

128128
func (dss *DiscoveryServiceStatus) GetDeploymentStatus(key types.NamespacedName) *appsv1.DeploymentStatus {
@@ -176,9 +176,9 @@ type DiscoveryService struct {
176176
Status DiscoveryServiceStatus `json:"status,omitempty"`
177177
}
178178

179-
var _ status.ObjectWithAppStatus = &DiscoveryService{}
179+
var _ reconciler.ObjectWithAppStatus = &DiscoveryService{}
180180

181-
func (d *DiscoveryService) GetStatus() status.AppStatus {
181+
func (d *DiscoveryService) GetStatus() reconciler.AppStatus {
182182
return &d.Status
183183
}
184184

apis/operator.marin3r/v1alpha1/discoveryservicecertificate_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"github.com/3scale-ops/marin3r/pkg/util/pointer"
2021
corev1 "k8s.io/api/core/v1"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
@@ -207,6 +208,22 @@ type DiscoveryServiceCertificate struct {
207208
Status DiscoveryServiceCertificateStatus `json:"status,omitempty"`
208209
}
209210

211+
func (dsc *DiscoveryServiceCertificate) Default() {
212+
if dsc.Spec.IsServerCertificate == nil {
213+
dsc.Spec.IsServerCertificate = pointer.New(dsc.IsServerCertificate())
214+
}
215+
if dsc.Spec.IsCA == nil {
216+
dsc.Spec.IsCA = pointer.New(dsc.IsCA())
217+
}
218+
if dsc.Spec.Hosts == nil {
219+
dsc.Spec.Hosts = dsc.GetHosts()
220+
}
221+
if dsc.Spec.CertificateRenewalConfig == nil {
222+
crc := dsc.GetCertificateRenewalConfig()
223+
dsc.Spec.CertificateRenewalConfig = &crc
224+
}
225+
}
226+
210227
// +kubebuilder:object:root=true
211228

212229
// DiscoveryServiceCertificateList contains a list of DiscoveryServiceCertificate

apis/operator.marin3r/v1alpha1/envoydeployment_types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"time"
2222

23-
"github.com/3scale-ops/basereconciler/status"
23+
"github.com/3scale-ops/basereconciler/reconciler"
2424
defaults "github.com/3scale-ops/marin3r/pkg/envoy/container/defaults"
2525
"github.com/3scale-ops/marin3r/pkg/util/pointer"
2626
appsv1 "k8s.io/api/apps/v1"
@@ -390,7 +390,7 @@ func (im *InitManager) GetImage() string {
390390
}
391391

392392
// ensure the status implements the AppStatus interface from "github.com/3scale-ops/basereconciler/status"
393-
var _ status.AppStatus = &EnvoyDeploymentStatus{}
393+
var _ reconciler.AppStatus = &EnvoyDeploymentStatus{}
394394

395395
// EnvoyDeploymentStatus defines the observed state of EnvoyDeployment
396396
type EnvoyDeploymentStatus struct {
@@ -401,7 +401,7 @@ type EnvoyDeploymentStatus struct {
401401
// +optional
402402
*appsv1.DeploymentStatus `json:"deploymentStatus,omitempty"`
403403
// internal fields
404-
status.UnimplementedStatefulSetStatus `json:"-"`
404+
reconciler.UnimplementedStatefulSetStatus `json:"-"`
405405
}
406406

407407
func (eds *EnvoyDeploymentStatus) GetDeploymentStatus(key types.NamespacedName) *appsv1.DeploymentStatus {
@@ -429,9 +429,9 @@ type EnvoyDeployment struct {
429429
Status EnvoyDeploymentStatus `json:"status,omitempty"`
430430
}
431431

432-
var _ status.ObjectWithAppStatus = &EnvoyDeployment{}
432+
var _ reconciler.ObjectWithAppStatus = &EnvoyDeployment{}
433433

434-
func (ed *EnvoyDeployment) GetStatus() status.AppStatus {
434+
func (ed *EnvoyDeployment) GetStatus() reconciler.AppStatus {
435435
return &ed.Status
436436
}
437437

cmd/discoveryservice.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sync"
2727
"time"
2828

29+
"github.com/3scale-ops/basereconciler/reconciler"
2930
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
3031
operatorv1alpha1 "github.com/3scale-ops/marin3r/apis/operator.marin3r/v1alpha1"
3132
marin3rcontroller "github.com/3scale-ops/marin3r/controllers/marin3r"
@@ -145,18 +146,16 @@ func runDiscoveryService(cmd *cobra.Command, args []string) {
145146

146147
// Start controllers
147148
if err := (&marin3rcontroller.EnvoyConfigReconciler{
148-
Client: mgr.GetClient(),
149-
Log: ctrl.Log.WithName("controllers").WithName("envoyconfig"),
150-
Scheme: mgr.GetScheme(),
149+
Reconciler: reconciler.NewFromManager(mgr).
150+
WithLogger(ctrl.Log.WithName("controllers").WithName("envoyconfig")),
151151
}).SetupWithManager(mgr); err != nil {
152152
setupLog.Error(err, "unable to create controller", "controller", "envoyconfig")
153153
os.Exit(1)
154154
}
155155

156156
if err := (&marin3rcontroller.EnvoyConfigRevisionReconciler{
157-
Client: mgr.GetClient(),
158-
Log: ctrl.Log.WithName("controllers").WithName(fmt.Sprintf("envoyconfigrevision_%s", string(envoy.APIv3))),
159-
Scheme: mgr.GetScheme(),
157+
Reconciler: reconciler.NewFromManager(mgr).
158+
WithLogger(ctrl.Log.WithName("controllers").WithName(fmt.Sprintf("envoyconfigrevision_%s", string(envoy.APIv3)))),
160159
XdsCache: xdss.GetCache(envoy.APIv3),
161160
APIVersion: envoy.APIv3,
162161
DiscoveryStats: xdss.GetDiscoveryStats(envoy.APIv3),

cmd/initmanager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func parseBindAddress(address string) (string, uint32, error) {
173173

174174
var err error
175175
var host string
176-
var port int
176+
var port int64
177177

178178
var parts []string
179179
if parts = strings.Split(address, ":"); len(parts) != 2 {
@@ -186,7 +186,7 @@ func parseBindAddress(address string) (string, uint32, error) {
186186
return "", 0, err
187187
}
188188

189-
if port, err = strconv.Atoi(parts[1]); err != nil {
189+
if port, err = strconv.ParseInt(parts[1], 10, 32); err != nil {
190190
return "", 0, fmt.Errorf("unable to parse port value in 'spec.envoyStaticConfig.adminBindAddress'")
191191
}
192192

cmd/operator.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,24 @@ func runOperator(cmd *cobra.Command, args []string) {
107107
}
108108

109109
if err := (&operatorcontroller.DiscoveryServiceReconciler{
110-
Reconciler: reconciler.NewFromManager(mgr),
111-
Log: ctrl.Log.WithName("controllers").WithName("discoveryservice"),
110+
Reconciler: reconciler.NewFromManager(mgr).
111+
WithLogger(ctrl.Log.WithName("controllers").WithName("discoveryservice")),
112112
}).SetupWithManager(mgr); err != nil {
113113
setupLog.Error(err, "unable to create controller", "controller", "discoveryservice")
114114
os.Exit(1)
115115
}
116116

117117
if err := (&operatorcontroller.DiscoveryServiceCertificateReconciler{
118-
Client: mgr.GetClient(),
119-
Log: ctrl.Log.WithName("controllers").WithName("discoveryservicecertificate"),
120-
Scheme: mgr.GetScheme(),
118+
Reconciler: reconciler.NewFromManager(mgr).
119+
WithLogger(ctrl.Log.WithName("controllers").WithName("discoveryservicecertificate")),
121120
}).SetupWithManager(mgr); err != nil {
122121
setupLog.Error(err, "unable to create controller", "controller", "discoveryservicecertificate")
123122
os.Exit(1)
124123
}
125124

126125
if err = (&operatorcontroller.EnvoyDeploymentReconciler{
127-
Reconciler: reconciler.NewFromManager(mgr),
128-
Log: ctrl.Log.WithName("controllers").WithName("envoydeployment"),
126+
Reconciler: reconciler.NewFromManager(mgr).
127+
WithLogger(ctrl.Log.WithName("controllers").WithName("envoydeployment")),
129128
}).SetupWithManager(mgr); err != nil {
130129
setupLog.Error(err, "unable to create controller", "controller", "EnvoyDeployment")
131130
os.Exit(1)

controllers/marin3r/envoyconfig_controller.go

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ package controllers
1919
import (
2020
"context"
2121

22+
"github.com/3scale-ops/basereconciler/reconciler"
23+
reconciler_util "github.com/3scale-ops/basereconciler/util"
2224
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
2325
envoyconfig "github.com/3scale-ops/marin3r/pkg/reconcilers/marin3r/envoyconfig"
24-
25-
"github.com/go-logr/logr"
26-
"k8s.io/apimachinery/pkg/api/errors"
27-
"k8s.io/apimachinery/pkg/runtime"
2826
ctrl "sigs.k8s.io/controller-runtime"
2927
"sigs.k8s.io/controller-runtime/pkg/client"
3028
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3129
)
3230

3331
// EnvoyConfigReconciler reconciles a EnvoyConfig object
3432
type EnvoyConfigReconciler struct {
35-
Client client.Client
36-
Log logr.Logger
37-
Scheme *runtime.Scheme
33+
*reconciler.Reconciler
3834
}
3935

4036
// Reconcile progresses EnvoyConfig resources to its desired state
@@ -44,60 +40,47 @@ type EnvoyConfigReconciler struct {
4440
// +kubebuilder:rbac:groups=marin3r.3scale.net,namespace=placeholder,resources=envoyconfigrevisions/status,verbs=get;update;patch
4541

4642
func (r *EnvoyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
47-
log := r.Log.WithValues("name", req.Name, "namespace", req.Namespace)
4843

49-
// Fetch the EnvoyConfig instance
44+
ctx, logger := r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
5045
ec := &marin3rv1alpha1.EnvoyConfig{}
51-
err := r.Client.Get(ctx, req.NamespacedName, ec)
52-
if err != nil {
53-
if errors.IsNotFound(err) {
54-
// Request object not found, could have been deleted after reconcile request.
55-
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
56-
// Return and don't requeue
57-
return ctrl.Result{}, nil
58-
}
59-
// Error reading the object - requeue the request.
60-
return ctrl.Result{}, err
61-
}
62-
63-
log = log.WithValues("nodeID", ec.Spec.NodeID, "envoyAPI", ec.GetEnvoyAPIVersion())
64-
65-
if ok := envoyconfig.IsInitialized(ec); !ok {
66-
if err := r.Client.Update(ctx, ec); err != nil {
67-
log.Error(err, "unable to update EnvoyConfig")
68-
return ctrl.Result{}, err
69-
}
70-
log.Info("initialized EnvoyConfig resource")
71-
return reconcile.Result{}, nil
46+
result := r.ManageResourceLifecycle(ctx, req, ec,
47+
// Apply defaults
48+
reconciler.WithInitializationFunc(reconciler_util.ResourceDefaulter(ec)),
49+
// convert spec.EnvoyResources to spec.Resources
50+
reconciler.WithInMemoryInitializationFunc(func(ctx context.Context, c client.Client, o client.Object) error {
51+
if ec.Spec.EnvoyResources != nil {
52+
ec := o.(*marin3rv1alpha1.EnvoyConfig)
53+
if resources, err := (ec.Spec.EnvoyResources).Resources(ec.GetSerialization()); err != nil {
54+
return err
55+
} else {
56+
ec.Spec.Resources = resources
57+
ec.Spec.EnvoyResources = nil
58+
}
59+
}
60+
return nil
61+
}),
62+
)
63+
if result.ShouldReturn() {
64+
return result.Values()
7265
}
7366

74-
// convert spec.EnvoyResources to spec.Resources
75-
// all the code from this point on will make use solely
76-
// of the spec.Resources field.
77-
if ec.Spec.EnvoyResources != nil {
78-
if resources, err := (ec.Spec.EnvoyResources).Resources(ec.GetSerialization()); err != nil {
79-
return ctrl.Result{}, err
80-
} else {
81-
ec.Spec.Resources = resources
82-
ec.Spec.EnvoyResources = nil
83-
}
84-
}
67+
logger = logger.WithValues("nodeID", ec.Spec.NodeID, "envoyAPI", ec.GetEnvoyAPIVersion())
8568

8669
revisionReconciler := envoyconfig.NewRevisionReconciler(
87-
ctx, log, r.Client, r.Scheme, ec,
70+
ctx, logger, r.Client, r.Scheme, ec,
8871
)
8972

90-
result, err := revisionReconciler.Reconcile()
91-
if result.Requeue || err != nil {
92-
return result, err
73+
reconcilerResult, err := revisionReconciler.Reconcile()
74+
if reconcilerResult.Requeue || err != nil {
75+
return reconcilerResult, err
9376
}
9477

9578
if ok := envoyconfig.IsStatusReconciled(ec, revisionReconciler.GetCacheState(), revisionReconciler.PublishedVersion(), revisionReconciler.GetRevisionList()); !ok {
9679
if err := r.Client.Status().Update(ctx, ec); err != nil {
97-
log.Error(err, "unable to update EnvoyConfig status")
80+
logger.Error(err, "unable to update EnvoyConfig status")
9881
return ctrl.Result{}, err
9982
}
100-
log.Info("status updated for EnvoyConfig resource")
83+
logger.Info("status updated for EnvoyConfig resource")
10184
return reconcile.Result{}, nil
10285
}
10386

0 commit comments

Comments
 (0)