-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add EDS Support #591
Add EDS Support #591
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,10 +21,13 @@ import ( | |||||
"k8s.io/apimachinery/pkg/types" | ||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||||||
|
||||||
edsv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1" | ||||||
) | ||||||
|
||||||
type updateDepStatusComponentFunc func(deployment *appsv1.Deployment, newStatus *datadoghqv2alpha1.DatadogAgentStatus, updateTime metav1.Time, status metav1.ConditionStatus, reason, message string) | ||||||
type updateDSStatusComponentFunc func(daemonset *appsv1.DaemonSet, newStatus *datadoghqv2alpha1.DatadogAgentStatus, updateTime metav1.Time, status metav1.ConditionStatus, reason, message string) | ||||||
type updateEDSStatusComponentFunc func(eds *edsv1alpha1.ExtendedDaemonSet, newStatus *datadoghqv2alpha1.DatadogAgentStatus, updateTime metav1.Time, status metav1.ConditionStatus, reason, message string) | ||||||
|
||||||
func (r *Reconciler) createOrUpdateDeployment(parentLogger logr.Logger, dda *datadoghqv2alpha1.DatadogAgent, deployment *appsv1.Deployment, newStatus *datadoghqv2alpha1.DatadogAgentStatus, updateStatusFunc updateDepStatusComponentFunc) (reconcile.Result, error) { | ||||||
logger := parentLogger.WithValues("deployment.Namespace", deployment.Namespace, "deployment.Name", deployment.Name) | ||||||
|
@@ -181,7 +184,7 @@ func (r *Reconciler) createOrUpdateDaemonset(parentLogger logr.Logger, dda *data | |||||
if err != nil { | ||||||
return reconcile.Result{}, err | ||||||
} | ||||||
event := buildEventInfo(updateDaemonset.Name, updateDaemonset.Namespace, deploymentKind, datadog.UpdateEvent) | ||||||
event := buildEventInfo(updateDaemonset.Name, updateDaemonset.Namespace, daemonSetKind, datadog.UpdateEvent) | ||||||
r.recordEvent(dda, event) | ||||||
updateStatusFunc(updateDaemonset, newStatus, now, metav1.ConditionTrue, "Daemonset_updated", "Daemonset updated") | ||||||
} else { | ||||||
|
@@ -201,3 +204,92 @@ func (r *Reconciler) createOrUpdateDaemonset(parentLogger logr.Logger, dda *data | |||||
|
||||||
return result, err | ||||||
} | ||||||
|
||||||
func (r *Reconciler) createOrUpdateExtendedDaemonset(parentLogger logr.Logger, dda *datadoghqv2alpha1.DatadogAgent, eds *edsv1alpha1.ExtendedDaemonSet, newStatus *datadoghqv2alpha1.DatadogAgentStatus, updateStatusFunc updateEDSStatusComponentFunc) (reconcile.Result, error) { | ||||||
logger := parentLogger.WithValues("ExtendedDaemonSet.Namespace", eds.Namespace, "ExtendedDaemonSet.Name", eds.Name) | ||||||
|
||||||
var result reconcile.Result | ||||||
var err error | ||||||
|
||||||
// Set DatadogAgent instance instance as the owner and controller | ||||||
if err = controllerutil.SetControllerReference(dda, eds, r.scheme); err != nil { | ||||||
return reconcile.Result{}, err | ||||||
} | ||||||
|
||||||
// From here the PodTemplateSpec should be ready, we can generate the hash that will be use to compare this extendeddaemonset with the current (if exist). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var hash string | ||||||
hash, err = comparison.SetMD5DatadogAgentGenerationAnnotation(&eds.ObjectMeta, eds.Spec) | ||||||
if err != nil { | ||||||
return result, err | ||||||
} | ||||||
|
||||||
// Get the current extendeddaemonset and compare | ||||||
nsName := types.NamespacedName{ | ||||||
Name: eds.GetName(), | ||||||
Namespace: eds.GetNamespace(), | ||||||
} | ||||||
|
||||||
currentEDS := &edsv1alpha1.ExtendedDaemonSet{} | ||||||
alreadyExist := true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||||||
err = r.client.Get(context.TODO(), nsName, currentEDS) | ||||||
if err != nil { | ||||||
if apierrors.IsNotFound(err) { | ||||||
logger.Info("ExtendedDaemonSet is not found") | ||||||
alreadyExist = false | ||||||
} else { | ||||||
logger.Error(err, "unexpected error during ExtendedDaemonSet get") | ||||||
return reconcile.Result{}, err | ||||||
} | ||||||
} | ||||||
|
||||||
if alreadyExist { | ||||||
// check if same hash | ||||||
needUpdate := !comparison.IsSameSpecMD5Hash(hash, currentEDS.GetAnnotations()) | ||||||
if !needUpdate { | ||||||
// Even if the EDS is still the same, it's status might have | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// changed (for example, the number of pods ready). This call is | ||||||
// needed to keep the agent status updated. | ||||||
now := metav1.NewTime(time.Now()) | ||||||
newStatus.Agent = datadoghqv2alpha1.UpdateExtendedDaemonSetStatus(currentEDS, newStatus.Agent, &now) | ||||||
|
||||||
// no need to update the EDS to stop here the process | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return reconcile.Result{}, nil | ||||||
} | ||||||
|
||||||
logger.Info("Updating ExtendedDaemonSet") | ||||||
|
||||||
// TODO: these parameter can be added to the override.PodTemplateSpec. (it exist in v1alpha) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
keepAnnotationsFilter := "" | ||||||
keepLabelsFilter := "" | ||||||
|
||||||
// Copy possibly changed fields | ||||||
updateEDS := eds.DeepCopy() | ||||||
updateEDS.Spec = *eds.Spec.DeepCopy() | ||||||
updateEDS.Annotations = mergeAnnotationsLabels(logger, currentEDS.GetAnnotations(), eds.GetAnnotations(), keepAnnotationsFilter) | ||||||
updateEDS.Labels = mergeAnnotationsLabels(logger, currentEDS.GetLabels(), eds.GetLabels(), keepLabelsFilter) | ||||||
|
||||||
now := metav1.NewTime(time.Now()) | ||||||
err = kubernetes.UpdateFromObject(context.TODO(), r.client, updateEDS, currentEDS.ObjectMeta) | ||||||
if err != nil { | ||||||
return reconcile.Result{}, err | ||||||
} | ||||||
event := buildEventInfo(updateEDS.Name, updateEDS.Namespace, extendedDaemonSetKind, datadog.UpdateEvent) | ||||||
r.recordEvent(dda, event) | ||||||
updateStatusFunc(updateEDS, newStatus, now, metav1.ConditionTrue, "Extended_Daemonset_updated", "ExtendedDaemonSet updated") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe? |
||||||
} else { | ||||||
now := metav1.NewTime(time.Now()) | ||||||
|
||||||
err = r.client.Create(context.TODO(), eds) | ||||||
if err != nil { | ||||||
updateStatusFunc(nil, newStatus, now, metav1.ConditionFalse, "create_failed", "Unable to create ExtendedDaemonSet") | ||||||
return reconcile.Result{}, err | ||||||
} | ||||||
event := buildEventInfo(eds.Name, eds.Namespace, extendedDaemonSetKind, datadog.CreationEvent) | ||||||
r.recordEvent(dda, event) | ||||||
updateStatusFunc(eds, newStatus, now, metav1.ConditionTrue, "create_success", "ExtendedDaemonSet created") | ||||||
} | ||||||
|
||||||
logger.Info("Creating ExtendedDaemonSet") | ||||||
|
||||||
return result, err | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.