-
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(operator): introduce evaluation support for Dynatrace (#194)
BREAKING CHANGE: With API version `v1alpha2`, `KeptnEvaluationProvider` uses a Secret Selector instead of `SecretName`.
- Loading branch information
Showing
14 changed files
with
1,233 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestHasKey(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
provider KeptnEvaluationProvider | ||
result bool | ||
}{ | ||
{ | ||
name: "Correct Definition", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "mysecret", | ||
}, | ||
Key: "mykey", | ||
}, | ||
}, | ||
}, | ||
result: true, | ||
}, | ||
{ | ||
name: "Missing key", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "mysecret", | ||
}, | ||
Key: "", | ||
}, | ||
}, | ||
}, | ||
result: false, | ||
}, | ||
{ | ||
name: "Missing name", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "", | ||
}, | ||
Key: "mykey", | ||
}, | ||
}, | ||
}, | ||
result: false, | ||
}, | ||
{ | ||
name: "Key made by spaces", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "mysecret", | ||
}, | ||
Key: " ", | ||
}, | ||
}, | ||
}, | ||
result: false, | ||
}, | ||
{ | ||
name: "Name made by spaces", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: " ", | ||
}, | ||
Key: "mykey", | ||
}, | ||
}, | ||
}, | ||
result: false, | ||
}, | ||
{ | ||
name: "Empty secret struct", | ||
provider: KeptnEvaluationProvider{ | ||
Spec: KeptnEvaluationProviderSpec{ | ||
TargetServer: "", | ||
SecretKeyRef: corev1.SecretKeySelector{}, | ||
}, | ||
}, | ||
result: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require.Equal(t, tt.result, tt.provider.HasSecretDefined()) | ||
}) | ||
|
||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package keptnevaluation | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"strconv" | ||
|
||
klcv1alpha2 "github.com/keptn/lifecycle-toolkit/operator/api/v1alpha2" | ||
) | ||
|
||
func checkValue(objective klcv1alpha2.Objective, item *klcv1alpha2.EvaluationStatusItem) (bool, error) { | ||
|
||
if len(item.Value) == 0 || len(objective.EvaluationTarget) == 0 { | ||
return false, fmt.Errorf("no values") | ||
} | ||
|
||
eval := objective.EvaluationTarget[1:] | ||
sign := objective.EvaluationTarget[:1] | ||
|
||
resultValue, err := strconv.ParseFloat(item.Value, 64) | ||
if err != nil || math.IsNaN(resultValue) { | ||
return false, err | ||
} | ||
|
||
compareValue, err := strconv.ParseFloat(eval, 64) | ||
if err != nil || math.IsNaN(compareValue) { | ||
return false, err | ||
} | ||
|
||
// choose comparator | ||
switch sign { | ||
case ">": | ||
return resultValue > compareValue, nil | ||
case "<": | ||
return resultValue < compareValue, nil | ||
default: | ||
return false, fmt.Errorf("invalid operator") | ||
} | ||
} |
Oops, something went wrong.