Skip to content

Commit

Permalink
call defaulting code (#545)
Browse files Browse the repository at this point in the history
* call defaulting code

* add call to spec defaulting
  • Loading branch information
celenechang committed Jul 13, 2022
1 parent 8a809b6 commit 60b999e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 0 additions & 2 deletions apis/datadoghq/v2alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ const (

// defaultPrometheusScrapeEnabled bool = false
defaultPrometheusScrapeEnableServiceEndpoints bool = false

// defaultDatadogMonitorEnabled bool = false
)

// DefaultDatadogAgent defaults the DatadogAgentSpec GlobalConfig and Features.
Expand Down
6 changes: 5 additions & 1 deletion controllers/datadogagent/controller_reconcile_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func (r *Reconciler) internalReconcileV2(ctx context.Context, request reconcile.
}
*/

return r.reconcileInstanceV2(ctx, reqLogger, instance)
// Set default values for GlobalConfig and Features
instanceCopy := instance.DeepCopy()
datadoghqv2alpha1.DefaultDatadogAgent(instanceCopy)

return r.reconcileInstanceV2(ctx, reqLogger, instanceCopy)
}

func (r *Reconciler) reconcileInstanceV2(ctx context.Context, logger logr.Logger, instance *datadoghqv2alpha1.DatadogAgent) (reconcile.Result, error) {
Expand Down
12 changes: 10 additions & 2 deletions controllers/datadogagent/dependencies/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/DataDog/datadog-operator/pkg/kubernetes"
"github.com/go-logr/logr"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -198,16 +199,23 @@ func (ds *Store) Apply(ctx context.Context, k8sClient client.Client) []error {
err := k8sClient.Get(ctx, objNSName, objAPIServer)
if err != nil && apierrors.IsNotFound(err) {
ds.logger.V(2).Info("dependencies.store Add object to create", "obj.namespace", objStore.GetNamespace(), "obj.name", objStore.GetName(), "obj.kind", kind)
objsToCreate = append(objsToCreate, ds.deps[kind][objID])
objsToCreate = append(objsToCreate, objStore)
continue
} else if err != nil {
errs = append(errs, err)
continue
}

// ServicesKind is a special case; the cluster IPs are immutable and resource version must be set.
if kind == kubernetes.ServicesKind {
objStore.(*v1.Service).Spec.ClusterIP = objAPIServer.(*v1.Service).Spec.ClusterIP
objStore.(*v1.Service).Spec.ClusterIPs = objAPIServer.(*v1.Service).Spec.ClusterIPs
objStore.SetResourceVersion(objAPIServer.GetResourceVersion())
}

if !equality.IsEqualObject(kind, objStore, objAPIServer) {
ds.logger.V(2).Info("dependencies.store Add object to update", "obj.namespace", objStore.GetNamespace(), "obj.name", objStore.GetName(), "obj.kind", kind)
objsToUpdate = append(objsToUpdate, ds.deps[kind][objID])
objsToUpdate = append(objsToUpdate, objStore)
continue
}
}
Expand Down
6 changes: 5 additions & 1 deletion docs/how-to-contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export DD_API_KEY=<api-key>
export DD_APP_KEY=<app-key>
export DD_TOKEN=<32-chars-token>
kubectl -n $KUBE_NAMESPACE create secret generic datadog-secret --from-literal api-key=$DD_API_KEY --from-literal app-key=$DD_APP_KEY --from-literal token=$DD_TOKEN
kubectl -n $KUBE_NAMESPACE create secret generic datadog-secret --from-literal api-key=$DD_API_KEY --from-literal app-key=$DD_APP_KEY
kubectl -n $KUBE_NAMESPACE create secret generic datadog-token --from-literal token=$DD_TOKEN
kubectl -n $KUBE_NAMESPACE apply -f `examples/v2alpha1/min.yaml`
```
Expand Down

0 comments on commit 60b999e

Please sign in to comment.