Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade/libs #217

Merged
merged 10 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20.10 as builder
FROM golang:1.20.13 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ endif
IMG ?= $(IMAGE_TAG_BASE):v$(VERSION)

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26
ENVTEST_K8S_VERSION = 1.27

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

kind-create: export KUBECONFIG = $(PWD)/kubeconfig
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
$(KIND) create cluster --wait 5m --config test/kind.yaml --image kindest/node:v1.25.2
$(KIND) create cluster --wait 5m --config test/kind.yaml --image kindest/node:v1.27.10
$(MAKE) deploy-cert-manager
$(KIND) load docker-image quay.io/3scale/marin3r:test --name kind

Expand Down
8 changes: 8 additions & 0 deletions apis/marin3r/v1alpha1/envoyconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
reconcilerutil "github.com/3scale-ops/basereconciler/util"
"github.com/3scale-ops/marin3r/pkg/envoy"
envoy_serializer "github.com/3scale-ops/marin3r/pkg/envoy/serializer"
"github.com/3scale-ops/marin3r/pkg/util/pointer"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -168,6 +169,13 @@ func (ec *EnvoyConfig) GetEnvoyResourcesVersion() string {
return reconcilerutil.Hash(ec.Spec.Resources)
}

// Default implements defaulting for the EnvoyConfig resource
func (ec *EnvoyConfig) Default() {
if ec.Spec.EnvoyAPI == nil {
ec.Spec.EnvoyAPI = pointer.New(ec.GetEnvoyAPIVersion())
}
}

// +kubebuilder:object:root=true

// EnvoyConfigList contains a list of EnvoyConfig
Expand Down
8 changes: 8 additions & 0 deletions apis/marin3r/v1alpha1/envoyconfigrevision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
"github.com/3scale-ops/marin3r/pkg/envoy"
envoy_serializer "github.com/3scale-ops/marin3r/pkg/envoy/serializer"
"github.com/3scale-ops/marin3r/pkg/util/pointer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -170,6 +171,13 @@ func (ecr *EnvoyConfigRevision) GetSerialization() envoy_serializer.Serializatio
return envoy_serializer.Serialization(*ecr.Spec.Serialization)
}

// Default implements defaulting for the EnvoyConfigRevision resource
func (ecr *EnvoyConfigRevision) Default() {
if ecr.Spec.EnvoyAPI == nil {
ecr.Spec.EnvoyAPI = pointer.New(ecr.GetEnvoyAPIVersion())
}
}

// +kubebuilder:object:root=true

// EnvoyConfigRevisionList contains a list of EnvoyConfigRevision
Expand Down
8 changes: 4 additions & 4 deletions apis/operator.marin3r/v1alpha1/discoveryservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"github.com/3scale-ops/basereconciler/status"
"github.com/3scale-ops/basereconciler/reconciler"
"github.com/3scale-ops/marin3r/pkg/image"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -122,7 +122,7 @@ type DiscoveryServiceStatus struct {
// +optional
*appsv1.DeploymentStatus `json:"deploymentStatus,omitempty"`
// internal fields
status.UnimplementedStatefulSetStatus `json:"-"`
reconciler.UnimplementedStatefulSetStatus `json:"-"`
}

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

var _ status.ObjectWithAppStatus = &DiscoveryService{}
var _ reconciler.ObjectWithAppStatus = &DiscoveryService{}

