@@ -12,10 +12,6 @@ import (
1212 "strings"
1313 "time"
1414
15- cLog "github.com/DataDog/chaos-controller/log"
16- "github.com/DataDog/chaos-controller/o11y/metrics"
17- "github.com/DataDog/chaos-controller/utils"
18-
1915 "github.com/robfig/cron"
2016 "go.uber.org/zap"
2117 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -26,6 +22,10 @@ import (
2622 ctrl "sigs.k8s.io/controller-runtime"
2723 "sigs.k8s.io/controller-runtime/pkg/webhook"
2824 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
25+
26+ "github.com/DataDog/chaos-controller/o11y/metrics"
27+ tagutil "github.com/DataDog/chaos-controller/o11y/tags"
28+ "github.com/DataDog/chaos-controller/utils"
2929)
3030
3131const (
@@ -48,8 +48,8 @@ func (d *DisruptionCron) SetupWebhookWithManager(setupWebhookConfig utils.SetupW
4848 disruptionCronWebhookRecorder = setupWebhookConfig .Recorder
4949 disruptionCronWebhookDeleteOnly = setupWebhookConfig .DeleteOnlyFlag
5050 disruptionCronWebhookLogger = setupWebhookConfig .Logger .With (
51- "source" , "admission-controller" ,
52- "admission-controller" , "disruption-cron-webhook" ,
51+ tagutil . SourceKey , "admission-controller" ,
52+ tagutil . AdmissionControllerKey , "disruption-cron-webhook" ,
5353 )
5454 disruptionCronMetricsSink = setupWebhookConfig .MetricsSink
5555
@@ -76,7 +76,11 @@ var _ webhook.Defaulter = &DisruptionCron{}
7676// Default implements webhook.Defaulter so a webhook will be registered for the type
7777func (d * DisruptionCron ) Default () {
7878 if d .Spec .DelayedStartTolerance .Duration () == 0 {
79- logger .Infow (fmt .Sprintf ("setting default delayedStartTolerance of %s in disruptionCron" , defaultCronDelayedStartTolerance ), cLog .DisruptionCronNameKey , d .Name , cLog .DisruptionCronNamespaceKey , d .Namespace )
79+ logger .Infow (fmt .Sprintf ("setting default delayedStartTolerance of %s in disruptionCron" , defaultCronDelayedStartTolerance ),
80+ tagutil .DisruptionCronNameKey , d .Name ,
81+ tagutil .DisruptionCronNamespaceKey , d .Namespace ,
82+ )
83+
8084 d .Spec .DelayedStartTolerance = DisruptionDuration (defaultCronDelayedStartTolerance .String ())
8185 }
8286}
@@ -87,16 +91,19 @@ var _ webhook.Validator = &DisruptionCron{}
8791
8892// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
8993func (d * DisruptionCron ) ValidateCreate () (_ admission.Warnings , err error ) {
90- log := disruptionCronWebhookLogger .With (cLog .DisruptionCronNameKey , d .Name , cLog .DisruptionCronNamespaceKey , d .Namespace )
94+ log := disruptionCronWebhookLogger .With (
95+ tagutil .DisruptionCronNameKey , d .Name ,
96+ tagutil .DisruptionCronNamespaceKey , d .Namespace ,
97+ )
9198
92- log .Infow ("validating created disruption cron" , "spec" , d .Spec )
99+ log .Infow ("validating created disruption cron" , tagutil . SpecKey , d .Spec )
93100
94101 metricTags := d .getMetricsTags ()
95102
96103 defer func () {
97104 if err != nil {
98105 if mErr := disruptionCronMetricsSink .MetricValidationFailed (metricTags ); mErr != nil {
99- log .Errorw ("error sending a metric" , "error" , mErr )
106+ log .Errorw ("error sending a metric" , tagutil . ErrorKey , mErr )
100107 }
101108 }
102109 }()
@@ -123,7 +130,7 @@ func (d *DisruptionCron) ValidateCreate() (_ admission.Warnings, err error) {
123130 }
124131
125132 if mErr := metricsSink .MetricValidationCreated (metricTags ); mErr != nil {
126- log .Errorw ("error sending a metric" , "error" , mErr )
133+ log .Errorw ("error sending a metric" , tagutil . ErrorKey , mErr )
127134 }
128135
129136 // send informative event to disruption cron to broadcast
@@ -133,16 +140,18 @@ func (d *DisruptionCron) ValidateCreate() (_ admission.Warnings, err error) {
133140}
134141
135142func (d * DisruptionCron ) ValidateUpdate (oldObject runtime.Object ) (_ admission.Warnings , err error ) {
136- log := logger .With (cLog .DisruptionCronNameKey , d .Name , cLog .DisruptionCronNamespaceKey , d .Namespace )
143+ log := logger .With (
144+ tagutil .DisruptionCronNameKey , d .Name , tagutil .DisruptionCronNamespaceKey , d .Namespace ,
145+ )
137146
138- log .Infow ("validating updated disruption cron" , "spec" , d .Spec )
147+ log .Infow ("validating updated disruption cron" , tagutil . SpecKey , d .Spec )
139148
140149 metricTags := d .getMetricsTags ()
141150
142151 defer func () {
143152 if err != nil {
144153 if mErr := disruptionCronMetricsSink .MetricValidationFailed (metricTags ); mErr != nil {
145- log .Errorw ("error sending a metric" , "error" , mErr )
154+ log .Errorw ("error sending a metric" , tagutil . ErrorKey , mErr )
146155 }
147156 }
148157 }()
@@ -169,7 +178,7 @@ func (d *DisruptionCron) ValidateUpdate(oldObject runtime.Object) (_ admission.W
169178 }
170179
171180 if mErr := metricsSink .MetricValidationUpdated (metricTags ); mErr != nil {
172- log .Errorw ("error sending a metric" , "error" , mErr )
181+ log .Errorw ("error sending a metric" , tagutil . ErrorKey , mErr )
173182 }
174183
175184 // send informative event to disruption cron to broadcast
@@ -179,15 +188,18 @@ func (d *DisruptionCron) ValidateUpdate(oldObject runtime.Object) (_ admission.W
179188}
180189
181190func (d * DisruptionCron ) ValidateDelete () (warnings admission.Warnings , err error ) {
182- log := disruptionCronWebhookLogger .With (cLog .DisruptionCronNameKey , d .Name , cLog .DisruptionCronNamespaceKey , d .Namespace )
191+ log := disruptionCronWebhookLogger .With (
192+ tagutil .DisruptionCronNameKey , d .Name ,
193+ tagutil .DisruptionCronNamespaceKey , d .Namespace ,
194+ )
183195
184- log .Infow ("validating deleted disruption cron" , "spec" , d .Spec )
196+ log .Infow ("validating deleted disruption cron" , tagutil . SpecKey , d .Spec )
185197
186198 // During the validation of the deletion the timestamp does not exist so we need to set it before emitting the event
187199 d .DeletionTimestamp = & metav1.Time {Time : time .Now ()}
188200
189201 if mErr := metricsSink .MetricValidationDeleted (d .getMetricsTags ()); mErr != nil {
190- log .Errorw ("error sending a metric" , "error" , mErr )
202+ log .Errorw ("error sending a metric" , tagutil . ErrorKey , mErr )
191203 }
192204
193205 // send informative event to disruption cron to broadcast
@@ -199,7 +211,7 @@ func (d *DisruptionCron) ValidateDelete() (warnings admission.Warnings, err erro
199211func (d * DisruptionCron ) emitEvent (eventReason EventReason ) {
200212 disruptionCronJSON , err := json .Marshal (d )
201213 if err != nil {
202- disruptionCronWebhookLogger .Errorw ("failed to marshal disruption cron" , "error" , err )
214+ disruptionCronWebhookLogger .Errorw ("failed to marshal disruption cron" , tagutil . ErrorKey , err )
203215 return
204216 }
205217
0 commit comments