Skip to content

Commit

Permalink
release: v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Nov 23, 2022
1 parent ef23bc1 commit 93bebe6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ helm repo update
The most recent version is installed via.

```bash
helm install uptrends uptrends/uptrends --create-namespace --namespace uptrends --version v0.0.1-beta.
helm install uptrends uptrends/uptrends --create-namespace --namespace uptrends --version v0.0.1
```

The required `API_USERNAME` and `API_PASSWORD` can be securely configured via `envFrom` in the `values.yaml`.
Expand Down
1 change: 1 addition & 0 deletions exmples/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ spec:
name: service1
port:
number: 80

34 changes: 30 additions & 4 deletions pkg/controller/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ func (c *ingressReconciler) Reconcile(ctx context.Context, r reconcile.Request)
}

func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networkingv1.Ingress) error {
existingMonitors := &v1alpha1.UptrendsList{}
err := c.List(ctx, existingMonitors, client.InNamespace(in.Namespace))
if err != nil {
return err
}

existingNames := make(map[string]v1alpha1.Uptrends)
for _, m := range existingMonitors.Items {
existingNames[m.Name] = m
}

annotations := make(map[string]string)

for k, v := range in.Annotations {
Expand All @@ -95,10 +106,13 @@ func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networki
continue
}

name := fmt.Sprintf("%s-%s", r.Host, in.Name)
delete(existingNames, name)

monitor := &v1alpha1.Uptrends{
ObjectMeta: metav1.ObjectMeta{
Namespace: in.Namespace,
Name: r.Host,
Name: name,
},
Spec: v1alpha1.UptrendsSpec{
Name: fmt.Sprintf("%s - Uptime", r.Host),
Expand Down Expand Up @@ -126,7 +140,7 @@ func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networki
}

existingMonitor := &v1alpha1.Uptrends{}
if utils.IsObjectFound(ctx, c, in.Namespace, r.Host, existingMonitor) {
if utils.IsObjectFound(ctx, c, in.Namespace, name, existingMonitor) {
// this is not DaemonSet is not owned by Octopinger
if ownerRef := metav1.GetControllerOf(existingMonitor); ownerRef == nil || ownerRef.Kind != v1alpha1.CRDResourceKind {
continue
Expand All @@ -149,8 +163,18 @@ func (c *ingressReconciler) reconcileResources(ctx context.Context, in *networki
}
}

// clean up
if len(existingNames) > 0 {
for _, v := range existingNames {
err := c.Delete(ctx, &v)
if err != nil {
return err
}
}
}

in.SetFinalizers(finalizers.AddFinalizer(in, v1alpha1.FinalizerName))
err := c.Update(ctx, in)
err = c.Update(ctx, in)
if err != nil && !errors.IsNotFound(err) {
return err
}
Expand All @@ -176,8 +200,10 @@ func (c *ingressReconciler) reconcileDelete(ctx context.Context, in *networkingv
continue
}

name := fmt.Sprintf("%s-%s", r.Host, in.Name)

m := &v1alpha1.Uptrends{}
err := c.Get(ctx, types.NamespacedName{Namespace: in.Namespace, Name: r.Host}, m)
err := c.Get(ctx, types.NamespacedName{Namespace: in.Namespace, Name: name}, m)
if err != nil && errors.IsNotFound(err) {
continue
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"net/http"

"github.com/ionos-cloud/uptrends-operator/api/v1alpha1"
"github.com/ionos-cloud/uptrends-operator/pkg/credentials"
Expand Down Expand Up @@ -101,8 +102,8 @@ func (m *monitorReconcile) reconcileDelete(ctx context.Context, mon *v1alpha1.Up

client := sw.NewAPIClient(sw.NewConfiguration())

_, err := client.MonitorApi.MonitorDeleteMonitor(auth, mon.Status.MonitorGuid)
if err != nil {
resp, err := client.MonitorApi.MonitorDeleteMonitor(auth, mon.Status.MonitorGuid)
if err != nil && resp.StatusCode != http.StatusNotFound { // assume that this was already deleted
return err
}

Expand Down

0 comments on commit 93bebe6

Please sign in to comment.