func (d *DiscoveryService) GetStatus() status.AppStatus {
func (d *DiscoveryService) GetStatus() reconciler.AppStatus {
return &d.Status
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

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

func (dsc *DiscoveryServiceCertificate) Default() {
if dsc.Spec.IsServerCertificate == nil {
dsc.Spec.IsServerCertificate = pointer.New(dsc.IsServerCertificate())
}
if dsc.Spec.IsCA == nil {
dsc.Spec.IsCA = pointer.New(dsc.IsCA())
}
if dsc.Spec.Hosts == nil {
dsc.Spec.Hosts = dsc.GetHosts()
}
if dsc.Spec.CertificateRenewalConfig == nil {
crc := dsc.GetCertificateRenewalConfig()
dsc.Spec.CertificateRenewalConfig = &crc
}
}

// +kubebuilder:object:root=true

// DiscoveryServiceCertificateList contains a list of DiscoveryServiceCertificate
Expand Down
10 changes: 5 additions & 5 deletions apis/operator.marin3r/v1alpha1/envoydeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

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

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

// EnvoyDeploymentStatus defines the observed state of EnvoyDeployment
type EnvoyDeploymentStatus struct {
Expand All @@ -401,7 +401,7 @@ type EnvoyDeploymentStatus struct {
// +optional
*appsv1.DeploymentStatus `json:"deploymentStatus,omitempty"`
// internal fields
status.UnimplementedStatefulSetStatus `json:"-"`
reconciler.UnimplementedStatefulSetStatus `json:"-"`
}

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

var _ status.ObjectWithAppStatus = &EnvoyDeployment{}
var _ reconciler.ObjectWithAppStatus = &EnvoyDeployment{}

func (ed *EnvoyDeployment) GetStatus() status.AppStatus {
func (ed *EnvoyDeployment) GetStatus() reconciler.AppStatus {
return &ed.Status
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/discoveryservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"time"

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

// Start controllers
if err := (&marin3rcontroller.EnvoyConfigReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("envoyconfig"),
Scheme: mgr.GetScheme(),
Reconciler: reconciler.NewFromManager(mgr).
WithLogger(ctrl.Log.WithName("controllers").WithName("envoyconfig")),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "envoyconfig")
os.Exit(1)
}

if err := (&marin3rcontroller.EnvoyConfigRevisionReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName(fmt.Sprintf("envoyconfigrevision_%s", string(envoy.APIv3))),
Scheme: mgr.GetScheme(),
Reconciler: reconciler.NewFromManager(mgr).
WithLogger(ctrl.Log.WithName("controllers").WithName(fmt.Sprintf("envoyconfigrevision_%s", string(envoy.APIv3)))),
XdsCache: xdss.GetCache(envoy.APIv3),
APIVersion: envoy.APIv3,
DiscoveryStats: xdss.GetDiscoveryStats(envoy.APIv3),
Expand Down
4 changes: 2 additions & 2 deletions cmd/initmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func parseBindAddress(address string) (string, uint32, error) {

var err error
var host string
var port int
var port int64

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

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

Expand Down
13 changes: 6 additions & 7 deletions cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,24 @@ func runOperator(cmd *cobra.Command, args []string) {
}

if err := (&operatorcontroller.DiscoveryServiceReconciler{
Reconciler: reconciler.NewFromManager(mgr),
Log: ctrl.Log.WithName("controllers").WithName("discoveryservice"),
Reconciler: reconciler.NewFromManager(mgr).
WithLogger(ctrl.Log.WithName("controllers").WithName("discoveryservice")),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "discoveryservice")
os.Exit(1)
}

if err := (&operatorcontroller.DiscoveryServiceCertificateReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("discoveryservicecertificate"),
Scheme: mgr.GetScheme(),
Reconciler: reconciler.NewFromManager(mgr).
WithLogger(ctrl.Log.WithName("controllers").WithName("discoveryservicecertificate")),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "discoveryservicecertificate")
os.Exit(1)
}

if err = (&operatorcontroller.EnvoyDeploymentReconciler{
Reconciler: reconciler.NewFromManager(mgr),
Log: ctrl.Log.WithName("controllers").WithName("envoydeployment"),
Reconciler: reconciler.NewFromManager(mgr).
WithLogger(ctrl.Log.WithName("controllers").WithName("envoydeployment")),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "EnvoyDeployment")
os.Exit(1)
Expand Down
77 changes: 30 additions & 47 deletions controllers/marin3r/envoyconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ package controllers
import (
"context"

"github.com/3scale-ops/basereconciler/reconciler"
reconciler_util "github.com/3scale-ops/basereconciler/util"
marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
envoyconfig "github.com/3scale-ops/marin3r/pkg/reconcilers/marin3r/envoyconfig"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

// EnvoyConfigReconciler reconciles a EnvoyConfig object
type EnvoyConfigReconciler struct {
Client client.Client
Log logr.Logger
Scheme *runtime.Scheme
*reconciler.Reconciler
}

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

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

// Fetch the EnvoyConfig instance
ctx, logger := r.Logger(ctx, "name", req.Name, "namespace", req.Namespace)
ec := &marin3rv1alpha1.EnvoyConfig{}
err := r.Client.Get(ctx, req.NamespacedName, ec)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}

log = log.WithValues("nodeID", ec.Spec.NodeID, "envoyAPI", ec.GetEnvoyAPIVersion())

if ok := envoyconfig.IsInitialized(ec); !ok {
if err := r.Client.Update(ctx, ec); err != nil {
log.Error(err, "unable to update EnvoyConfig")
return ctrl.Result{}, err
}
log.Info("initialized EnvoyConfig resource")
return reconcile.Result{}, nil
result := r.ManageResourceLifecycle(ctx, req, ec,
// Apply defaults
reconciler.WithInitializationFunc(reconciler_util.ResourceDefaulter(ec)),
// convert spec.EnvoyResources to spec.Resources
reconciler.WithInMemoryInitializationFunc(func(ctx context.Context, c client.Client, o client.Object) error {
if ec.Spec.EnvoyResources != nil {
ec := o.(*marin3rv1alpha1.EnvoyConfig)
if resources, err := (ec.Spec.EnvoyResources).Resources(ec.GetSerialization()); err != nil {
return err
} else {
ec.Spec.Resources = resources
ec.Spec.EnvoyResources = nil
}
}
return nil
}),
)
if result.ShouldReturn() {
return result.Values()
}

// convert spec.EnvoyResources to spec.Resources
// all the code from this point on will make use solely
// of the spec.Resources field.
if ec.Spec.EnvoyResources != nil {
if resources, err := (ec.Spec.EnvoyResources).Resources(ec.GetSerialization()); err != nil {
return ctrl.Result{}, err
} else {
ec.Spec.Resources = resources
ec.Spec.EnvoyResources = nil
}
}
logger = logger.WithValues("nodeID", ec.Spec.NodeID, "envoyAPI", ec.GetEnvoyAPIVersion())

revisionReconciler := envoyconfig.NewRevisionReconciler(
ctx, log, r.Client, r.Scheme, ec,
ctx, logger, r.Client, r.Scheme, ec,
)

result, err := revisionReconciler.Reconcile()
if result.Requeue || err != nil {
return result, err
reconcilerResult, err := revisionReconciler.Reconcile()
if reconcilerResult.Requeue || err != nil {
return reconcilerResult, err
}

if ok := envoyconfig.IsStatusReconciled(ec, revisionReconciler.GetCacheState(), revisionReconciler.PublishedVersion(), revisionReconciler.GetRevisionList()); !ok {
if err := r.Client.Status().Update(ctx, ec); err != nil {
log.Error(err, "unable to update EnvoyConfig status")
logger.Error(err, "unable to update EnvoyConfig status")
return ctrl.Result{}, err
}
log.Info("status updated for EnvoyConfig resource")
logger.Info("status updated for EnvoyConfig resource")
return reconcile.Result{}, nil
}

Expand Down
Loading
Loading