generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mimir enabled: Delete per cluster heartbeat alertmanagerconfigs
Signed-off-by: QuentinBisson <[email protected]>
- Loading branch information
1 parent
2a9a170
commit 7676c42
Showing
9 changed files
with
151 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
service/controller/resource/alerting/heartbeatwebhookconfig/client.go
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
service/controller/resource/alerting/heartbeatwebhookconfig/create.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package heartbeatwebhookconfig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/giantswarm/microerror" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error { | ||
if r.mimirEnabled { | ||
return r.EnsureDeleted(ctx, obj) | ||
} | ||
|
||
desired, err := r.toAlertmanagerConfig(obj) | ||
if err != nil { | ||
return microerror.Mask(err) | ||
} | ||
|
||
r.logger.Debugf(ctx, "creating") | ||
current, err := r.client.MonitoringV1alpha1().AlertmanagerConfigs(desired.GetNamespace()).Get(ctx, desired.GetName(), metav1.GetOptions{}) | ||
if apierrors.IsNotFound(err) { | ||
current, err = r.client.MonitoringV1alpha1().AlertmanagerConfigs(desired.GetNamespace()).Create(ctx, desired, metav1.CreateOptions{}) | ||
} | ||
|
||
if err != nil { | ||
return microerror.Mask(err) | ||
} | ||
|
||
if r.hasChanged(current, desired) { | ||
updateMeta(current, desired) | ||
_, err = r.client.MonitoringV1alpha1().AlertmanagerConfigs(desired.GetNamespace()).Update(ctx, desired, metav1.UpdateOptions{}) | ||
if err != nil { | ||
return microerror.Mask(err) | ||
} | ||
} | ||
r.logger.Debugf(ctx, "created") | ||
|
||
return nil | ||
} | ||
|
||
func updateMeta(c, d metav1.Object) { | ||
d.SetGenerateName(c.GetGenerateName()) | ||
d.SetUID(c.GetUID()) | ||
d.SetResourceVersion(c.GetResourceVersion()) | ||
d.SetGeneration(c.GetGeneration()) | ||
d.SetSelfLink(c.GetSelfLink()) | ||
d.SetCreationTimestamp(c.GetCreationTimestamp()) | ||
d.SetDeletionTimestamp(c.GetDeletionTimestamp()) | ||
d.SetDeletionGracePeriodSeconds(c.GetDeletionGracePeriodSeconds()) | ||
// without this, it's impossible to change labels on resources | ||
if len(d.GetLabels()) == 0 { | ||
d.SetLabels(c.GetLabels()) | ||
} | ||
// without this, it's impossible to change annotations on resources | ||
if len(d.GetAnnotations()) == 0 { | ||
d.SetAnnotations(c.GetAnnotations()) | ||
} | ||
d.SetFinalizers(c.GetFinalizers()) | ||
d.SetOwnerReferences(c.GetOwnerReferences()) | ||
d.SetManagedFields(c.GetManagedFields()) | ||
} |
27 changes: 27 additions & 0 deletions
27
service/controller/resource/alerting/heartbeatwebhookconfig/delete.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package heartbeatwebhookconfig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/giantswarm/microerror" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (r *Resource) EnsureDeleted(ctx context.Context, obj interface{}) error { | ||
object, err := r.getObjectMeta(obj) | ||
if err != nil { | ||
return microerror.Mask(err) | ||
} | ||
|
||
r.logger.Debugf(ctx, "deleting") | ||
err = r.client.MonitoringV1alpha1().AlertmanagerConfigs(object.GetNamespace()).Delete(ctx, object.GetName(), metav1.DeleteOptions{}) | ||
if apierrors.IsNotFound(err) { | ||
// fall through | ||
} else if err != nil { | ||
return microerror.Mask(err) | ||
} | ||
r.logger.Debugf(ctx, "deleted") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters