Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into support_kube_1_20_15
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Nov 15, 2024
2 parents 902a5f8 + 3363fac commit 27591a4
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 228 deletions.
20 changes: 0 additions & 20 deletions autoscaler/controllers/collectorsgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// CollectorsGroupReconciler reconciles a CollectorsGroup object
type CollectorsGroupReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand All @@ -44,24 +43,6 @@ type CollectorsGroupReconciler struct {
Config *controllerconfig.ControllerConfig
}

//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups/finalizers,verbs=update
//+kubebuilder:rbac:groups=apps,namespace=odigos-system,resources=deployments,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,namespace=odigos-system,resources=deployments/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=apps,namespace=odigos-system,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,namespace=odigos-system,resources=daemonsets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups="",namespace=odigos-system,resources=services,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="",namespace=odigos-system,resources=configmaps,verbs=get;list;watch;create;update;patch;delete

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// the CollectorsGroup object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.2/pkg/reconcile
func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling CollectorsGroup")
Expand All @@ -79,7 +60,6 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *CollectorsGroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&odigosv1.CollectorsGroup{}).
Expand Down
7 changes: 2 additions & 5 deletions autoscaler/controllers/datacollectiondaemonset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
predicate "github.com/odigos-io/odigos/k8sutils/pkg/predicate"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -20,10 +21,6 @@ func (r *DataCollectionDaemonSetReconciler) Reconcile(ctx context.Context, req c
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling DaemonSet")

if req.Name != consts.OdigosNodeCollectorDaemonSetName {
return ctrl.Result{}, nil
}

var ds appsv1.DaemonSet
if err := r.Get(ctx, req.NamespacedName, &ds); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
Expand Down Expand Up @@ -56,9 +53,9 @@ func calcDataCollectionReadyStatus(ds *appsv1.DaemonSet) bool {
return ds.Status.DesiredNumberScheduled > 0 && float64(ds.Status.NumberReady) >= float64(ds.Status.DesiredNumberScheduled)/float64(2)
}

// SetupWithManager sets up the controller with the Manager.
func (r *DataCollectionDaemonSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&appsv1.DaemonSet{}).
WithEventFilter(&predicate.NodeCollectorsDaemonSetPredicate).
Complete(r)
}
17 changes: 4 additions & 13 deletions autoscaler/controllers/destination_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
)

// DestinationReconciler reconciles a Destination object
type DestinationReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand All @@ -38,18 +38,6 @@ type DestinationReconciler struct {
Config *controllerconfig.ControllerConfig
}

//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=destinations,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=destinations/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=destinations/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// the Destination object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.2/pkg/reconcile
func (r *DestinationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Destination")
Expand All @@ -65,5 +53,8 @@ func (r *DestinationReconciler) Reconcile(ctx context.Context, req ctrl.Request)
func (r *DestinationReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1.Destination{}).
// auto scaler only cares about the spec of each destination.
// filter out events on resource status and metadata changes.
WithEventFilter(&predicate.GenerationChangedPredicate{}).
Complete(r)
}
7 changes: 2 additions & 5 deletions autoscaler/controllers/gatewaydeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
predicate "github.com/odigos-io/odigos/k8sutils/pkg/predicate"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -20,10 +21,6 @@ func (r *GatewayDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Re
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Deployment")

if req.Name != consts.OdigosClusterCollectorDeploymentName {
return ctrl.Result{}, nil
}

var dep appsv1.Deployment
if err := r.Get(ctx, req.NamespacedName, &dep); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
Expand All @@ -50,9 +47,9 @@ func (r *GatewayDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Re
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *GatewayDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&appsv1.Deployment{}).
WithEventFilter(&predicate.ClusterCollectorDeploymentPredicate).
Complete(r)
}
18 changes: 4 additions & 14 deletions autoscaler/controllers/instrumentedapplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
predicate "github.com/odigos-io/odigos/k8sutils/pkg/predicate"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/version"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// InstrumentedApplicationReconciler reconciles a InstrumentedApplication object
type InstrumentedApplicationReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand All @@ -38,18 +38,6 @@ type InstrumentedApplicationReconciler struct {
DisableNameProcessor bool
}

