diff --git a/metrics-operator/api/v1alpha3/keptnmetric_types.go b/metrics-operator/api/v1alpha3/keptnmetric_types.go index d4781566ec0..5b4e5076097 100644 --- a/metrics-operator/api/v1alpha3/keptnmetric_types.go +++ b/metrics-operator/api/v1alpha3/keptnmetric_types.go @@ -79,3 +79,7 @@ type KeptnMetricList struct { func init() { SchemeBuilder.Register(&KeptnMetric{}, &KeptnMetricList{}) } + +func (s *KeptnMetric) IsStatusSet() bool { + return s.Status.Value != "" +} diff --git a/metrics-operator/api/v1alpha3/keptnmetric_types_test.go b/metrics-operator/api/v1alpha3/keptnmetric_types_test.go new file mode 100644 index 00000000000..a7700f4017c --- /dev/null +++ b/metrics-operator/api/v1alpha3/keptnmetric_types_test.go @@ -0,0 +1,53 @@ +package v1alpha3 + +import ( + "testing" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestKeptnMetric_IsStatusSet(t *testing.T) { + type fields struct { + TypeMeta v1.TypeMeta + ObjectMeta v1.ObjectMeta + Spec KeptnMetricSpec + Status KeptnMetricStatus + } + tests := []struct { + name string + fields fields + want bool + }{ + { + name: "No value set", + fields: fields{ + Status: KeptnMetricStatus{ + Value: "", + }, + }, + want: false, + }, + { + name: "we have a value", + fields: fields{ + Status: KeptnMetricStatus{ + Value: "1.0", + }, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &KeptnMetric{ + TypeMeta: tt.fields.TypeMeta, + ObjectMeta: tt.fields.ObjectMeta, + Spec: tt.fields.Spec, + Status: tt.fields.Status, + } + if got := s.IsStatusSet(); got != tt.want { + t.Errorf("IsStatusSet() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/operator/controllers/common/fake/fakeclient.go b/operator/controllers/common/fake/fakeclient.go index c627e2ced30..dd4dc356a1f 100644 --- a/operator/controllers/common/fake/fakeclient.go +++ b/operator/controllers/common/fake/fakeclient.go @@ -1,7 +1,7 @@ package fake import ( - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" lfcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" optionsv1alpha1 "github.com/keptn/lifecycle-toolkit/operator/apis/options/v1alpha1" corev1 "k8s.io/api/core/v1" diff --git a/operator/controllers/common/providers/keptnmetric/keptnmetric.go b/operator/controllers/common/providers/keptnmetric/keptnmetric.go index fd08879a7b1..7cc6ba799d3 100644 --- a/operator/controllers/common/providers/keptnmetric/keptnmetric.go +++ b/operator/controllers/common/providers/keptnmetric/keptnmetric.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-logr/logr" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" "github.com/keptn/lifecycle-toolkit/operator/controllers/common" "k8s.io/apimachinery/pkg/types" diff --git a/operator/controllers/common/providers/keptnmetric/keptnmetric_test.go b/operator/controllers/common/providers/keptnmetric/keptnmetric_test.go index e05cb5919ac..beed84da0ef 100644 --- a/operator/controllers/common/providers/keptnmetric/keptnmetric_test.go +++ b/operator/controllers/common/providers/keptnmetric/keptnmetric_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" "github.com/keptn/lifecycle-toolkit/operator/controllers/common" "github.com/stretchr/testify/require" diff --git a/operator/controllers/lifecycle/keptnevaluation/controller_test.go b/operator/controllers/lifecycle/keptnevaluation/controller_test.go index 06288380956..f63900019f4 100644 --- a/operator/controllers/lifecycle/keptnevaluation/controller_test.go +++ b/operator/controllers/lifecycle/keptnevaluation/controller_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/go-logr/logr" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/operator/controllers/common" diff --git a/operator/go.mod b/operator/go.mod index db9ec631818..ff48966eee2 100644 --- a/operator/go.mod +++ b/operator/go.mod @@ -9,7 +9,7 @@ require ( github.com/imdario/mergo v0.3.15 github.com/kelseyhightower/envconfig v1.4.0 github.com/keptn/lifecycle-toolkit/klt-cert-manager v0.0.0-20230517124521-e381f7fc6d79 - github.com/keptn/lifecycle-toolkit/metrics-operator v0.0.0-20230413082525-dd15d4a0e0e4 + github.com/keptn/lifecycle-toolkit/metrics-operator v0.0.0-20230517134932-24a60f5e6f8f github.com/magiconair/properties v1.8.7 github.com/onsi/ginkgo/v2 v2.9.5 github.com/onsi/gomega v1.27.6 diff --git a/operator/main.go b/operator/main.go index 4c213b959f8..f231943ea11 100644 --- a/operator/main.go +++ b/operator/main.go @@ -28,7 +28,7 @@ import ( "github.com/keptn/lifecycle-toolkit/klt-cert-manager/pkg/certificates" certCommon "github.com/keptn/lifecycle-toolkit/klt-cert-manager/pkg/common" "github.com/keptn/lifecycle-toolkit/klt-cert-manager/pkg/webhook" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" lifecyclev1alpha1 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha1" lifecyclev1alpha2 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2" lifecyclev1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" diff --git a/operator/test/component/common/common.go b/operator/test/component/common/common.go index 6b010ad1f40..3f78d1408a0 100644 --- a/operator/test/component/common/common.go +++ b/operator/test/component/common/common.go @@ -8,7 +8,7 @@ import ( "strings" "time" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/operator/controllers/common" diff --git a/operator/test/component/evaluation/evaluation_test.go b/operator/test/component/evaluation/evaluation_test.go index ba8e41e4f87..9cef2968749 100644 --- a/operator/test/component/evaluation/evaluation_test.go +++ b/operator/test/component/evaluation/evaluation_test.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/operator/controllers/common"