Skip to content
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 secretRef to PagerDutyProperties #691

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/v1alpha1/humioaction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ type HumioActionOpsGenieProperties struct {

// HumioActionPagerDutyProperties defines the desired state of HumioActionPagerDutyProperties
type HumioActionPagerDutyProperties struct {
RoutingKey string `json:"routingKey,omitempty"`
Severity string `json:"severity,omitempty"`
UseProxy bool `json:"useProxy,omitempty"`
RoutingKey string `json:"routingKey,omitempty"`
RoutingKeySource VarSource `json:"routingKeySource,omitempty"`
Severity string `json:"severity,omitempty"`
UseProxy bool `json:"useProxy,omitempty"`
}

// HumioActionSlackProperties defines the desired state of HumioActionSlackProperties
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions charts/humio-operator/crds/core.humio.com_humioactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ spec:
properties:
routingKey:
type: string
routingKeySource:
properties:
secretKeyRef:
description: SecretKeySelector selects a key of a Secret.
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the Secret or its key must
be defined
type: boolean
required:
- key
type: object
type: object
severity:
type: string
useProxy:
Expand Down
21 changes: 21 additions & 0 deletions config/crd/bases/core.humio.com_humioactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ spec:
properties:
routingKey:
type: string
routingKeySource:
properties:
secretKeyRef:
description: SecretKeySelector selects a key of a Secret.
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the Secret or its key must
be defined
type: boolean
required:
- key
type: object
type: object
severity:
type: string
useProxy:
Expand Down
7 changes: 7 additions & 0 deletions controllers/humioaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ func (r *HumioActionReconciler) resolveSecrets(ctx context.Context, ha *humiov1a
}
}

if ha.Spec.PagerDutyProperties != nil {
ha.Spec.PagerDutyProperties.RoutingKey, err = r.resolveField(ctx, ha.Namespace, ha.Spec.PagerDutyProperties.RoutingKey, ha.Spec.PagerDutyProperties.RoutingKeySource)
if err != nil {
return fmt.Errorf("pagerDutyProperties.routingKeySource.%v", err)
}
}

return nil
}

Expand Down
106 changes: 106 additions & 0 deletions controllers/suite/resources/humioresources_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,112 @@ var _ = Describe("Humio Resources Controllers", func() {
Expect(createdAction.Spec.Name).To(Equal(toCreateAction.Spec.Name))
Expect(createdAction.Spec.SlackPostMessageProperties.ApiToken).To(Equal("direct-token"))
})

It("HumioAction: PagerDutyProperties: Should support referencing secrets", func() {
ctx := context.Background()
key := types.NamespacedName{
Name: "humio-pagerduty-action-secret",
Namespace: clusterKey.Namespace,
}

toCreateAction := &humiov1alpha1.HumioAction{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: humiov1alpha1.HumioActionSpec{
ManagedClusterName: clusterKey.Name,
Name: key.Name,
ViewName: testRepo.Spec.Name,
PagerDutyProperties: &humiov1alpha1.HumioActionPagerDutyProperties{
RoutingKeySource: humiov1alpha1.VarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "action-pagerduty-secret",
},
Key: "key",
},
},
Severity: "critical",
},
},
}

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "action-pagerduty-secret",
Namespace: clusterKey.Namespace,
},
Data: map[string][]byte{
"key": []byte("secret-key"),
},
}

Expect(k8sClient.Create(ctx, secret)).Should(Succeed())
Expect(k8sClient.Create(ctx, toCreateAction)).Should(Succeed())

fetchedAction := &humiov1alpha1.HumioAction{}
Eventually(func() string {
k8sClient.Get(ctx, key, fetchedAction)
return fetchedAction.Status.State
}, testTimeout, suite.TestInterval).Should(Equal(humiov1alpha1.HumioActionStateExists))

var action *humioapi.Action
Eventually(func() error {
action, err = humioClient.GetAction(sharedCluster.Config(), reconcile.Request{NamespacedName: clusterKey}, toCreateAction)
return err
}, testTimeout, suite.TestInterval).Should(Succeed())
Expect(action).ToNot(BeNil())

createdAction, err := humio.CRActionFromAPIAction(action)
Expect(err).To(BeNil())
Expect(createdAction.Spec.Name).To(Equal(toCreateAction.Spec.Name))
Expect(createdAction.Spec.PagerDutyProperties.RoutingKey).To(Equal("secret-key"))
})

It("HumioAction: PagerDutyProperties: Should support direct api token", func() {
ctx := context.Background()
key := types.NamespacedName{
Name: "humio-pagerduty-action-direct",
Namespace: clusterKey.Namespace,
}

toCreateAction := &humiov1alpha1.HumioAction{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: humiov1alpha1.HumioActionSpec{
ManagedClusterName: clusterKey.Name,
Name: key.Name,
ViewName: testRepo.Spec.Name,
PagerDutyProperties: &humiov1alpha1.HumioActionPagerDutyProperties{
RoutingKey: "direct-routing-key",
Severity: "critical",
},
},
}

Expect(k8sClient.Create(ctx, toCreateAction)).Should(Succeed())

fetchedAction := &humiov1alpha1.HumioAction{}
Eventually(func() string {
k8sClient.Get(ctx, key, fetchedAction)
return fetchedAction.Status.State
}, testTimeout, suite.TestInterval).Should(Equal(humiov1alpha1.HumioActionStateExists))

var action *humioapi.Action
Eventually(func() error {
action, err = humioClient.GetAction(sharedCluster.Config(), reconcile.Request{NamespacedName: clusterKey}, toCreateAction)
return err
}, testTimeout, suite.TestInterval).Should(Succeed())
Expect(action).ToNot(BeNil())

createdAction, err := humio.CRActionFromAPIAction(action)
Expect(err).To(BeNil())
Expect(createdAction.Spec.Name).To(Equal(toCreateAction.Spec.Name))
Expect(createdAction.Spec.PagerDutyProperties.RoutingKey).To(Equal("direct-routing-key"))
})
})

Context("Humio Alert", func() {
Expand Down