//+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// the InstrumentedApplication object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.2/pkg/reconcile
func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling InstrumentedApps")
Expand All @@ -61,9 +49,11 @@ func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req c
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *InstrumentedApplicationReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&odigosv1.InstrumentedApplication{}).
// this controller only cares about the instrumented application existence.
// when it is created or removed, the node collector config map needs to be updated to scrape logs for it's pods.
WithEventFilter(&predicate.ExistencePredicate{}).
Complete(r)
}
1 change: 0 additions & 1 deletion autoscaler/controllers/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (r *OdigosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *OdigosConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1.ConfigMap{}).
Expand Down
5 changes: 4 additions & 1 deletion autoscaler/controllers/processor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

type ProcessorReconciler struct {
Expand Down Expand Up @@ -42,9 +43,11 @@ func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *ProcessorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1.Processor{}).
// auto scaler only cares about the spec of each processor.
// filter out events on resource status and metadata changes.
WithEventFilter(&predicate.GenerationChangedPredicate{}).
Complete(r)
}
35 changes: 5 additions & 30 deletions autoscaler/controllers/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

controllerconfig "github.com/odigos-io/odigos/autoscaler/controllers/controller_config"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
odigospredicate "github.com/odigos-io/odigos/k8sutils/pkg/predicate"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

Expand All @@ -23,33 +23,6 @@ type SecretReconciler struct {
Config *controllerconfig.ControllerConfig
}

type secretPredicate struct {
predicate.Funcs
}

func (i *secretPredicate) Create(e event.CreateEvent) bool {
return false
}

func (i *secretPredicate) Update(e event.UpdateEvent) bool {
oldSecret, oldOk := e.ObjectOld.(*corev1.Secret)
newSecret, newOk := e.ObjectNew.(*corev1.Secret)

if !oldOk || !newOk {
return false
}

return oldSecret.ResourceVersion != newSecret.ResourceVersion
}

func (i *secretPredicate) Delete(e event.DeleteEvent) bool {
return false
}

func (i *secretPredicate) Generic(e event.GenericEvent) bool {
return false
}

func (r *SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Secret")
Expand All @@ -62,10 +35,12 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *SecretReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&corev1.Secret{}).
WithEventFilter(&secretPredicate{}).
// we need to handle secrets only when they are updated.
// this is to trigger redeployment of the cluster collector in case of destination secret change.
// when the secret was just created (via auto-scaler restart or initial deployment), the cluster collector will be reconciled by other controllers.
WithEventFilter(predicate.And(&odigospredicate.OnlyUpdatesPredicate{}, &predicate.ResourceVersionChangedPredicate{})).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// DaemonSetReconciler reconciles a DaemonSet object
type DaemonSetReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,resources=daemonsets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=apps,resources=daemonsets/finalizers,verbs=update

func (r *DaemonSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// DeploymentReconciler reconciles a Deployment object
type DeploymentReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=apps,resources=deployments/finalizers,verbs=update

func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func getObjectByOwnerReference(ctx context.Context, k8sClient client.Client, own
return nil, fmt.Errorf("unsupported owner kind %s", ownerRef.Kind)
}

// DeploymentReconciler reconciles a Deployment object
type InstrumentedApplicationReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (i *NsLabelBecameDisabledPredicate) Generic(e event.GenericEvent) bool {
return false
}

// NamespaceReconciler reconciles a Namespace object
type NamespaceReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// StatefulSetReconciler reconciles a StatefulSet object
type StatefulSetReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,resources=statefulsets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=apps,resources=statefulsets/finalizers,verbs=update

func (r *StatefulSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// InstrumentedApplicationReconciler reconciles a InstrumentedApplication object
type InstrumentedApplicationReconciler struct {
client.Client
Scheme *runtime.Scheme
Expand Down
8 changes: 8 additions & 0 deletions k8sutils/pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func podContainerDeviceName(container v1.Container) *string {
}

func AllContainersReady(pod *v1.Pod) bool {
// If pod has no containers, return false as we can't determine readiness
if len(pod.Status.ContainerStatuses) == 0 {
return false
}
// Check if pod is in Running phase.
if pod.Status.Phase != v1.PodRunning {
return false
}
// Iterate over all containers in the pod
// Return false if any container is:
// 1. Not Ready
Expand Down
Loading

0 comments on commit 27591a4

Please sign in to comment.