-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for timeframe in
KeptnMetric
(#1471)
Signed-off-by: Rakshit Gondwal <[email protected]> Signed-off-by: Rakshit Gondwal <[email protected]> Co-authored-by: Florian Bacher <[email protected]>
- Loading branch information
1 parent
b37aed9
commit 4d9ceb7
Showing
20 changed files
with
353 additions
and
11 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
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
143 changes: 143 additions & 0 deletions
143
metrics-operator/api/v1alpha3/keptnmetric_webhook_test.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,143 @@ | ||
package v1alpha3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
|
||
func TestKeptnMetric_validateRangeInterval(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
verb string | ||
Spec KeptnMetricSpec | ||
want error | ||
oldSpec runtime.Object | ||
}{ | ||
{ | ||
name: "create-with-nil-range", | ||
verb: "create", | ||
Spec: KeptnMetricSpec{ | ||
Range: nil, | ||
}, | ||
}, | ||
{ | ||
name: "create-with-wrong-interval", | ||
verb: "create", | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5mins"}, | ||
}, | ||
want: apierrors.NewInvalid( | ||
schema.GroupKind{Group: "metrics.keptn.sh", Kind: "KeptnMetric"}, | ||
"create-with-wrong-interval", | ||
field.ErrorList{ | ||
field.Invalid( | ||
field.NewPath("spec").Child("range").Child("interval"), | ||
"5mins", | ||
"Forbidden! The time interval cannot be parsed. Please check for suitable conventions", | ||
), | ||
}, | ||
), | ||
}, | ||
{ | ||
name: "create-with-empty-interval", | ||
verb: "create", | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: ""}, | ||
}, | ||
want: apierrors.NewInvalid( | ||
schema.GroupKind{Group: "metrics.keptn.sh", Kind: "KeptnMetric"}, | ||
"create-with-empty-interval", | ||
field.ErrorList{ | ||
field.Invalid( | ||
field.NewPath("spec").Child("range").Child("interval"), | ||
"", | ||
"Forbidden! The time interval cannot be parsed. Please check for suitable conventions", | ||
), | ||
}, | ||
), | ||
}, | ||
{ | ||
name: "create-with-right-interval", | ||
verb: "create", | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5m"}, | ||
}, | ||
}, | ||
{ | ||
name: "update-with-right-interval", | ||
verb: "update", | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5m"}, | ||
}, | ||
oldSpec: &KeptnMetric{ | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5mins"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "update-with-wrong-interval", | ||
verb: "update", | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5mins"}, | ||
}, | ||
want: apierrors.NewInvalid( | ||
schema.GroupKind{Group: "metrics.keptn.sh", Kind: "KeptnMetric"}, | ||
"update-with-wrong-interval", | ||
field.ErrorList{ | ||
field.Invalid( | ||
field.NewPath("spec").Child("range").Child("interval"), | ||
"5mins", | ||
"Forbidden! The time interval cannot be parsed. Please check for suitable conventions", | ||
), | ||
}, | ||
), | ||
oldSpec: &KeptnMetric{ | ||
Spec: KeptnMetricSpec{ | ||
Range: &RangeSpec{Interval: "5m"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "delete", | ||
verb: "delete", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var s *KeptnMetric | ||
if tt.Spec.Range == nil { | ||
s = &KeptnMetric{ | ||
ObjectMeta: metav1.ObjectMeta{Name: tt.name}, | ||
Spec: KeptnMetricSpec{Range: tt.Spec.Range}, | ||
} | ||
} else { | ||
s = &KeptnMetric{ | ||
ObjectMeta: metav1.ObjectMeta{Name: tt.name}, | ||
Spec: KeptnMetricSpec{Range: &RangeSpec{Interval: tt.Spec.Range.Interval}}, | ||
} | ||
} | ||
var err error | ||
switch tt.verb { | ||
case "create": | ||
err = s.ValidateCreate() | ||
case "update": | ||
err = s.ValidateUpdate(tt.oldSpec) | ||
case "delete": | ||
err = s.ValidateDelete() | ||
} | ||
if tt.want == nil { | ||
require.Nil(t, err) | ||
} else { | ||
require.Equal(t, tt.want, err) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
23 changes: 23 additions & 0 deletions
23
metrics-operator/config/default/manager_webhook_patch.yaml
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,23 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
ports: | ||
- containerPort: 9443 | ||
name: webhook-server | ||
protocol: TCP | ||
volumeMounts: | ||
- mountPath: /tmp/k8s-webhook-server/serving-certs | ||
name: cert | ||
readOnly: true | ||
volumes: | ||
- name: cert | ||
secret: | ||
defaultMode: 420 | ||
secretName: webhook-server-cert |
Oops, something went wrong.