From 2d386e6704b68559840ee9b9483384c0c12df385 Mon Sep 17 00:00:00 2001 From: Yuri Tseretyan Date: Mon, 9 Dec 2024 10:29:05 -0500 Subject: [PATCH] Alerting: Migrate notification models to generated by grafnaa-app-sdk (#95430) * create notifications module and generate models * switch template group to app models * switch time intervals to use app models * switch receiver to use app models * switch routing tree to use app models * move schema registration to resource packages * fix package names to match app * fix codeowners * fix UI to use metadata.name instead of uid * update dockerfile * move generated models to pkg * remove provenance from field selector * move client factories to test files * rename GenericClient to TypedClient --- .github/CODEOWNERS | 3 +- Dockerfile | 1 + apps/alerting/common/constants.go | 5 + apps/alerting/notifications/Makefile | 4 +- .../alerting/notifications/cue.mod/module.cue | 1 - apps/alerting/notifications/go.mod | 95 ++ apps/alerting/notifications/go.sum | 203 ++++ .../notifications/kinds/cue.mod/module.cue | 1 + .../notifications/{ => kinds}/receiver.cue | 7 +- .../notifications/{ => kinds}/routingtree.cue | 0 .../notifications/{ => kinds}/template.cue | 5 +- .../{ => kinds}/timeInterval.cue | 3 + .../apis/resource/receiver/v0alpha1/ext.go | 74 ++ .../receiver/v0alpha1/receiver_codec_gen.go | 28 + .../v0alpha1/receiver_metadata_gen.go | 32 + .../receiver/v0alpha1/receiver_object_gen.go | 266 +++++ .../receiver/v0alpha1/receiver_schema_gen.go | 46 + .../receiver/v0alpha1/receiver_spec_gen.go | 18 + .../receiver/v0alpha1/receiver_status_gen.go | 70 ++ .../receiver/v0alpha1/zz_openapi_gen.go | 365 +++++++ .../apis/resource/routingtree/v0alpha1/ext.go | 36 + .../v0alpha1/routingtree_codec_gen.go | 28 + .../v0alpha1/routingtree_metadata_gen.go | 32 + .../v0alpha1/routingtree_object_gen.go | 266 +++++ .../v0alpha1/routingtree_schema_gen.go | 34 + .../v0alpha1/routingtree_spec_gen.go | 12 +- .../v0alpha1/routingtree_status_gen.go | 70 ++ .../routingtree/v0alpha1/zz_openapi_gen.go | 493 +++++++++ .../resource/templategroup/v0alpha1/ext.go | 45 + .../v0alpha1/templategroup_codec_gen.go | 28 + .../v0alpha1/templategroup_metadata_gen.go | 32 + .../v0alpha1/templategroup_object_gen.go | 266 +++++ .../v0alpha1/templategroup_schema_gen.go | 46 + .../v0alpha1/templategroup_spec_gen.go | 6 +- .../v0alpha1/templategroup_status_gen.go | 70 ++ .../templategroup/v0alpha1/zz_openapi_gen.go | 294 ++++++ .../resource/timeinterval/v0alpha1/ext.go | 45 + .../timeinterval/v0alpha1/fakes/gen.go | 27 +- .../v0alpha1/timeinterval_codec_gen.go | 28 + .../v0alpha1/timeinterval_metadata_gen.go | 32 + .../v0alpha1/timeinterval_object_gen.go | 266 +++++ .../v0alpha1/timeinterval_schema_gen.go | 46 + .../v0alpha1/timeinterval_spec_gen.go | 26 + .../v0alpha1/timeinterval_status_gen.go | 70 ++ .../timeinterval/v0alpha1/zz_openapi_gen.go | 422 ++++++++ .../notifications/pkg/apis/resource/type.go | 5 + go.work | 1 + go.work.sum | 23 +- .../alerting_notifications/v0alpha1/doc.go | 6 - .../v0alpha1/receiver_spec.go | 24 - .../v0alpha1/register.go | 222 ----- .../v0alpha1/timeinterval_spec.go | 38 - .../alerting_notifications/v0alpha1/types.go | 340 ------- .../v0alpha1/types_ext.go | 120 --- .../v0alpha1/zz_generated.deepcopy.go | 544 ---------- .../v0alpha1/zz_generated.defaults.go | 19 - .../v0alpha1/zz_generated.openapi.go | 932 ------------------ ...enerated.openapi_violation_exceptions.list | 19 - .../v0alpha1/integration.go | 71 -- .../v0alpha1/interval.go | 83 -- .../v0alpha1/matcher.go | 47 - .../v0alpha1/receiver.go | 202 ---- .../v0alpha1/receiverspec.go | 39 - .../alerting_notifications/v0alpha1/route.go | 111 --- .../v0alpha1/routedefaults.go | 63 -- .../v0alpha1/routingtree.go | 202 ---- .../v0alpha1/routingtreespec.go | 39 - .../v0alpha1/templategroup.go | 202 ---- .../v0alpha1/templategroupspec.go | 34 - .../v0alpha1/timeinterval.go | 202 ---- .../v0alpha1/timeintervalspec.go | 39 - .../v0alpha1/timerange.go | 34 - pkg/generated/applyconfiguration/utils.go | 46 +- .../clientset/versioned/clientset.go | 15 +- .../versioned/fake/clientset_generated.go | 7 - .../clientset/versioned/fake/register.go | 2 - .../clientset/versioned/scheme/register.go | 2 - .../v0alpha1/alerting_notifications_client.go | 108 -- .../alerting_notifications/v0alpha1/doc.go | 6 - .../v0alpha1/fake/doc.go | 6 - .../fake_alerting_notifications_client.go | 38 - .../v0alpha1/fake/fake_receiver.go | 146 --- .../v0alpha1/fake/fake_routingtree.go | 146 --- .../v0alpha1/fake/fake_templategroup.go | 146 --- .../v0alpha1/fake/fake_timeinterval.go | 146 --- .../v0alpha1/generated_expansion.go | 13 - .../v0alpha1/receiver.go | 55 -- .../v0alpha1/routingtree.go | 55 -- .../v0alpha1/templategroup.go | 55 -- .../v0alpha1/timeinterval.go | 55 -- .../alerting_notifications/interface.go | 32 - .../v0alpha1/interface.go | 52 - .../v0alpha1/receiver.go | 76 -- .../v0alpha1/routingtree.go | 76 -- .../v0alpha1/templategroup.go | 76 -- .../v0alpha1/timeinterval.go | 76 -- .../informers/externalversions/factory.go | 6 - .../informers/externalversions/generic.go | 17 +- .../v0alpha1/expansion_generated.go | 37 - .../v0alpha1/receiver.go | 56 -- .../v0alpha1/routingtree.go | 56 -- .../v0alpha1/templategroup.go | 56 -- .../v0alpha1/timeinterval.go | 56 -- .../notifications/receiver/authorize.go | 2 +- .../notifications/receiver/conversions.go | 15 +- .../notifications/receiver/legacy_storage.go | 18 +- .../notifications/receiver/storage.go | 50 +- .../alerting/notifications/receiver/type.go | 62 ++ .../apis/alerting/notifications/register.go | 127 ++- .../authorize.go | 4 +- .../conversions.go | 14 +- .../legacy_storage.go | 40 +- .../{routing_tree => routingtree}/storage.go | 4 +- .../notifications/routingtree/type.go | 29 + .../notifications/template_group/storage.go | 67 -- .../authorize.go | 4 +- .../conversions.go | 12 +- .../legacy_storage.go | 20 +- .../notifications/templategroup/storage.go | 29 + .../notifications/templategroup/type.go | 59 ++ .../notifications/timeinterval/authorize.go | 5 +- .../notifications/timeinterval/conversions.go | 14 +- .../timeinterval/legacy_storage.go | 22 +- .../notifications/timeinterval/storage.go | 50 +- .../notifications/timeinterval/type.go | 59 ++ .../notifications/receivers/receiver_test.go | 174 ++-- .../routing_tree_test.go | 69 +- .../templates_group_test.go | 91 +- .../timeinterval/timeinterval_test.go | 144 +-- pkg/tests/apis/helper.go | 85 ++ .../contact-points/useContactPoints.ts | 2 +- 131 files changed, 4665 insertions(+), 5933 deletions(-) create mode 100644 apps/alerting/common/constants.go delete mode 100644 apps/alerting/notifications/cue.mod/module.cue create mode 100644 apps/alerting/notifications/go.mod create mode 100644 apps/alerting/notifications/go.sum create mode 100644 apps/alerting/notifications/kinds/cue.mod/module.cue rename apps/alerting/notifications/{ => kinds}/receiver.cue (84%) rename apps/alerting/notifications/{ => kinds}/routingtree.cue (100%) rename apps/alerting/notifications/{ => kinds}/template.cue (81%) rename apps/alerting/notifications/{ => kinds}/timeInterval.cue (93%) create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/ext.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_codec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_metadata_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_object_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_schema_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_spec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_status_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/zz_openapi_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/ext.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_codec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_metadata_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_object_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_schema_gen.go rename pkg/apis/alerting_notifications/v0alpha1/routingtree_spec.go => apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_spec_gen.go (84%) create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_status_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/zz_openapi_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/ext.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_codec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_metadata_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_object_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_schema_gen.go rename pkg/apis/alerting_notifications/v0alpha1/templategroup_spec.go => apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_spec_gen.go (54%) create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_status_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/zz_openapi_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/ext.go rename pkg/apis/alerting_notifications/v0alpha1/testing.go => apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/fakes/gen.go (81%) create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_codec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_metadata_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_object_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_schema_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_spec_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_status_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/zz_openapi_gen.go create mode 100644 apps/alerting/notifications/pkg/apis/resource/type.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/doc.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/receiver_spec.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/register.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/timeinterval_spec.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/types.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/types_ext.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/zz_generated.deepcopy.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/zz_generated.defaults.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi.go delete mode 100644 pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi_violation_exceptions.list delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/integration.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/interval.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/matcher.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiver.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiverspec.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/route.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routedefaults.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtree.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtreespec.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroup.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroupspec.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeinterval.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeintervalspec.go delete mode 100644 pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timerange.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/alerting_notifications_client.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/doc.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/doc.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_alerting_notifications_client.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_receiver.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_routingtree.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_templategroup.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_timeinterval.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/generated_expansion.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/receiver.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/routingtree.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/templategroup.go delete mode 100644 pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/timeinterval.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/interface.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/interface.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/receiver.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/routingtree.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/templategroup.go delete mode 100644 pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/timeinterval.go delete mode 100644 pkg/generated/listers/alerting_notifications/v0alpha1/expansion_generated.go delete mode 100644 pkg/generated/listers/alerting_notifications/v0alpha1/receiver.go delete mode 100644 pkg/generated/listers/alerting_notifications/v0alpha1/routingtree.go delete mode 100644 pkg/generated/listers/alerting_notifications/v0alpha1/templategroup.go delete mode 100644 pkg/generated/listers/alerting_notifications/v0alpha1/timeinterval.go create mode 100644 pkg/registry/apis/alerting/notifications/receiver/type.go rename pkg/registry/apis/alerting/notifications/{routing_tree => routingtree}/authorize.go (93%) rename pkg/registry/apis/alerting/notifications/{routing_tree => routingtree}/conversions.go (95%) rename pkg/registry/apis/alerting/notifications/{routing_tree => routingtree}/legacy_storage.go (79%) rename pkg/registry/apis/alerting/notifications/{routing_tree => routingtree}/storage.go (84%) create mode 100644 pkg/registry/apis/alerting/notifications/routingtree/type.go delete mode 100644 pkg/registry/apis/alerting/notifications/template_group/storage.go rename pkg/registry/apis/alerting/notifications/{template_group => templategroup}/authorize.go (94%) rename pkg/registry/apis/alerting/notifications/{template_group => templategroup}/conversions.go (84%) rename pkg/registry/apis/alerting/notifications/{template_group => templategroup}/legacy_storage.go (89%) create mode 100644 pkg/registry/apis/alerting/notifications/templategroup/storage.go create mode 100644 pkg/registry/apis/alerting/notifications/templategroup/type.go create mode 100644 pkg/registry/apis/alerting/notifications/timeinterval/type.go rename pkg/tests/apis/alerting/notifications/{routing_tree => routingtree}/routing_tree_test.go (92%) rename pkg/tests/apis/alerting/notifications/{template_group => templategroup}/templates_group_test.go (89%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c0d29e120fb..db375717784 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -66,11 +66,10 @@ /scripts/go-workspace @grafana/grafana-app-platform-squad /hack/ @grafana/grafana-app-platform-squad -/apps/alerting/ @grafana/alerting-backend +/apps/alerting/ @grafana/alerting-backend @grafana/alerting-frontend /apps/playlist/ @grafana/grafana-app-platform-squad /pkg/api/ @grafana/grafana-backend-group /pkg/apis/ @grafana/grafana-app-platform-squad -/pkg/apis/alerting_notifications @grafana/grafana-app-platform-squad @grafana/alerting-backend @grafana/alerting-frontend /pkg/apis/query @grafana/grafana-datasources-core-services /pkg/apis/userstorage @grafana/grafana-app-platform-squad @grafana/plugins-platform-backend /pkg/bus/ @grafana/grafana-search-and-storage diff --git a/Dockerfile b/Dockerfile index 6feabfdc747..dc326221eb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,6 +69,7 @@ COPY pkg/aggregator/go.* pkg/aggregator/ COPY apps/playlist/go.* apps/playlist/ COPY apps apps COPY kindsv2 kindsv2 +COPY apps/alerting/notifications/go.* apps/alerting/notifications/ RUN go mod download RUN if [[ "$BINGO" = "true" ]]; then \ diff --git a/apps/alerting/common/constants.go b/apps/alerting/common/constants.go new file mode 100644 index 00000000000..2cc7c413276 --- /dev/null +++ b/apps/alerting/common/constants.go @@ -0,0 +1,5 @@ +package common + +const InternalPrefix = "grafana.com/" +const ProvenanceStatusAnnotationKey = InternalPrefix + "provenance" +const ProvenanceStatusNone = "none" diff --git a/apps/alerting/notifications/Makefile b/apps/alerting/notifications/Makefile index 4fcd5fddd83..3b90bb0f6fb 100644 --- a/apps/alerting/notifications/Makefile +++ b/apps/alerting/notifications/Makefile @@ -1,4 +1,4 @@ .PHONY: generate generate: - ## --crdencoding none is needed to avoid infinite loop while generating recursive models' - grafana-app-sdk generate -c . -g ./apis --crdencoding none + ## --crdencoding none is needed to avoid infinite loop while generating recursive models (see routingtree.cue) + grafana-app-sdk generate -g ./pkg/apis --crdencoding none --nomanifest --postprocess diff --git a/apps/alerting/notifications/cue.mod/module.cue b/apps/alerting/notifications/cue.mod/module.cue deleted file mode 100644 index d5f6f45c25e..00000000000 --- a/apps/alerting/notifications/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module:"notifications" \ No newline at end of file diff --git a/apps/alerting/notifications/go.mod b/apps/alerting/notifications/go.mod new file mode 100644 index 00000000000..a50b6c21745 --- /dev/null +++ b/apps/alerting/notifications/go.mod @@ -0,0 +1,95 @@ +module github.com/grafana/grafana/apps/alerting/notifications + +go 1.23.1 + +require ( + github.com/grafana/grafana-app-sdk v0.23.1 + k8s.io/apimachinery v0.31.1 + k8s.io/apiserver v0.31.1 + k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 +) + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/blang/semver/v4 v4.0.0 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/coreos/go-semver v0.3.1 // indirect + github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/btree v1.1.2 // indirect + github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/google/gofuzz v1.2.0 // indirect + github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/gorilla/websocket v1.5.3 // indirect + github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect + github.com/jonboulle/clockwork v0.4.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/onsi/gomega v1.34.1 // indirect + github.com/prometheus/client_golang v1.20.5 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.60.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/x448/float16 v0.8.4 // indirect + go.etcd.io/bbolt v1.3.10 // indirect + go.etcd.io/etcd/api/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/v3 v3.5.14 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/sdk v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect + go.opentelemetry.io/proto/otlp v1.3.1 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect + golang.org/x/text v0.19.0 // indirect + golang.org/x/time v0.6.0 // indirect + google.golang.org/genproto v0.0.0-20240820151423-278611b39280 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/api v0.31.1 // indirect + k8s.io/client-go v0.31.1 // indirect + k8s.io/component-base v0.31.1 // indirect + k8s.io/klog/v2 v2.130.1 // indirect + k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect + sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect + sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect +) diff --git a/apps/alerting/notifications/go.sum b/apps/alerting/notifications/go.sum new file mode 100644 index 00000000000..7b660a3834e --- /dev/null +++ b/apps/alerting/notifications/go.sum @@ -0,0 +1,203 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= +github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= +github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= +github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= +github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da h1:xRmpO92tb8y+Z85iUOMOicpCfaYcv7o3Cg3wKrIpg8g= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/grafana/grafana-app-sdk v0.23.1 h1:BRpUG0bA0oVxjthkmO2thuJBo3nbjaRSSmZJHw+mA8I= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 h1:uGoIog/wiQHI9GAxXO5TJbT0wWKH3O9HhOJW1F9c3fY= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= +github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= +go.etcd.io/etcd/api/v3 v3.5.14 h1:vHObSCxyB9zlF60w7qzAdTcGaglbJOpSj1Xj9+WGxq0= +go.etcd.io/etcd/client/pkg/v3 v3.5.14 h1:SaNH6Y+rVEdxfpA2Jr5wkEvN6Zykme5+YnbCkxvuWxQ= +go.etcd.io/etcd/client/v2 v2.305.13 h1:RWfV1SX5jTU0lbCvpVQe3iPQeAHETWdOTb6pxhd77C8= +go.etcd.io/etcd/client/v3 v3.5.14 h1:CWfRs4FDaDoSz81giL7zPpZH2Z35tbOrAJkkjMqOupg= +go.etcd.io/etcd/pkg/v3 v3.5.13 h1:st9bDWNsKkBNpP4PR1MvM/9NqUPfvYZx/YXegsYEH8M= +go.etcd.io/etcd/raft/v3 v3.5.13 h1:7r/NKAOups1YnKcfro2RvGGo2PTuizF/xh26Z2CTAzA= +go.etcd.io/etcd/server/v3 v3.5.13 h1:V6KG+yMfMSqWt+lGnhFpP5z5dRUj1BDRJ5k1fQ9DFok= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 h1:yMkBS9yViCc7U7yeLzJPM2XizlfdVvBRSmsQDWu6qc0= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 h1:K0XaT3DwHAcV4nKLzcQvwAgSyisUghWoY20I7huthMk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0 h1:FFeLy03iVTXP6ffeN2iXrxfGsZGCjVx0/4KlizjyBwU= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20240820151423-278611b39280 h1:oKt8r1ZvaPqBe3oeGTdyx1iNjuBS+VJcc9QdU1CD3d8= +google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 h1:T6rh4haD3GVYsgEfWExoCZA2o2FmbNyKpTuAxbEFPTg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU= +k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI= +k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U= +k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/apiserver v0.31.1 h1:Sars5ejQDCRBY5f7R3QFHdqN3s61nhkpaX8/k1iEw1c= +k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0= +k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg= +k8s.io/component-base v0.31.1 h1:UpOepcrX3rQ3ab5NB6g5iP0tvsgJWzxTyAo20sgYSy8= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= +k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY= +sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= +sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= +sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= +sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/apps/alerting/notifications/kinds/cue.mod/module.cue b/apps/alerting/notifications/kinds/cue.mod/module.cue new file mode 100644 index 00000000000..c39c695111f --- /dev/null +++ b/apps/alerting/notifications/kinds/cue.mod/module.cue @@ -0,0 +1 @@ +module: "github.com/grafana/grafana/apps/alerting/notifications/kinds" \ No newline at end of file diff --git a/apps/alerting/notifications/receiver.cue b/apps/alerting/notifications/kinds/receiver.cue similarity index 84% rename from apps/alerting/notifications/receiver.cue rename to apps/alerting/notifications/kinds/receiver.cue index 3fe31a26684..6e2533e7523 100644 --- a/apps/alerting/notifications/receiver.cue +++ b/apps/alerting/notifications/kinds/receiver.cue @@ -19,7 +19,9 @@ receiver: { uid?: string type: string disableResolveMessage?: bool - settings: bytes + settings: { + [string]: _ + } secureFields?: [string]: bool } spec: { @@ -27,6 +29,9 @@ receiver: { integrations : [...#Integration] } } + selectableFields: [ + "spec.title", + ] } } } diff --git a/apps/alerting/notifications/routingtree.cue b/apps/alerting/notifications/kinds/routingtree.cue similarity index 100% rename from apps/alerting/notifications/routingtree.cue rename to apps/alerting/notifications/kinds/routingtree.cue diff --git a/apps/alerting/notifications/template.cue b/apps/alerting/notifications/kinds/template.cue similarity index 81% rename from apps/alerting/notifications/template.cue rename to apps/alerting/notifications/kinds/template.cue index 56c2507cd1e..c7c323fd2c0 100644 --- a/apps/alerting/notifications/template.cue +++ b/apps/alerting/notifications/kinds/template.cue @@ -10,7 +10,7 @@ templateGroup: { frontend: false backend: true } - pluralName: "TemplatesGroups" + pluralName: "TemplateGroups" current: "v0alpha1" versions: { "v0alpha1": { @@ -20,6 +20,9 @@ templateGroup: { content: string } } + selectableFields: [ + "spec.title", + ] } } } diff --git a/apps/alerting/notifications/timeInterval.cue b/apps/alerting/notifications/kinds/timeInterval.cue similarity index 93% rename from apps/alerting/notifications/timeInterval.cue rename to apps/alerting/notifications/kinds/timeInterval.cue index 04bff2c995e..8e50639dc17 100644 --- a/apps/alerting/notifications/timeInterval.cue +++ b/apps/alerting/notifications/kinds/timeInterval.cue @@ -32,6 +32,9 @@ timeInterval: { time_intervals: [...#Interval] } } + selectableFields: [ + "spec.name", + ] } } } \ No newline at end of file diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/ext.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/ext.go new file mode 100644 index 00000000000..da17a9f55df --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/ext.go @@ -0,0 +1,74 @@ +package v0alpha1 + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apiserver/pkg/registry/generic" + + "github.com/grafana/grafana/apps/alerting/common" +) + +func (o *Receiver) GetProvenanceStatus() string { + if o == nil || o.Annotations == nil { + return "" + } + s, ok := o.Annotations[common.ProvenanceStatusAnnotationKey] + if !ok || s == "" { + return common.ProvenanceStatusNone + } + return s +} + +func (o *Receiver) SetProvenanceStatus(status string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 1) + } + if status == "" { + status = common.ProvenanceStatusNone + } + o.Annotations[common.ProvenanceStatusAnnotationKey] = status +} + +func (o *Receiver) SetAccessControl(action string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 1) + } + o.Annotations[AccessControlAnnotation(action)] = "true" +} + +// AccessControlAnnotation returns the key for the access control annotation for the given action. +// Ex. grafana.com/access/canDelete. +func AccessControlAnnotation(action string) string { + return fmt.Sprintf("%s%s/%s", common.InternalPrefix, "access", action) +} + +func (o *Receiver) SetInUse(routesCnt int, rules []string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 2) + } + o.Annotations[InUseAnnotation("routes")] = fmt.Sprintf("%d", routesCnt) + o.Annotations[InUseAnnotation("rules")] = fmt.Sprintf("%d", len(rules)) +} + +// InUseAnnotation returns the key for the in-use annotation for the given resource. +// Ex. grafana.com/inUse/routes, grafana.com/inUse/rules. +func InUseAnnotation(resource string) string { + return fmt.Sprintf("%s%s/%s", common.InternalPrefix, "inUse", resource) +} + +func SelectableFields(obj *Receiver) fields.Set { + if obj == nil { + return nil + } + selectable := Schema().SelectableFields() + set := make(fields.Set, len(selectable)) + for _, field := range selectable { + f, err := field.FieldValueFunc(obj) + if err != nil { + continue + } + set[field.FieldSelector] = f + } + return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), set) +} diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_codec_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_codec_gen.go new file mode 100644 index 00000000000..7b5050a3af4 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_codec_gen.go @@ -0,0 +1,28 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "encoding/json" + "io" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// JSONCodec is an implementation of resource.Codec for kubernetes JSON encoding +type JSONCodec struct{} + +// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into` +func (*JSONCodec) Read(reader io.Reader, into resource.Object) error { + return json.NewDecoder(reader).Decode(into) +} + +// Write writes JSON-encoded bytes into `writer` marshaled from `from` +func (*JSONCodec) Write(writer io.Writer, from resource.Object) error { + return json.NewEncoder(writer).Encode(from) +} + +// Interface compliance checks +var _ resource.Codec = &JSONCodec{} diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_metadata_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_metadata_gen.go new file mode 100644 index 00000000000..24b09a76c08 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_metadata_gen.go @@ -0,0 +1,32 @@ +package v0alpha1 + +import ( + "time" +) + +// Metadata defines model for Metadata. +type Metadata struct { + CreatedBy string `json:"createdBy"` + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` + UpdateTimestamp time.Time `json:"updateTimestamp"` + UpdatedBy string `json:"updatedBy"` +} + +// _kubeObjectMetadata is metadata found in a kubernetes object's metadata field. +// It is not exhaustive and only includes fields which may be relevant to a kind's implementation, +// As it is also intended to be generic enough to function with any API Server. +type KubeObjectMetadata struct { + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_object_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_object_gen.go new file mode 100644 index 00000000000..e3a215207b3 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_object_gen.go @@ -0,0 +1,266 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + "github.com/grafana/grafana-app-sdk/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "time" +) + +// +k8s:openapi-gen=true +type Receiver struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec Spec `json:"spec"` + Status Status `json:"status"` +} + +func (o *Receiver) GetSpec() any { + return o.Spec +} + +func (o *Receiver) SetSpec(spec any) error { + cast, ok := spec.(Spec) + if !ok { + return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) + } + o.Spec = cast + return nil +} + +func (o *Receiver) GetSubresources() map[string]any { + return map[string]any{ + "status": o.Status, + } +} + +func (o *Receiver) GetSubresource(name string) (any, bool) { + switch name { + case "status": + return o.Status, true + default: + return nil, false + } +} + +func (o *Receiver) SetSubresource(name string, value any) error { + switch name { + case "status": + cast, ok := value.(Status) + if !ok { + return fmt.Errorf("cannot set status type %#v, not of type Status", value) + } + o.Status = cast + return nil + default: + return fmt.Errorf("subresource '%s' does not exist", name) + } +} + +func (o *Receiver) GetStaticMetadata() resource.StaticMetadata { + gvk := o.GroupVersionKind() + return resource.StaticMetadata{ + Name: o.ObjectMeta.Name, + Namespace: o.ObjectMeta.Namespace, + Group: gvk.Group, + Version: gvk.Version, + Kind: gvk.Kind, + } +} + +func (o *Receiver) SetStaticMetadata(metadata resource.StaticMetadata) { + o.Name = metadata.Name + o.Namespace = metadata.Namespace + o.SetGroupVersionKind(schema.GroupVersionKind{ + Group: metadata.Group, + Version: metadata.Version, + Kind: metadata.Kind, + }) +} + +func (o *Receiver) GetCommonMetadata() resource.CommonMetadata { + dt := o.DeletionTimestamp + var deletionTimestamp *time.Time + if dt != nil { + deletionTimestamp = &dt.Time + } + // Legacy ExtraFields support + extraFields := make(map[string]any) + if o.Annotations != nil { + extraFields["annotations"] = o.Annotations + } + if o.ManagedFields != nil { + extraFields["managedFields"] = o.ManagedFields + } + if o.OwnerReferences != nil { + extraFields["ownerReferences"] = o.OwnerReferences + } + return resource.CommonMetadata{ + UID: string(o.UID), + ResourceVersion: o.ResourceVersion, + Generation: o.Generation, + Labels: o.Labels, + CreationTimestamp: o.CreationTimestamp.Time, + DeletionTimestamp: deletionTimestamp, + Finalizers: o.Finalizers, + UpdateTimestamp: o.GetUpdateTimestamp(), + CreatedBy: o.GetCreatedBy(), + UpdatedBy: o.GetUpdatedBy(), + ExtraFields: extraFields, + } +} + +func (o *Receiver) SetCommonMetadata(metadata resource.CommonMetadata) { + o.UID = types.UID(metadata.UID) + o.ResourceVersion = metadata.ResourceVersion + o.Generation = metadata.Generation + o.Labels = metadata.Labels + o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp) + if metadata.DeletionTimestamp != nil { + dt := metav1.NewTime(*metadata.DeletionTimestamp) + o.DeletionTimestamp = &dt + } else { + o.DeletionTimestamp = nil + } + o.Finalizers = metadata.Finalizers + if o.Annotations == nil { + o.Annotations = make(map[string]string) + } + if !metadata.UpdateTimestamp.IsZero() { + o.SetUpdateTimestamp(metadata.UpdateTimestamp) + } + if metadata.CreatedBy != "" { + o.SetCreatedBy(metadata.CreatedBy) + } + if metadata.UpdatedBy != "" { + o.SetUpdatedBy(metadata.UpdatedBy) + } + // Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields + if metadata.ExtraFields != nil { + if annotations, ok := metadata.ExtraFields["annotations"]; ok { + if cast, ok := annotations.(map[string]string); ok { + o.Annotations = cast + } + } + if managedFields, ok := metadata.ExtraFields["managedFields"]; ok { + if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok { + o.ManagedFields = cast + } + } + if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok { + if cast, ok := ownerReferences.([]metav1.OwnerReference); ok { + o.OwnerReferences = cast + } + } + } +} + +func (o *Receiver) GetCreatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/createdBy"] +} + +func (o *Receiver) SetCreatedBy(createdBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy +} + +func (o *Receiver) GetUpdateTimestamp() time.Time { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) + return parsed +} + +func (o *Receiver) SetUpdateTimestamp(updateTimestamp time.Time) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) +} + +func (o *Receiver) GetUpdatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/updatedBy"] +} + +func (o *Receiver) SetUpdatedBy(updatedBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy +} + +func (o *Receiver) Copy() resource.Object { + return resource.CopyObject(o) +} + +func (o *Receiver) DeepCopyObject() runtime.Object { + return o.Copy() +} + +// Interface compliance compile-time check +var _ resource.Object = &Receiver{} + +// +k8s:openapi-gen=true +type ReceiverList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []Receiver `json:"items"` +} + +func (o *ReceiverList) DeepCopyObject() runtime.Object { + return o.Copy() +} + +func (o *ReceiverList) Copy() resource.ListObject { + cpy := &ReceiverList{ + TypeMeta: o.TypeMeta, + Items: make([]Receiver, len(o.Items)), + } + o.ListMeta.DeepCopyInto(&cpy.ListMeta) + for i := 0; i < len(o.Items); i++ { + if item, ok := o.Items[i].Copy().(*Receiver); ok { + cpy.Items[i] = *item + } + } + return cpy +} + +func (o *ReceiverList) GetItems() []resource.Object { + items := make([]resource.Object, len(o.Items)) + for i := 0; i < len(o.Items); i++ { + items[i] = &o.Items[i] + } + return items +} + +func (o *ReceiverList) SetItems(items []resource.Object) { + o.Items = make([]Receiver, len(items)) + for i := 0; i < len(items); i++ { + o.Items[i] = *items[i].(*Receiver) + } +} + +// Interface compliance compile-time check +var _ resource.ListObject = &ReceiverList{} diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_schema_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_schema_gen.go new file mode 100644 index 00000000000..48b5d72fbd9 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_schema_gen.go @@ -0,0 +1,46 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// schema is unexported to prevent accidental overwrites +var ( + schemaReceiver = resource.NewSimpleSchema("notifications.alerting.grafana.app", "v0alpha1", &Receiver{}, &ReceiverList{}, resource.WithKind("Receiver"), + resource.WithPlural("receivers"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{resource.SelectableField{ + FieldSelector: "spec.title", + FieldValueFunc: func(o resource.Object) (string, error) { + cast, ok := o.(*Receiver) + if !ok { + return "", fmt.Errorf("provided object must be of type *Receiver") + } + return cast.Spec.Title, nil + }, + }, + })) + kindReceiver = resource.Kind{ + Schema: schemaReceiver, + Codecs: map[resource.KindEncoding]resource.Codec{ + resource.KindEncodingJSON: &JSONCodec{}, + }, + } +) + +// Kind returns a resource.Kind for this Schema with a JSON codec +func Kind() resource.Kind { + return kindReceiver +} + +// Schema returns a resource.SimpleSchema representation of Receiver +func Schema() *resource.SimpleSchema { + return schemaReceiver +} + +// Interface compliance checks +var _ resource.Schema = kindReceiver diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_spec_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_spec_gen.go new file mode 100644 index 00000000000..f65ec727299 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_spec_gen.go @@ -0,0 +1,18 @@ +package v0alpha1 + +// Integration defines model for Integration. +// +k8s:openapi-gen=true +type Integration struct { + DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"` + SecureFields map[string]bool `json:"secureFields,omitempty"` + Settings map[string]interface{} `json:"settings"` + Type string `json:"type"` + Uid *string `json:"uid,omitempty"` +} + +// Spec defines model for Spec. +// +k8s:openapi-gen=true +type Spec struct { + Integrations []Integration `json:"integrations"` + Title string `json:"title"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_status_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_status_gen.go new file mode 100644 index 00000000000..6cf30ace059 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/receiver_status_gen.go @@ -0,0 +1,70 @@ +package v0alpha1 + +// Defines values for OperatorStateState. +const ( + OperatorStateStateFailed OperatorStateState = "failed" + OperatorStateStateInProgress OperatorStateState = "in_progress" + OperatorStateStateSuccess OperatorStateState = "success" +) + +// Defines values for StatusOperatorStateState. +const ( + StatusOperatorStateStateFailed StatusOperatorStateState = "failed" + StatusOperatorStateStateInProgress StatusOperatorStateState = "in_progress" + StatusOperatorStateStateSuccess StatusOperatorStateState = "success" +) + +// OperatorState defines model for OperatorState. +// +k8s:openapi-gen=true +type OperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State OperatorStateState `json:"state"` +} + +// OperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type OperatorStateState string + +// Status defines model for Status. +// +k8s:openapi-gen=true +type Status struct { + // additionalFields is reserved for future use + AdditionalFields map[string]interface{} `json:"additionalFields,omitempty"` + + // operatorStates is a map of operator ID to operator state evaluations. + // Any operator which consumes this kind SHOULD add its state evaluation information to this field. + OperatorStates map[string]StatusOperatorState `json:"operatorStates,omitempty"` +} + +// StatusOperatorState defines model for status.#OperatorState. +// +k8s:openapi-gen=true +type StatusOperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State StatusOperatorStateState `json:"state"` +} + +// StatusOperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type StatusOperatorStateState string diff --git a/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/zz_openapi_gen.go b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/zz_openapi_gen.go new file mode 100644 index 00000000000..d9d707e4deb --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1/zz_openapi_gen.go @@ -0,0 +1,365 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by grafana-app-sdk. DO NOT EDIT. + +package v0alpha1 + +import ( + common "k8s.io/kube-openapi/pkg/common" + spec "k8s.io/kube-openapi/pkg/validation/spec" +) + +func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { + return map[string]common.OpenAPIDefinition{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Integration": schema_apis_resource_receiver_v0alpha1_Integration(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.OperatorState": schema_apis_resource_receiver_v0alpha1_OperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Receiver": schema_apis_resource_receiver_v0alpha1_Receiver(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.ReceiverList": schema_apis_resource_receiver_v0alpha1_ReceiverList(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Spec": schema_apis_resource_receiver_v0alpha1_Spec(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Status": schema_apis_resource_receiver_v0alpha1_Status(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.StatusOperatorState": schema_apis_resource_receiver_v0alpha1_StatusOperatorState(ref), + } +} + +func schema_apis_resource_receiver_v0alpha1_Integration(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Integration defines model for Integration.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "disableResolveMessage": { + SchemaProps: spec.SchemaProps{ + Type: []string{"boolean"}, + Format: "", + }, + }, + "secureFields": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, + }, + }, + }, + "settings": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "type": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "uid": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"settings", "type"}, + }, + }, + } +} + +func schema_apis_resource_receiver_v0alpha1_OperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "OperatorState defines model for OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_receiver_v0alpha1_Receiver(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Spec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Status"), + }, + }, + }, + Required: []string{"metadata", "spec", "status"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Spec", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Status", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_apis_resource_receiver_v0alpha1_ReceiverList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Receiver"), + }, + }, + }, + }, + }, + }, + Required: []string{"metadata", "items"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Receiver", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_apis_resource_receiver_v0alpha1_Spec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Spec defines model for Spec.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "integrations": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Integration"), + }, + }, + }, + }, + }, + "title": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"integrations", "title"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.Integration"}, + } +} + +func schema_apis_resource_receiver_v0alpha1_Status(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Status defines model for Status.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "additionalFields": { + SchemaProps: spec.SchemaProps{ + Description: "additionalFields is reserved for future use", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "operatorStates": { + SchemaProps: spec.SchemaProps{ + Description: "operatorStates is a map of operator ID to operator state evaluations. Any operator which consumes this kind SHOULD add its state evaluation information to this field.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.StatusOperatorState"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1.StatusOperatorState"}, + } +} + +func schema_apis_resource_receiver_v0alpha1_StatusOperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "StatusOperatorState defines model for status.#OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/ext.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/ext.go new file mode 100644 index 00000000000..c4f4fb4475d --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/ext.go @@ -0,0 +1,36 @@ +package v0alpha1 + +import ( + "github.com/grafana/grafana/apps/alerting/common" +) + +// Re-define some enum values with confusing names +// TODO figure out how we can control name of enum +const ( + MatcherTypeNotEqual MatcherType = "!=" + MatcherTypeEqualRegex MatcherType = "=~" + MatcherTypeNotEqualRegex MatcherType = "!~" +) + +const UserDefinedRoutingTreeName = "user-defined" + +func (o *RoutingTree) GetProvenanceStatus() string { + if o == nil || o.Annotations == nil { + return "" + } + s, ok := o.Annotations[common.ProvenanceStatusAnnotationKey] + if !ok || s == "" { + return common.ProvenanceStatusNone + } + return s +} + +func (o *RoutingTree) SetProvenanceStatus(status string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 1) + } + if status == "" { + status = common.ProvenanceStatusNone + } + o.Annotations[common.ProvenanceStatusAnnotationKey] = status +} diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_codec_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_codec_gen.go new file mode 100644 index 00000000000..7b5050a3af4 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_codec_gen.go @@ -0,0 +1,28 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "encoding/json" + "io" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// JSONCodec is an implementation of resource.Codec for kubernetes JSON encoding +type JSONCodec struct{} + +// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into` +func (*JSONCodec) Read(reader io.Reader, into resource.Object) error { + return json.NewDecoder(reader).Decode(into) +} + +// Write writes JSON-encoded bytes into `writer` marshaled from `from` +func (*JSONCodec) Write(writer io.Writer, from resource.Object) error { + return json.NewEncoder(writer).Encode(from) +} + +// Interface compliance checks +var _ resource.Codec = &JSONCodec{} diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_metadata_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_metadata_gen.go new file mode 100644 index 00000000000..24b09a76c08 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_metadata_gen.go @@ -0,0 +1,32 @@ +package v0alpha1 + +import ( + "time" +) + +// Metadata defines model for Metadata. +type Metadata struct { + CreatedBy string `json:"createdBy"` + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` + UpdateTimestamp time.Time `json:"updateTimestamp"` + UpdatedBy string `json:"updatedBy"` +} + +// _kubeObjectMetadata is metadata found in a kubernetes object's metadata field. +// It is not exhaustive and only includes fields which may be relevant to a kind's implementation, +// As it is also intended to be generic enough to function with any API Server. +type KubeObjectMetadata struct { + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_object_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_object_gen.go new file mode 100644 index 00000000000..c1823a29c62 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_object_gen.go @@ -0,0 +1,266 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + "github.com/grafana/grafana-app-sdk/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "time" +) + +// +k8s:openapi-gen=true +type RoutingTree struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec Spec `json:"spec"` + Status Status `json:"status"` +} + +func (o *RoutingTree) GetSpec() any { + return o.Spec +} + +func (o *RoutingTree) SetSpec(spec any) error { + cast, ok := spec.(Spec) + if !ok { + return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) + } + o.Spec = cast + return nil +} + +func (o *RoutingTree) GetSubresources() map[string]any { + return map[string]any{ + "status": o.Status, + } +} + +func (o *RoutingTree) GetSubresource(name string) (any, bool) { + switch name { + case "status": + return o.Status, true + default: + return nil, false + } +} + +func (o *RoutingTree) SetSubresource(name string, value any) error { + switch name { + case "status": + cast, ok := value.(Status) + if !ok { + return fmt.Errorf("cannot set status type %#v, not of type Status", value) + } + o.Status = cast + return nil + default: + return fmt.Errorf("subresource '%s' does not exist", name) + } +} + +func (o *RoutingTree) GetStaticMetadata() resource.StaticMetadata { + gvk := o.GroupVersionKind() + return resource.StaticMetadata{ + Name: o.ObjectMeta.Name, + Namespace: o.ObjectMeta.Namespace, + Group: gvk.Group, + Version: gvk.Version, + Kind: gvk.Kind, + } +} + +func (o *RoutingTree) SetStaticMetadata(metadata resource.StaticMetadata) { + o.Name = metadata.Name + o.Namespace = metadata.Namespace + o.SetGroupVersionKind(schema.GroupVersionKind{ + Group: metadata.Group, + Version: metadata.Version, + Kind: metadata.Kind, + }) +} + +func (o *RoutingTree) GetCommonMetadata() resource.CommonMetadata { + dt := o.DeletionTimestamp + var deletionTimestamp *time.Time + if dt != nil { + deletionTimestamp = &dt.Time + } + // Legacy ExtraFields support + extraFields := make(map[string]any) + if o.Annotations != nil { + extraFields["annotations"] = o.Annotations + } + if o.ManagedFields != nil { + extraFields["managedFields"] = o.ManagedFields + } + if o.OwnerReferences != nil { + extraFields["ownerReferences"] = o.OwnerReferences + } + return resource.CommonMetadata{ + UID: string(o.UID), + ResourceVersion: o.ResourceVersion, + Generation: o.Generation, + Labels: o.Labels, + CreationTimestamp: o.CreationTimestamp.Time, + DeletionTimestamp: deletionTimestamp, + Finalizers: o.Finalizers, + UpdateTimestamp: o.GetUpdateTimestamp(), + CreatedBy: o.GetCreatedBy(), + UpdatedBy: o.GetUpdatedBy(), + ExtraFields: extraFields, + } +} + +func (o *RoutingTree) SetCommonMetadata(metadata resource.CommonMetadata) { + o.UID = types.UID(metadata.UID) + o.ResourceVersion = metadata.ResourceVersion + o.Generation = metadata.Generation + o.Labels = metadata.Labels + o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp) + if metadata.DeletionTimestamp != nil { + dt := metav1.NewTime(*metadata.DeletionTimestamp) + o.DeletionTimestamp = &dt + } else { + o.DeletionTimestamp = nil + } + o.Finalizers = metadata.Finalizers + if o.Annotations == nil { + o.Annotations = make(map[string]string) + } + if !metadata.UpdateTimestamp.IsZero() { + o.SetUpdateTimestamp(metadata.UpdateTimestamp) + } + if metadata.CreatedBy != "" { + o.SetCreatedBy(metadata.CreatedBy) + } + if metadata.UpdatedBy != "" { + o.SetUpdatedBy(metadata.UpdatedBy) + } + // Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields + if metadata.ExtraFields != nil { + if annotations, ok := metadata.ExtraFields["annotations"]; ok { + if cast, ok := annotations.(map[string]string); ok { + o.Annotations = cast + } + } + if managedFields, ok := metadata.ExtraFields["managedFields"]; ok { + if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok { + o.ManagedFields = cast + } + } + if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok { + if cast, ok := ownerReferences.([]metav1.OwnerReference); ok { + o.OwnerReferences = cast + } + } + } +} + +func (o *RoutingTree) GetCreatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/createdBy"] +} + +func (o *RoutingTree) SetCreatedBy(createdBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy +} + +func (o *RoutingTree) GetUpdateTimestamp() time.Time { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) + return parsed +} + +func (o *RoutingTree) SetUpdateTimestamp(updateTimestamp time.Time) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) +} + +func (o *RoutingTree) GetUpdatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/updatedBy"] +} + +func (o *RoutingTree) SetUpdatedBy(updatedBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy +} + +func (o *RoutingTree) Copy() resource.Object { + return resource.CopyObject(o) +} + +func (o *RoutingTree) DeepCopyObject() runtime.Object { + return o.Copy() +} + +// Interface compliance compile-time check +var _ resource.Object = &RoutingTree{} + +// +k8s:openapi-gen=true +type RoutingTreeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []RoutingTree `json:"items"` +} + +func (o *RoutingTreeList) DeepCopyObject() runtime.Object { + return o.Copy() +} + +func (o *RoutingTreeList) Copy() resource.ListObject { + cpy := &RoutingTreeList{ + TypeMeta: o.TypeMeta, + Items: make([]RoutingTree, len(o.Items)), + } + o.ListMeta.DeepCopyInto(&cpy.ListMeta) + for i := 0; i < len(o.Items); i++ { + if item, ok := o.Items[i].Copy().(*RoutingTree); ok { + cpy.Items[i] = *item + } + } + return cpy +} + +func (o *RoutingTreeList) GetItems() []resource.Object { + items := make([]resource.Object, len(o.Items)) + for i := 0; i < len(o.Items); i++ { + items[i] = &o.Items[i] + } + return items +} + +func (o *RoutingTreeList) SetItems(items []resource.Object) { + o.Items = make([]RoutingTree, len(items)) + for i := 0; i < len(items); i++ { + o.Items[i] = *items[i].(*RoutingTree) + } +} + +// Interface compliance compile-time check +var _ resource.ListObject = &RoutingTreeList{} diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_schema_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_schema_gen.go new file mode 100644 index 00000000000..5a7ed4b24c0 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_schema_gen.go @@ -0,0 +1,34 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "github.com/grafana/grafana-app-sdk/resource" +) + +// schema is unexported to prevent accidental overwrites +var ( + schemaRoutingTree = resource.NewSimpleSchema("notifications.alerting.grafana.app", "v0alpha1", &RoutingTree{}, &RoutingTreeList{}, resource.WithKind("RoutingTree"), + resource.WithPlural("routingtrees"), resource.WithScope(resource.NamespacedScope)) + kindRoutingTree = resource.Kind{ + Schema: schemaRoutingTree, + Codecs: map[resource.KindEncoding]resource.Codec{ + resource.KindEncodingJSON: &JSONCodec{}, + }, + } +) + +// Kind returns a resource.Kind for this Schema with a JSON codec +func Kind() resource.Kind { + return kindRoutingTree +} + +// Schema returns a resource.SimpleSchema representation of RoutingTree +func Schema() *resource.SimpleSchema { + return schemaRoutingTree +} + +// Interface compliance checks +var _ resource.Schema = kindRoutingTree diff --git a/pkg/apis/alerting_notifications/v0alpha1/routingtree_spec.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_spec_gen.go similarity index 84% rename from pkg/apis/alerting_notifications/v0alpha1/routingtree_spec.go rename to apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_spec_gen.go index e67cea00b05..aa3092478e4 100644 --- a/pkg/apis/alerting_notifications/v0alpha1/routingtree_spec.go +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_spec_gen.go @@ -2,10 +2,10 @@ package v0alpha1 // Defines values for MatcherType. const ( - MatcherTypeNotEqual MatcherType = "!=" - MatcherTypeEqual MatcherType = "=" - MatcherTypeEqualRegex MatcherType = "=~" - MatcherTypeNotEqualRegex MatcherType = "!~" + MatcherTypeEmpty MatcherType = "!=" + MatcherTypeEqual MatcherType = "=" + MatcherTypeEqualTilde MatcherType = "=~" + MatcherTypeN1 MatcherType = "!~" ) // Matcher defines model for Matcher. @@ -23,7 +23,7 @@ type MatcherType string // Route defines model for Route. // +k8s:openapi-gen=true type Route struct { - Continue bool `json:"continue,omitempty"` + Continue bool `json:"continue"` GroupBy []string `json:"group_by,omitempty"` GroupInterval *string `json:"group_interval,omitempty"` GroupWait *string `json:"group_wait,omitempty"` @@ -46,7 +46,7 @@ type RouteDefaults struct { // Spec defines model for Spec. // +k8s:openapi-gen=true -type RoutingTreeSpec struct { +type Spec struct { Defaults RouteDefaults `json:"defaults"` Routes []Route `json:"routes"` } diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_status_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_status_gen.go new file mode 100644 index 00000000000..6cf30ace059 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/routingtree_status_gen.go @@ -0,0 +1,70 @@ +package v0alpha1 + +// Defines values for OperatorStateState. +const ( + OperatorStateStateFailed OperatorStateState = "failed" + OperatorStateStateInProgress OperatorStateState = "in_progress" + OperatorStateStateSuccess OperatorStateState = "success" +) + +// Defines values for StatusOperatorStateState. +const ( + StatusOperatorStateStateFailed StatusOperatorStateState = "failed" + StatusOperatorStateStateInProgress StatusOperatorStateState = "in_progress" + StatusOperatorStateStateSuccess StatusOperatorStateState = "success" +) + +// OperatorState defines model for OperatorState. +// +k8s:openapi-gen=true +type OperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State OperatorStateState `json:"state"` +} + +// OperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type OperatorStateState string + +// Status defines model for Status. +// +k8s:openapi-gen=true +type Status struct { + // additionalFields is reserved for future use + AdditionalFields map[string]interface{} `json:"additionalFields,omitempty"` + + // operatorStates is a map of operator ID to operator state evaluations. + // Any operator which consumes this kind SHOULD add its state evaluation information to this field. + OperatorStates map[string]StatusOperatorState `json:"operatorStates,omitempty"` +} + +// StatusOperatorState defines model for status.#OperatorState. +// +k8s:openapi-gen=true +type StatusOperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State StatusOperatorStateState `json:"state"` +} + +// StatusOperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type StatusOperatorStateState string diff --git a/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/zz_openapi_gen.go b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/zz_openapi_gen.go new file mode 100644 index 00000000000..7f93e199450 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1/zz_openapi_gen.go @@ -0,0 +1,493 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by grafana-app-sdk. DO NOT EDIT. + +package v0alpha1 + +import ( + common "k8s.io/kube-openapi/pkg/common" + spec "k8s.io/kube-openapi/pkg/validation/spec" +) + +func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { + return map[string]common.OpenAPIDefinition{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Matcher": schema_apis_resource_routingtree_v0alpha1_Matcher(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.OperatorState": schema_apis_resource_routingtree_v0alpha1_OperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Route": schema_apis_resource_routingtree_v0alpha1_Route(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RouteDefaults": schema_apis_resource_routingtree_v0alpha1_RouteDefaults(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RoutingTree": schema_apis_resource_routingtree_v0alpha1_RoutingTree(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RoutingTreeList": schema_apis_resource_routingtree_v0alpha1_RoutingTreeList(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Spec": schema_apis_resource_routingtree_v0alpha1_Spec(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Status": schema_apis_resource_routingtree_v0alpha1_Status(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.StatusOperatorState": schema_apis_resource_routingtree_v0alpha1_StatusOperatorState(ref), + } +} + +func schema_apis_resource_routingtree_v0alpha1_Matcher(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Matcher defines model for Matcher.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "label": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "type": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "value": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"label", "type", "value"}, + }, + }, + } +} + +func schema_apis_resource_routingtree_v0alpha1_OperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "OperatorState defines model for OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_routingtree_v0alpha1_Route(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Route defines model for Route.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "continue": { + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, + "group_by": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "group_interval": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "group_wait": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "matchers": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Matcher"), + }, + }, + }, + }, + }, + "mute_time_intervals": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "receiver": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "repeat_interval": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "routes": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Route"), + }, + }, + }, + }, + }, + }, + Required: []string{"continue"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Matcher", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Route"}, + } +} + +func schema_apis_resource_routingtree_v0alpha1_RouteDefaults(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "RouteDefaults defines model for RouteDefaults.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "group_by": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "group_interval": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "group_wait": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "receiver": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "repeat_interval": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"receiver"}, + }, + }, + } +} + +func schema_apis_resource_routingtree_v0alpha1_RoutingTree(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Spec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Status"), + }, + }, + }, + Required: []string{"metadata", "spec", "status"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Spec", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Status", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_apis_resource_routingtree_v0alpha1_RoutingTreeList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RoutingTree"), + }, + }, + }, + }, + }, + }, + Required: []string{"metadata", "items"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RoutingTree", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_apis_resource_routingtree_v0alpha1_Spec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Spec defines model for Spec.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "defaults": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RouteDefaults"), + }, + }, + "routes": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Route"), + }, + }, + }, + }, + }, + }, + Required: []string{"defaults", "routes"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.Route", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.RouteDefaults"}, + } +} + +func schema_apis_resource_routingtree_v0alpha1_Status(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Status defines model for Status.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "additionalFields": { + SchemaProps: spec.SchemaProps{ + Description: "additionalFields is reserved for future use", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "operatorStates": { + SchemaProps: spec.SchemaProps{ + Description: "operatorStates is a map of operator ID to operator state evaluations. Any operator which consumes this kind SHOULD add its state evaluation information to this field.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.StatusOperatorState"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1.StatusOperatorState"}, + } +} + +func schema_apis_resource_routingtree_v0alpha1_StatusOperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "StatusOperatorState defines model for status.#OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/ext.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/ext.go new file mode 100644 index 00000000000..a7a158950c9 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/ext.go @@ -0,0 +1,45 @@ +package v0alpha1 + +import ( + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apiserver/pkg/registry/generic" + + "github.com/grafana/grafana/apps/alerting/common" +) + +func (o *TemplateGroup) GetProvenanceStatus() string { + if o == nil || o.Annotations == nil { + return "" + } + s, ok := o.Annotations[common.ProvenanceStatusAnnotationKey] + if !ok || s == "" { + return common.ProvenanceStatusNone + } + return s +} + +func (o *TemplateGroup) SetProvenanceStatus(status string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 1) + } + if status == "" { + status = common.ProvenanceStatusNone + } + o.Annotations[common.ProvenanceStatusAnnotationKey] = status +} + +func SelectableFields(obj *TemplateGroup) fields.Set { + if obj == nil { + return nil + } + selectable := Schema().SelectableFields() + set := make(fields.Set, len(selectable)) + for _, field := range selectable { + f, err := field.FieldValueFunc(obj) + if err != nil { + continue + } + set[field.FieldSelector] = f + } + return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), set) +} diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_codec_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_codec_gen.go new file mode 100644 index 00000000000..7b5050a3af4 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_codec_gen.go @@ -0,0 +1,28 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "encoding/json" + "io" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// JSONCodec is an implementation of resource.Codec for kubernetes JSON encoding +type JSONCodec struct{} + +// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into` +func (*JSONCodec) Read(reader io.Reader, into resource.Object) error { + return json.NewDecoder(reader).Decode(into) +} + +// Write writes JSON-encoded bytes into `writer` marshaled from `from` +func (*JSONCodec) Write(writer io.Writer, from resource.Object) error { + return json.NewEncoder(writer).Encode(from) +} + +// Interface compliance checks +var _ resource.Codec = &JSONCodec{} diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_metadata_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_metadata_gen.go new file mode 100644 index 00000000000..24b09a76c08 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_metadata_gen.go @@ -0,0 +1,32 @@ +package v0alpha1 + +import ( + "time" +) + +// Metadata defines model for Metadata. +type Metadata struct { + CreatedBy string `json:"createdBy"` + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` + UpdateTimestamp time.Time `json:"updateTimestamp"` + UpdatedBy string `json:"updatedBy"` +} + +// _kubeObjectMetadata is metadata found in a kubernetes object's metadata field. +// It is not exhaustive and only includes fields which may be relevant to a kind's implementation, +// As it is also intended to be generic enough to function with any API Server. +type KubeObjectMetadata struct { + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_object_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_object_gen.go new file mode 100644 index 00000000000..66ed2279d4c --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_object_gen.go @@ -0,0 +1,266 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + "github.com/grafana/grafana-app-sdk/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "time" +) + +// +k8s:openapi-gen=true +type TemplateGroup struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec Spec `json:"spec"` + Status Status `json:"status"` +} + +func (o *TemplateGroup) GetSpec() any { + return o.Spec +} + +func (o *TemplateGroup) SetSpec(spec any) error { + cast, ok := spec.(Spec) + if !ok { + return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) + } + o.Spec = cast + return nil +} + +func (o *TemplateGroup) GetSubresources() map[string]any { + return map[string]any{ + "status": o.Status, + } +} + +func (o *TemplateGroup) GetSubresource(name string) (any, bool) { + switch name { + case "status": + return o.Status, true + default: + return nil, false + } +} + +func (o *TemplateGroup) SetSubresource(name string, value any) error { + switch name { + case "status": + cast, ok := value.(Status) + if !ok { + return fmt.Errorf("cannot set status type %#v, not of type Status", value) + } + o.Status = cast + return nil + default: + return fmt.Errorf("subresource '%s' does not exist", name) + } +} + +func (o *TemplateGroup) GetStaticMetadata() resource.StaticMetadata { + gvk := o.GroupVersionKind() + return resource.StaticMetadata{ + Name: o.ObjectMeta.Name, + Namespace: o.ObjectMeta.Namespace, + Group: gvk.Group, + Version: gvk.Version, + Kind: gvk.Kind, + } +} + +func (o *TemplateGroup) SetStaticMetadata(metadata resource.StaticMetadata) { + o.Name = metadata.Name + o.Namespace = metadata.Namespace + o.SetGroupVersionKind(schema.GroupVersionKind{ + Group: metadata.Group, + Version: metadata.Version, + Kind: metadata.Kind, + }) +} + +func (o *TemplateGroup) GetCommonMetadata() resource.CommonMetadata { + dt := o.DeletionTimestamp + var deletionTimestamp *time.Time + if dt != nil { + deletionTimestamp = &dt.Time + } + // Legacy ExtraFields support + extraFields := make(map[string]any) + if o.Annotations != nil { + extraFields["annotations"] = o.Annotations + } + if o.ManagedFields != nil { + extraFields["managedFields"] = o.ManagedFields + } + if o.OwnerReferences != nil { + extraFields["ownerReferences"] = o.OwnerReferences + } + return resource.CommonMetadata{ + UID: string(o.UID), + ResourceVersion: o.ResourceVersion, + Generation: o.Generation, + Labels: o.Labels, + CreationTimestamp: o.CreationTimestamp.Time, + DeletionTimestamp: deletionTimestamp, + Finalizers: o.Finalizers, + UpdateTimestamp: o.GetUpdateTimestamp(), + CreatedBy: o.GetCreatedBy(), + UpdatedBy: o.GetUpdatedBy(), + ExtraFields: extraFields, + } +} + +func (o *TemplateGroup) SetCommonMetadata(metadata resource.CommonMetadata) { + o.UID = types.UID(metadata.UID) + o.ResourceVersion = metadata.ResourceVersion + o.Generation = metadata.Generation + o.Labels = metadata.Labels + o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp) + if metadata.DeletionTimestamp != nil { + dt := metav1.NewTime(*metadata.DeletionTimestamp) + o.DeletionTimestamp = &dt + } else { + o.DeletionTimestamp = nil + } + o.Finalizers = metadata.Finalizers + if o.Annotations == nil { + o.Annotations = make(map[string]string) + } + if !metadata.UpdateTimestamp.IsZero() { + o.SetUpdateTimestamp(metadata.UpdateTimestamp) + } + if metadata.CreatedBy != "" { + o.SetCreatedBy(metadata.CreatedBy) + } + if metadata.UpdatedBy != "" { + o.SetUpdatedBy(metadata.UpdatedBy) + } + // Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields + if metadata.ExtraFields != nil { + if annotations, ok := metadata.ExtraFields["annotations"]; ok { + if cast, ok := annotations.(map[string]string); ok { + o.Annotations = cast + } + } + if managedFields, ok := metadata.ExtraFields["managedFields"]; ok { + if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok { + o.ManagedFields = cast + } + } + if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok { + if cast, ok := ownerReferences.([]metav1.OwnerReference); ok { + o.OwnerReferences = cast + } + } + } +} + +func (o *TemplateGroup) GetCreatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/createdBy"] +} + +func (o *TemplateGroup) SetCreatedBy(createdBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy +} + +func (o *TemplateGroup) GetUpdateTimestamp() time.Time { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) + return parsed +} + +func (o *TemplateGroup) SetUpdateTimestamp(updateTimestamp time.Time) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) +} + +func (o *TemplateGroup) GetUpdatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/updatedBy"] +} + +func (o *TemplateGroup) SetUpdatedBy(updatedBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy +} + +func (o *TemplateGroup) Copy() resource.Object { + return resource.CopyObject(o) +} + +func (o *TemplateGroup) DeepCopyObject() runtime.Object { + return o.Copy() +} + +// Interface compliance compile-time check +var _ resource.Object = &TemplateGroup{} + +// +k8s:openapi-gen=true +type TemplateGroupList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []TemplateGroup `json:"items"` +} + +func (o *TemplateGroupList) DeepCopyObject() runtime.Object { + return o.Copy() +} + +func (o *TemplateGroupList) Copy() resource.ListObject { + cpy := &TemplateGroupList{ + TypeMeta: o.TypeMeta, + Items: make([]TemplateGroup, len(o.Items)), + } + o.ListMeta.DeepCopyInto(&cpy.ListMeta) + for i := 0; i < len(o.Items); i++ { + if item, ok := o.Items[i].Copy().(*TemplateGroup); ok { + cpy.Items[i] = *item + } + } + return cpy +} + +func (o *TemplateGroupList) GetItems() []resource.Object { + items := make([]resource.Object, len(o.Items)) + for i := 0; i < len(o.Items); i++ { + items[i] = &o.Items[i] + } + return items +} + +func (o *TemplateGroupList) SetItems(items []resource.Object) { + o.Items = make([]TemplateGroup, len(items)) + for i := 0; i < len(items); i++ { + o.Items[i] = *items[i].(*TemplateGroup) + } +} + +// Interface compliance compile-time check +var _ resource.ListObject = &TemplateGroupList{} diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_schema_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_schema_gen.go new file mode 100644 index 00000000000..256fbab3116 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_schema_gen.go @@ -0,0 +1,46 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// schema is unexported to prevent accidental overwrites +var ( + schemaTemplateGroup = resource.NewSimpleSchema("notifications.alerting.grafana.app", "v0alpha1", &TemplateGroup{}, &TemplateGroupList{}, resource.WithKind("TemplateGroup"), + resource.WithPlural("templategroups"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{resource.SelectableField{ + FieldSelector: "spec.title", + FieldValueFunc: func(o resource.Object) (string, error) { + cast, ok := o.(*TemplateGroup) + if !ok { + return "", fmt.Errorf("provided object must be of type *TemplateGroup") + } + return cast.Spec.Title, nil + }, + }, + })) + kindTemplateGroup = resource.Kind{ + Schema: schemaTemplateGroup, + Codecs: map[resource.KindEncoding]resource.Codec{ + resource.KindEncodingJSON: &JSONCodec{}, + }, + } +) + +// Kind returns a resource.Kind for this Schema with a JSON codec +func Kind() resource.Kind { + return kindTemplateGroup +} + +// Schema returns a resource.SimpleSchema representation of TemplateGroup +func Schema() *resource.SimpleSchema { + return schemaTemplateGroup +} + +// Interface compliance checks +var _ resource.Schema = kindTemplateGroup diff --git a/pkg/apis/alerting_notifications/v0alpha1/templategroup_spec.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_spec_gen.go similarity index 54% rename from pkg/apis/alerting_notifications/v0alpha1/templategroup_spec.go rename to apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_spec_gen.go index 0731380f602..a2c73e7da8f 100644 --- a/pkg/apis/alerting_notifications/v0alpha1/templategroup_spec.go +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_spec_gen.go @@ -1,8 +1,8 @@ package v0alpha1 -// TemplateGroupSpec defines model for TemplateGroupSpec. +// Spec defines model for Spec. // +k8s:openapi-gen=true -type TemplateGroupSpec struct { - Title string `json:"title"` +type Spec struct { Content string `json:"content"` + Title string `json:"title"` } diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_status_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_status_gen.go new file mode 100644 index 00000000000..6cf30ace059 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/templategroup_status_gen.go @@ -0,0 +1,70 @@ +package v0alpha1 + +// Defines values for OperatorStateState. +const ( + OperatorStateStateFailed OperatorStateState = "failed" + OperatorStateStateInProgress OperatorStateState = "in_progress" + OperatorStateStateSuccess OperatorStateState = "success" +) + +// Defines values for StatusOperatorStateState. +const ( + StatusOperatorStateStateFailed StatusOperatorStateState = "failed" + StatusOperatorStateStateInProgress StatusOperatorStateState = "in_progress" + StatusOperatorStateStateSuccess StatusOperatorStateState = "success" +) + +// OperatorState defines model for OperatorState. +// +k8s:openapi-gen=true +type OperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State OperatorStateState `json:"state"` +} + +// OperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type OperatorStateState string + +// Status defines model for Status. +// +k8s:openapi-gen=true +type Status struct { + // additionalFields is reserved for future use + AdditionalFields map[string]interface{} `json:"additionalFields,omitempty"` + + // operatorStates is a map of operator ID to operator state evaluations. + // Any operator which consumes this kind SHOULD add its state evaluation information to this field. + OperatorStates map[string]StatusOperatorState `json:"operatorStates,omitempty"` +} + +// StatusOperatorState defines model for status.#OperatorState. +// +k8s:openapi-gen=true +type StatusOperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State StatusOperatorStateState `json:"state"` +} + +// StatusOperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type StatusOperatorStateState string diff --git a/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/zz_openapi_gen.go b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/zz_openapi_gen.go new file mode 100644 index 00000000000..863104ba463 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1/zz_openapi_gen.go @@ -0,0 +1,294 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by grafana-app-sdk. DO NOT EDIT. + +package v0alpha1 + +import ( + common "k8s.io/kube-openapi/pkg/common" + spec "k8s.io/kube-openapi/pkg/validation/spec" +) + +func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { + return map[string]common.OpenAPIDefinition{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.OperatorState": schema_apis_resource_templategroup_v0alpha1_OperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Spec": schema_apis_resource_templategroup_v0alpha1_Spec(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Status": schema_apis_resource_templategroup_v0alpha1_Status(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.StatusOperatorState": schema_apis_resource_templategroup_v0alpha1_StatusOperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.TemplateGroup": schema_apis_resource_templategroup_v0alpha1_TemplateGroup(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.TemplateGroupList": schema_apis_resource_templategroup_v0alpha1_TemplateGroupList(ref), + } +} + +func schema_apis_resource_templategroup_v0alpha1_OperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "OperatorState defines model for OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_templategroup_v0alpha1_Spec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Spec defines model for Spec.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "content": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "title": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"content", "title"}, + }, + }, + } +} + +func schema_apis_resource_templategroup_v0alpha1_Status(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Status defines model for Status.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "additionalFields": { + SchemaProps: spec.SchemaProps{ + Description: "additionalFields is reserved for future use", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "operatorStates": { + SchemaProps: spec.SchemaProps{ + Description: "operatorStates is a map of operator ID to operator state evaluations. Any operator which consumes this kind SHOULD add its state evaluation information to this field.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.StatusOperatorState"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.StatusOperatorState"}, + } +} + +func schema_apis_resource_templategroup_v0alpha1_StatusOperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "StatusOperatorState defines model for status.#OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_templategroup_v0alpha1_TemplateGroup(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Spec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Status"), + }, + }, + }, + Required: []string{"metadata", "spec", "status"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Spec", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.Status", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_apis_resource_templategroup_v0alpha1_TemplateGroupList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.TemplateGroup"), + }, + }, + }, + }, + }, + }, + Required: []string{"metadata", "items"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1.TemplateGroup", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/ext.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/ext.go new file mode 100644 index 00000000000..481818c7471 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/ext.go @@ -0,0 +1,45 @@ +package v0alpha1 + +import ( + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apiserver/pkg/registry/generic" + + "github.com/grafana/grafana/apps/alerting/common" +) + +func (o *TimeInterval) GetProvenanceStatus() string { + if o == nil || o.Annotations == nil { + return "" + } + s, ok := o.Annotations[common.ProvenanceStatusAnnotationKey] + if !ok || s == "" { + return common.ProvenanceStatusNone + } + return s +} + +func (o *TimeInterval) SetProvenanceStatus(status string) { + if o.Annotations == nil { + o.Annotations = make(map[string]string, 1) + } + if status == "" { + status = common.ProvenanceStatusNone + } + o.Annotations[common.ProvenanceStatusAnnotationKey] = status +} + +func SelectableFields(obj *TimeInterval) fields.Set { + if obj == nil { + return nil + } + selectable := Schema().SelectableFields() + set := make(fields.Set, len(selectable)) + for _, field := range selectable { + f, err := field.FieldValueFunc(obj) + if err != nil { + continue + } + set[field.FieldSelector] = f + } + return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), set) +} diff --git a/pkg/apis/alerting_notifications/v0alpha1/testing.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/fakes/gen.go similarity index 81% rename from pkg/apis/alerting_notifications/v0alpha1/testing.go rename to apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/fakes/gen.go index 355f7422f20..3e6fcf5aeaa 100644 --- a/pkg/apis/alerting_notifications/v0alpha1/testing.go +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/fakes/gen.go @@ -1,4 +1,4 @@ -package v0alpha1 +package fakes import ( "fmt" @@ -7,15 +7,14 @@ import ( "strings" "time" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1" "github.com/grafana/grafana/pkg/util" ) // +k8s:openapi-gen=false -// +k8s:deepcopy-gen=false -type IntervalMutator func(spec *Interval) +type IntervalMutator func(spec *v0alpha1.Interval) // +k8s:openapi-gen=false -// +k8s:deepcopy-gen=false type IntervalGenerator struct { mutators []IntervalMutator } @@ -36,10 +35,10 @@ func (t IntervalGenerator) generateDaysOfMonth() string { return fmt.Sprintf("%d:%d", from, to) } -func (t IntervalGenerator) generateTimeRange() TimeRange { +func (t IntervalGenerator) generateTimeRange() v0alpha1.TimeRange { from := rand.Int63n(1440 / 2) // [0, 719] to := from + rand.Int63n(1440/2) + 1 // from < ([0,719] + [1,720]) < 1440 - return TimeRange{ + return v0alpha1.TimeRange{ StartTime: time.Unix(from*60, 0).UTC().Format("15:04"), EndTime: time.Unix(to*60, 0).UTC().Format("15:04"), } @@ -70,16 +69,16 @@ func (t IntervalGenerator) generateMonth() string { return fmt.Sprintf("%d", rand.Intn(12)+1) } -func (t IntervalGenerator) GenerateMany(count int) []Interval { - result := make([]Interval, 0, count) +func (t IntervalGenerator) GenerateMany(count int) []v0alpha1.Interval { + result := make([]v0alpha1.Interval, 0, count) for i := 0; i < count; i++ { result = append(result, t.Generate()) } return result } -func (t IntervalGenerator) Generate() Interval { - i := Interval{ +func (t IntervalGenerator) Generate() v0alpha1.Interval { + i := v0alpha1.Interval{ DaysOfMonth: generateMany(rand.Intn(6), true, t.generateDaysOfMonth), Location: t.generateLocation(), Months: generateMany(rand.Intn(3), true, t.generateMonth), @@ -105,11 +104,3 @@ func generateMany[T comparable](repeatTimes int, unique bool, f func() T) []T { } return result } - -func CopyWith(in Interval, mutators ...IntervalMutator) Interval { - r := *in.DeepCopy() - for _, mut := range mutators { - mut(&r) - } - return r -} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_codec_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_codec_gen.go new file mode 100644 index 00000000000..7b5050a3af4 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_codec_gen.go @@ -0,0 +1,28 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "encoding/json" + "io" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// JSONCodec is an implementation of resource.Codec for kubernetes JSON encoding +type JSONCodec struct{} + +// Read reads JSON-encoded bytes from `reader` and unmarshals them into `into` +func (*JSONCodec) Read(reader io.Reader, into resource.Object) error { + return json.NewDecoder(reader).Decode(into) +} + +// Write writes JSON-encoded bytes into `writer` marshaled from `from` +func (*JSONCodec) Write(writer io.Writer, from resource.Object) error { + return json.NewEncoder(writer).Encode(from) +} + +// Interface compliance checks +var _ resource.Codec = &JSONCodec{} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_metadata_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_metadata_gen.go new file mode 100644 index 00000000000..24b09a76c08 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_metadata_gen.go @@ -0,0 +1,32 @@ +package v0alpha1 + +import ( + "time" +) + +// Metadata defines model for Metadata. +type Metadata struct { + CreatedBy string `json:"createdBy"` + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` + UpdateTimestamp time.Time `json:"updateTimestamp"` + UpdatedBy string `json:"updatedBy"` +} + +// _kubeObjectMetadata is metadata found in a kubernetes object's metadata field. +// It is not exhaustive and only includes fields which may be relevant to a kind's implementation, +// As it is also intended to be generic enough to function with any API Server. +type KubeObjectMetadata struct { + CreationTimestamp time.Time `json:"creationTimestamp"` + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Finalizers []string `json:"finalizers"` + Generation int64 `json:"generation"` + Labels map[string]string `json:"labels"` + ResourceVersion string `json:"resourceVersion"` + Uid string `json:"uid"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_object_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_object_gen.go new file mode 100644 index 00000000000..ec2c8eb3c26 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_object_gen.go @@ -0,0 +1,266 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + "github.com/grafana/grafana-app-sdk/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "time" +) + +// +k8s:openapi-gen=true +type TimeInterval struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec Spec `json:"spec"` + Status Status `json:"status"` +} + +func (o *TimeInterval) GetSpec() any { + return o.Spec +} + +func (o *TimeInterval) SetSpec(spec any) error { + cast, ok := spec.(Spec) + if !ok { + return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) + } + o.Spec = cast + return nil +} + +func (o *TimeInterval) GetSubresources() map[string]any { + return map[string]any{ + "status": o.Status, + } +} + +func (o *TimeInterval) GetSubresource(name string) (any, bool) { + switch name { + case "status": + return o.Status, true + default: + return nil, false + } +} + +func (o *TimeInterval) SetSubresource(name string, value any) error { + switch name { + case "status": + cast, ok := value.(Status) + if !ok { + return fmt.Errorf("cannot set status type %#v, not of type Status", value) + } + o.Status = cast + return nil + default: + return fmt.Errorf("subresource '%s' does not exist", name) + } +} + +func (o *TimeInterval) GetStaticMetadata() resource.StaticMetadata { + gvk := o.GroupVersionKind() + return resource.StaticMetadata{ + Name: o.ObjectMeta.Name, + Namespace: o.ObjectMeta.Namespace, + Group: gvk.Group, + Version: gvk.Version, + Kind: gvk.Kind, + } +} + +func (o *TimeInterval) SetStaticMetadata(metadata resource.StaticMetadata) { + o.Name = metadata.Name + o.Namespace = metadata.Namespace + o.SetGroupVersionKind(schema.GroupVersionKind{ + Group: metadata.Group, + Version: metadata.Version, + Kind: metadata.Kind, + }) +} + +func (o *TimeInterval) GetCommonMetadata() resource.CommonMetadata { + dt := o.DeletionTimestamp + var deletionTimestamp *time.Time + if dt != nil { + deletionTimestamp = &dt.Time + } + // Legacy ExtraFields support + extraFields := make(map[string]any) + if o.Annotations != nil { + extraFields["annotations"] = o.Annotations + } + if o.ManagedFields != nil { + extraFields["managedFields"] = o.ManagedFields + } + if o.OwnerReferences != nil { + extraFields["ownerReferences"] = o.OwnerReferences + } + return resource.CommonMetadata{ + UID: string(o.UID), + ResourceVersion: o.ResourceVersion, + Generation: o.Generation, + Labels: o.Labels, + CreationTimestamp: o.CreationTimestamp.Time, + DeletionTimestamp: deletionTimestamp, + Finalizers: o.Finalizers, + UpdateTimestamp: o.GetUpdateTimestamp(), + CreatedBy: o.GetCreatedBy(), + UpdatedBy: o.GetUpdatedBy(), + ExtraFields: extraFields, + } +} + +func (o *TimeInterval) SetCommonMetadata(metadata resource.CommonMetadata) { + o.UID = types.UID(metadata.UID) + o.ResourceVersion = metadata.ResourceVersion + o.Generation = metadata.Generation + o.Labels = metadata.Labels + o.CreationTimestamp = metav1.NewTime(metadata.CreationTimestamp) + if metadata.DeletionTimestamp != nil { + dt := metav1.NewTime(*metadata.DeletionTimestamp) + o.DeletionTimestamp = &dt + } else { + o.DeletionTimestamp = nil + } + o.Finalizers = metadata.Finalizers + if o.Annotations == nil { + o.Annotations = make(map[string]string) + } + if !metadata.UpdateTimestamp.IsZero() { + o.SetUpdateTimestamp(metadata.UpdateTimestamp) + } + if metadata.CreatedBy != "" { + o.SetCreatedBy(metadata.CreatedBy) + } + if metadata.UpdatedBy != "" { + o.SetUpdatedBy(metadata.UpdatedBy) + } + // Legacy support for setting Annotations, ManagedFields, and OwnerReferences via ExtraFields + if metadata.ExtraFields != nil { + if annotations, ok := metadata.ExtraFields["annotations"]; ok { + if cast, ok := annotations.(map[string]string); ok { + o.Annotations = cast + } + } + if managedFields, ok := metadata.ExtraFields["managedFields"]; ok { + if cast, ok := managedFields.([]metav1.ManagedFieldsEntry); ok { + o.ManagedFields = cast + } + } + if ownerReferences, ok := metadata.ExtraFields["ownerReferences"]; ok { + if cast, ok := ownerReferences.([]metav1.OwnerReference); ok { + o.OwnerReferences = cast + } + } + } +} + +func (o *TimeInterval) GetCreatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/createdBy"] +} + +func (o *TimeInterval) SetCreatedBy(createdBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy +} + +func (o *TimeInterval) GetUpdateTimestamp() time.Time { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) + return parsed +} + +func (o *TimeInterval) SetUpdateTimestamp(updateTimestamp time.Time) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) +} + +func (o *TimeInterval) GetUpdatedBy() string { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + return o.ObjectMeta.Annotations["grafana.com/updatedBy"] +} + +func (o *TimeInterval) SetUpdatedBy(updatedBy string) { + if o.ObjectMeta.Annotations == nil { + o.ObjectMeta.Annotations = make(map[string]string) + } + + o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy +} + +func (o *TimeInterval) Copy() resource.Object { + return resource.CopyObject(o) +} + +func (o *TimeInterval) DeepCopyObject() runtime.Object { + return o.Copy() +} + +// Interface compliance compile-time check +var _ resource.Object = &TimeInterval{} + +// +k8s:openapi-gen=true +type TimeIntervalList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []TimeInterval `json:"items"` +} + +func (o *TimeIntervalList) DeepCopyObject() runtime.Object { + return o.Copy() +} + +func (o *TimeIntervalList) Copy() resource.ListObject { + cpy := &TimeIntervalList{ + TypeMeta: o.TypeMeta, + Items: make([]TimeInterval, len(o.Items)), + } + o.ListMeta.DeepCopyInto(&cpy.ListMeta) + for i := 0; i < len(o.Items); i++ { + if item, ok := o.Items[i].Copy().(*TimeInterval); ok { + cpy.Items[i] = *item + } + } + return cpy +} + +func (o *TimeIntervalList) GetItems() []resource.Object { + items := make([]resource.Object, len(o.Items)) + for i := 0; i < len(o.Items); i++ { + items[i] = &o.Items[i] + } + return items +} + +func (o *TimeIntervalList) SetItems(items []resource.Object) { + o.Items = make([]TimeInterval, len(items)) + for i := 0; i < len(items); i++ { + o.Items[i] = *items[i].(*TimeInterval) + } +} + +// Interface compliance compile-time check +var _ resource.ListObject = &TimeIntervalList{} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_schema_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_schema_gen.go new file mode 100644 index 00000000000..627e02a9572 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_schema_gen.go @@ -0,0 +1,46 @@ +// +// Code generated by grafana-app-sdk. DO NOT EDIT. +// + +package v0alpha1 + +import ( + "fmt" + + "github.com/grafana/grafana-app-sdk/resource" +) + +// schema is unexported to prevent accidental overwrites +var ( + schemaTimeInterval = resource.NewSimpleSchema("notifications.alerting.grafana.app", "v0alpha1", &TimeInterval{}, &TimeIntervalList{}, resource.WithKind("TimeInterval"), + resource.WithPlural("timeintervals"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{resource.SelectableField{ + FieldSelector: "spec.name", + FieldValueFunc: func(o resource.Object) (string, error) { + cast, ok := o.(*TimeInterval) + if !ok { + return "", fmt.Errorf("provided object must be of type *TimeInterval") + } + return cast.Spec.Name, nil + }, + }, + })) + kindTimeInterval = resource.Kind{ + Schema: schemaTimeInterval, + Codecs: map[resource.KindEncoding]resource.Codec{ + resource.KindEncodingJSON: &JSONCodec{}, + }, + } +) + +// Kind returns a resource.Kind for this Schema with a JSON codec +func Kind() resource.Kind { + return kindTimeInterval +} + +// Schema returns a resource.SimpleSchema representation of TimeInterval +func Schema() *resource.SimpleSchema { + return schemaTimeInterval +} + +// Interface compliance checks +var _ resource.Schema = kindTimeInterval diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_spec_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_spec_gen.go new file mode 100644 index 00000000000..88254bf4a13 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_spec_gen.go @@ -0,0 +1,26 @@ +package v0alpha1 + +// Interval defines model for Interval. +// +k8s:openapi-gen=true +type Interval struct { + DaysOfMonth []string `json:"days_of_month,omitempty"` + Location *string `json:"location,omitempty"` + Months []string `json:"months,omitempty"` + Times []TimeRange `json:"times,omitempty"` + Weekdays []string `json:"weekdays,omitempty"` + Years []string `json:"years,omitempty"` +} + +// Spec defines model for Spec. +// +k8s:openapi-gen=true +type Spec struct { + Name string `json:"name"` + TimeIntervals []Interval `json:"time_intervals"` +} + +// TimeRange defines model for TimeRange. +// +k8s:openapi-gen=true +type TimeRange struct { + EndTime string `json:"end_time"` + StartTime string `json:"start_time"` +} diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_status_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_status_gen.go new file mode 100644 index 00000000000..6cf30ace059 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/timeinterval_status_gen.go @@ -0,0 +1,70 @@ +package v0alpha1 + +// Defines values for OperatorStateState. +const ( + OperatorStateStateFailed OperatorStateState = "failed" + OperatorStateStateInProgress OperatorStateState = "in_progress" + OperatorStateStateSuccess OperatorStateState = "success" +) + +// Defines values for StatusOperatorStateState. +const ( + StatusOperatorStateStateFailed StatusOperatorStateState = "failed" + StatusOperatorStateStateInProgress StatusOperatorStateState = "in_progress" + StatusOperatorStateStateSuccess StatusOperatorStateState = "success" +) + +// OperatorState defines model for OperatorState. +// +k8s:openapi-gen=true +type OperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State OperatorStateState `json:"state"` +} + +// OperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type OperatorStateState string + +// Status defines model for Status. +// +k8s:openapi-gen=true +type Status struct { + // additionalFields is reserved for future use + AdditionalFields map[string]interface{} `json:"additionalFields,omitempty"` + + // operatorStates is a map of operator ID to operator state evaluations. + // Any operator which consumes this kind SHOULD add its state evaluation information to this field. + OperatorStates map[string]StatusOperatorState `json:"operatorStates,omitempty"` +} + +// StatusOperatorState defines model for status.#OperatorState. +// +k8s:openapi-gen=true +type StatusOperatorState struct { + // descriptiveState is an optional more descriptive state field which has no requirements on format + DescriptiveState *string `json:"descriptiveState,omitempty"` + + // details contains any extra information that is operator-specific + Details map[string]interface{} `json:"details,omitempty"` + + // lastEvaluation is the ResourceVersion last evaluated + LastEvaluation string `json:"lastEvaluation"` + + // state describes the state of the lastEvaluation. + // It is limited to three possible states for machine evaluation. + State StatusOperatorStateState `json:"state"` +} + +// StatusOperatorStateState state describes the state of the lastEvaluation. +// It is limited to three possible states for machine evaluation. +// +k8s:openapi-gen=true +type StatusOperatorStateState string diff --git a/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/zz_openapi_gen.go b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/zz_openapi_gen.go new file mode 100644 index 00000000000..832f9977321 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/zz_openapi_gen.go @@ -0,0 +1,422 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by grafana-app-sdk. DO NOT EDIT. + +package v0alpha1 + +import ( + common "k8s.io/kube-openapi/pkg/common" + spec "k8s.io/kube-openapi/pkg/validation/spec" +) + +func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { + return map[string]common.OpenAPIDefinition{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Interval": schema_apis_resource_timeinterval_v0alpha1_Interval(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.OperatorState": schema_apis_resource_timeinterval_v0alpha1_OperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Spec": schema_apis_resource_timeinterval_v0alpha1_Spec(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Status": schema_apis_resource_timeinterval_v0alpha1_Status(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.StatusOperatorState": schema_apis_resource_timeinterval_v0alpha1_StatusOperatorState(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeInterval": schema_apis_resource_timeinterval_v0alpha1_TimeInterval(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeIntervalList": schema_apis_resource_timeinterval_v0alpha1_TimeIntervalList(ref), + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeRange": schema_apis_resource_timeinterval_v0alpha1_TimeRange(ref), + } +} + +func schema_apis_resource_timeinterval_v0alpha1_Interval(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Interval defines model for Interval.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "days_of_month": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "location": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "months": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "times": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeRange"), + }, + }, + }, + }, + }, + "weekdays": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "years": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeRange"}, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_OperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "OperatorState defines model for OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_Spec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Spec defines model for Spec.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "time_intervals": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Interval"), + }, + }, + }, + }, + }, + }, + Required: []string{"name", "time_intervals"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Interval"}, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_Status(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Status defines model for Status.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "additionalFields": { + SchemaProps: spec.SchemaProps{ + Description: "additionalFields is reserved for future use", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "operatorStates": { + SchemaProps: spec.SchemaProps{ + Description: "operatorStates is a map of operator ID to operator state evaluations. Any operator which consumes this kind SHOULD add its state evaluation information to this field.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.StatusOperatorState"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.StatusOperatorState"}, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_StatusOperatorState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "StatusOperatorState defines model for status.#OperatorState.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "descriptiveState": { + SchemaProps: spec.SchemaProps{ + Description: "descriptiveState is an optional more descriptive state field which has no requirements on format", + Type: []string{"string"}, + Format: "", + }, + }, + "details": { + SchemaProps: spec.SchemaProps{ + Description: "details contains any extra information that is operator-specific", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Format: "", + }, + }, + }, + }, + }, + "lastEvaluation": { + SchemaProps: spec.SchemaProps{ + Description: "lastEvaluation is the ResourceVersion last evaluated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "state": { + SchemaProps: spec.SchemaProps{ + Description: "state describes the state of the lastEvaluation. It is limited to three possible states for machine evaluation.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"lastEvaluation", "state"}, + }, + }, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_TimeInterval(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Spec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Status"), + }, + }, + }, + Required: []string{"metadata", "spec", "status"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Spec", "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.Status", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_TimeIntervalList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeInterval"), + }, + }, + }, + }, + }, + }, + Required: []string{"metadata", "items"}, + }, + }, + Dependencies: []string{ + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1.TimeInterval", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_apis_resource_timeinterval_v0alpha1_TimeRange(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TimeRange defines model for TimeRange.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "end_time": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "start_time": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"end_time", "start_time"}, + }, + }, + } +} diff --git a/apps/alerting/notifications/pkg/apis/resource/type.go b/apps/alerting/notifications/pkg/apis/resource/type.go new file mode 100644 index 00000000000..e31e5548224 --- /dev/null +++ b/apps/alerting/notifications/pkg/apis/resource/type.go @@ -0,0 +1,5 @@ +package resource + +import "k8s.io/apimachinery/pkg/runtime/schema" + +var GroupVersion = schema.GroupVersion{Group: "notifications.alerting.grafana.app", Version: "v0alpha1"} diff --git a/go.work b/go.work index af82fefd085..f2c5d4fb6f3 100644 --- a/go.work +++ b/go.work @@ -5,6 +5,7 @@ go 1.23.1 use ( . // skip:golangci-lint + ./apps/alerting/notifications ./apps/playlist ./kindsv2 ./pkg/aggregator diff --git a/go.work.sum b/go.work.sum index 4500ed71caa..0195001fd44 100644 --- a/go.work.sum +++ b/go.work.sum @@ -623,6 +623,7 @@ github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0/go.mod h1:ccdDY github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 h1:goHVqTbFX3AIo0tzGr14pgfAW2ZfPChKO21Z9MGf/gk= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40 h1:q4dksr6ICHXqG5hm0ZW5IHyeEJXoIJSOZeBLmWPNeIQ= github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs= github.com/apache/arrow/go/v10 v10.0.1 h1:n9dERvixoC/1JjDmBcs9FPaEryoANa2sCgVFo6ez9cI= @@ -960,6 +961,7 @@ github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386/go.mod h1:JDGc github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE= +github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= github.com/google/go-jsonnet v0.18.0 h1:/6pTy6g+Jh1a1I2UMoAODkqELFiVIdOxbNwv0DDzoOg= github.com/google/go-jsonnet v0.18.0/go.mod h1:C3fTzyVJDslXdiTqw/bTFk7vSGyCtH3MGRbDfvEwGd0= github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9 h1:OF1IPgv+F4NmqmJ98KTjdN97Vs1JxDPB3vbmYzV2dpk= @@ -987,7 +989,6 @@ github.com/grafana/alerting v0.0.0-20240830172655-aa466962ea18 h1:3cQ+d+fkNL2Eqp github.com/grafana/alerting v0.0.0-20240830172655-aa466962ea18/go.mod h1:GMLi6d09Xqo96fCVUjNk//rcjP5NKEdjOzfWIffD5r4= github.com/grafana/alerting v0.0.0-20240917171353-6c25eb6eff10 h1:oDbLKM34O+JUF9EQFS+9aYhdYoeNfUpXqNjFCLIxwF4= github.com/grafana/alerting v0.0.0-20240917171353-6c25eb6eff10/go.mod h1:GMLi6d09Xqo96fCVUjNk//rcjP5NKEdjOzfWIffD5r4= -github.com/grafana/authlib/claims v0.0.0-20241202085737-df90af04f335 h1:3DHH81RJCi8Bcgn2MdBh7vgWUshmAFjZzBCVuxiQ0uk= github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2 h1:qhugDMdQ4Vp68H0tp/0iN17DM2ehRo1rLEdOFe/gB8I= github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2/go.mod h1:w/aiO1POVIeXUQyl0VQSZjl5OAGDTL5aX+4v0RA1tcw= github.com/grafana/cog v0.0.4/go.mod h1:lzetOuhGUl/JaSACiJoHvBokf9/fS6PEFaWZvnQu2vs= @@ -1002,8 +1003,6 @@ github.com/grafana/go-json v0.0.0-20241115232854-f14426c40ff2 h1:8xGrYqQ1GM4aaMk github.com/grafana/go-json v0.0.0-20241115232854-f14426c40ff2/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56/go.mod h1:PGk3RjYHpxMM8HFPhKKo+vve3DdlPUELZLSDEFehPuU= github.com/grafana/grafana-app-sdk v0.19.0/go.mod h1:y0BgzYxc+a7CwOqkwUhN9zXd5cgZJjd2zAbgHEd/xzo= -github.com/grafana/grafana-plugin-sdk-go v0.260.1 h1:KzbooQP9mv/9CPsn+SoUwGuomA8oUxO0iuIq6Rg/ekE= -github.com/grafana/grafana-plugin-sdk-go v0.260.1/go.mod h1:JriieK5Oc5v120QKhMs/LO55N0P3YI2ttEiVT1wfYsw= github.com/grafana/pyroscope-go/godeltaprof v0.1.6/go.mod h1:Tk376Nbldo4Cha9RgiU7ik8WKFkNpfds98aUzS8omLE= github.com/grafana/tail v0.0.0-20230510142333-77b18831edf0 h1:bjh0PVYSVVFxzINqPFYJmAmJNrWPgnVjuSdYJGHmtFU= github.com/grafana/tail v0.0.0-20230510142333-77b18831edf0/go.mod h1:7t5XR+2IA8P2qggOAHTj/GCZfoLBle3OvNSYh1VkRBU= @@ -1385,7 +1384,9 @@ github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:Om github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc= github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/common/assets v0.2.0 h1:0P5OrzoHrYBOSM1OigWL3mY8ZvV2N4zIE/5AahrSrfM= github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97/go.mod h1:LoBCZeRh+5hX+fSULNyFnagYlQG/gBsyA/deNzROkq8= github.com/prometheus/statsd_exporter v0.26.0 h1:SQl3M6suC6NWQYEzOvIv+EF6dAMYEqIuZy+o4H9F5Ig= @@ -1443,12 +1444,11 @@ github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad h1:fiWzISvDn0Csy5H0iwgAuJGQTUpVfEMJJd4nRFXogbc= +github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stoewer/parquet-cli v0.0.7 h1:rhdZODIbyMS3twr4OM3am8BPPT5pbfMcHLH93whDM5o= github.com/stoewer/parquet-cli v0.0.7/go.mod h1:bskxHdj8q3H1EmfuCqjViFoeO3NEvs5lzZAQvI8Nfjk= github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo= github.com/streadway/handy v0.0.0-20200128134331-0f66f006fb2e h1:mOtuXaRAbVZsxAHVdPR3IjfmN8T1h2iczJLynhLybf8= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/substrait-io/substrait-go v0.4.2 h1:buDnjsb3qAqTaNbOR7VKmNgXf4lYQxWEcnSGUWBtmN8= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/tdewolff/minify/v2 v2.12.9 h1:dvn5MtmuQ/DFMwqf5j8QhEVpPX6fi3WGImhv8RUB4zA= @@ -1695,12 +1695,12 @@ go.opentelemetry.io/contrib/exporters/autoexport v0.53.0 h1:13K+tY7E8GJInkrvRiPA go.opentelemetry.io/contrib/exporters/autoexport v0.53.0/go.mod h1:lyQF6xQ4iDnMg4sccNdFs1zf62xd79YI8vZqKjOTwMs= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0/go.mod h1:BMsdeOxN04K0L5FNUBfjFdvwWGNe/rkmSwH4Aelu/X0= go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0/go.mod h1:ImRBLMJv177/pwiLZ7tU7HDGNdBv7rS0HQ99eN/zBl8= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM= go.opentelemetry.io/contrib/propagators/b3 v1.23.0 h1:aaIGWc5JdfRGpCafLRxMJbD65MfTa206AwSKkvGS0Hg= go.opentelemetry.io/contrib/propagators/b3 v1.23.0/go.mod h1:Gyz7V7XghvwTq+mIhLFlTgcc03UDroOg8vezs4NLhwU= go.opentelemetry.io/contrib/propagators/b3 v1.27.0 h1:IjgxbomVrV9za6bRi8fWCNXENs0co37SZedQilP2hm0= go.opentelemetry.io/contrib/propagators/b3 v1.27.0/go.mod h1:Dv9obQz25lCisDvvs4dy28UPh974CxkahRDUPsY7y9E= go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= -go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= go.opentelemetry.io/otel/bridge/opencensus v1.26.0 h1:DZzxj9QjznMVoehskOJnFP2gsTCWtDTFBDvFhPAY7nc= go.opentelemetry.io/otel/bridge/opencensus v1.26.0/go.mod h1:rJiX0KrF5m8Tm1XE8jLczpAv5zUaDcvhKecFG0ZoFG4= go.opentelemetry.io/otel/bridge/opencensus v1.27.0 h1:ao9aGGHd+G4YfjBpGs6vbkvt5hoC67STlJA9fCnOAcs= @@ -1715,9 +1715,11 @@ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.23.1 h1:q/N go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.23.1/go.mod h1:DTE9yAu6r08jU3xa68GiSeI7oRcSEQ2RpKbbQGO+dWM= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 h1:aLmmtjRke7LPDQ3lvpFz+kNEH43faFhzW7v8BFIEydg= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0/go.mod h1:TC1pyCt6G9Sjb4bQpShH+P5R53pO6ZuGnHuuln9xMeE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0/go.mod h1:B5Ki776z/MBnVha1Nzwp5arlzBbE3+1jk+pGmaP5HME= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0/go.mod h1:TMu73/k1CP8nBUpDLc71Wj/Kf7ZS9FK5b53VapRsP9o= go.opentelemetry.io/otel/exporters/prometheus v0.46.0 h1:I8WIFXR351FoLJYuloU4EgXbtNX2URfU/85pUPheIEQ= go.opentelemetry.io/otel/exporters/prometheus v0.46.0/go.mod h1:ztwVUHe5DTR/1v7PeuGRnU5Bbd4QKYwApWmuutKsJSs= go.opentelemetry.io/otel/exporters/prometheus v0.50.0 h1:2Ewsda6hejmbhGFyUvWZjUThC98Cf8Zy6g0zkIimOng= @@ -1743,7 +1745,6 @@ go.opentelemetry.io/otel/sdk/metric v1.26.0/go.mod h1:ClMFFknnThJCksebJwz7KIyEDH go.opentelemetry.io/otel/sdk/metric v1.28.0 h1:OkuaKgKrgAbYrrY0t92c+cC+2F6hsFNnCQArXCKlg08= go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg= go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= -go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= @@ -1789,12 +1790,9 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= -golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= -golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1805,14 +1803,12 @@ golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1879,7 +1875,6 @@ google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjr google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/cheggaaa/pb.v1 v1.0.25 h1:Ev7yu1/f6+d+b3pi5vPdRPc6nNtP1umSfcWiEfRqv6I= gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= @@ -1909,6 +1904,7 @@ howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= +k8s.io/apiserver v0.31.1/go.mod h1:lzDhpeToamVZJmmFlaLwdYZwd7zB+WYRYIboqA1kGxM= k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= k8s.io/code-generator v0.31.0 h1:w607nrMi1KeDKB3/F/J4lIoOgAwc+gV9ZKew4XRfMp8= k8s.io/code-generator v0.31.0/go.mod h1:84y4w3es8rOJOUUP1rLsIiGlO1JuEaPFXQPA9e/K6U0= @@ -1917,6 +1913,7 @@ k8s.io/code-generator v0.31.1/go.mod h1:oL2ky46L48osNqqZAeOcWWy0S5BXj50vVdwOtTef k8s.io/code-generator v0.31.3 h1:Pj0fYOBms+ZrsulLi4DMsCEx1jG8fWKRLy44onHsLBI= k8s.io/code-generator v0.31.3/go.mod h1:/umCIlT84g1+Yu5ZXtP1KGSRTnGiIzzX5AzUAxsNlts= k8s.io/component-base v0.31.0/go.mod h1:TYVuzI1QmN4L5ItVdMSXKvH7/DtvIuas5/mm8YT3rTo= +k8s.io/component-base v0.31.1/go.mod h1:WGeaw7t/kTsqpVTaCoVEtillbqAhF2/JgvO0LDOMa0w= k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= diff --git a/pkg/apis/alerting_notifications/v0alpha1/doc.go b/pkg/apis/alerting_notifications/v0alpha1/doc.go deleted file mode 100644 index f1e30a11e31..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// +k8s:deepcopy-gen=package -// +k8s:openapi-gen=true -// +k8s:defaulter-gen=TypeMeta -// +groupName=notifications.alerting.grafana.app - -package v0alpha1 // import "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" diff --git a/pkg/apis/alerting_notifications/v0alpha1/receiver_spec.go b/pkg/apis/alerting_notifications/v0alpha1/receiver_spec.go deleted file mode 100644 index 18298dfa691..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/receiver_spec.go +++ /dev/null @@ -1,24 +0,0 @@ -package v0alpha1 - -import ( - common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" -) - -// Integration defines model for Integration. -// +k8s:openapi-gen=true -type Integration struct { - DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"` - // +mapType=atomic - SecureFields map[string]bool `json:"secureFields,omitempty"` - Settings common.Unstructured `json:"settings"` - Type string `json:"type"` - Uid *string `json:"uid,omitempty"` -} - -// ReceiverSpec defines model for Spec. -// +k8s:openapi-gen=true -type ReceiverSpec struct { - // +listType=atomic - Integrations []Integration `json:"integrations"` - Title string `json:"title"` -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/register.go b/pkg/apis/alerting_notifications/v0alpha1/register.go deleted file mode 100644 index 7bf9a679fab..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/register.go +++ /dev/null @@ -1,222 +0,0 @@ -package v0alpha1 - -import ( - "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apiserver/pkg/registry/generic" - - "github.com/grafana/grafana/pkg/apimachinery/utils" - scope "github.com/grafana/grafana/pkg/apis/scope/v0alpha1" -) - -func init() { - localSchemeBuilder.Register(AddKnownTypes) -} - -const ( - GROUP = "notifications.alerting.grafana.app" - VERSION = "v0alpha1" - APIVERSION = GROUP + "/" + VERSION - UserDefinedRoutingTreeName = "user-defined" -) - -var ( - TimeIntervalResourceInfo = utils.NewResourceInfo(GROUP, VERSION, - "timeintervals", "timeinterval", "TimeInterval", - func() runtime.Object { return &TimeInterval{} }, - func() runtime.Object { return &TimeIntervalList{} }, - utils.TableColumns{ - Definition: []metav1.TableColumnDefinition{ - {Name: "Name", Type: "string", Format: "name"}, - // {Name: "Intervals", Type: "string", Format: "string", Description: "The display name"}, - }, - Reader: func(obj any) ([]interface{}, error) { - r, ok := obj.(*TimeInterval) - if ok { - return []interface{}{ - r.Name, - // r.Spec, //TODO implement formatting for Spec, same as UI? - }, nil - } - return nil, fmt.Errorf("expected resource or info") - }, - }, - ) - ReceiverResourceInfo = utils.NewResourceInfo(GROUP, VERSION, - "receivers", "receiver", "Receiver", - func() runtime.Object { return &Receiver{} }, - func() runtime.Object { return &ReceiverList{} }, - utils.TableColumns{ - Definition: []metav1.TableColumnDefinition{ - {Name: "Name", Type: "string", Format: "name"}, - {Name: "Title", Type: "string", Format: "string", Description: "The receiver name"}, // TODO: Add integration types. - }, - Reader: func(obj any) ([]interface{}, error) { - r, ok := obj.(*Receiver) - if ok { - return []interface{}{ - r.Name, - r.Spec.Title, - // r.Spec, //TODO implement formatting for Spec, same as UI? - }, nil - } - return nil, fmt.Errorf("expected resource or info") - }, - }, - ) - TemplateGroupResourceInfo = utils.NewResourceInfo(GROUP, VERSION, - "templategroups", "templategroup", "TemplateGroup", - func() runtime.Object { return &TemplateGroup{} }, - func() runtime.Object { return &TemplateGroupList{} }, - utils.TableColumns{ - Definition: []metav1.TableColumnDefinition{ - {Name: "Name", Type: "string", Format: "name"}, - }, - Reader: func(obj any) ([]interface{}, error) { - r, ok := obj.(*TemplateGroup) - if !ok { - return nil, fmt.Errorf("expected resource or info") - } - return []interface{}{ - r.Name, - }, nil - }, - }, - ) - RouteResourceInfo = utils.NewResourceInfo(GROUP, VERSION, - "routingtrees", "routingtree", "RoutingTree", - func() runtime.Object { return &RoutingTree{} }, - func() runtime.Object { return &RoutingTreeList{} }, - utils.TableColumns{ - Definition: []metav1.TableColumnDefinition{ - {Name: "Name", Type: "string", Format: "name"}, - // {Name: "Intervals", Type: "string", Format: "string", Description: "The display name"}, - }, - Reader: func(obj any) ([]interface{}, error) { - r, ok := obj.(*RoutingTree) - if !ok { - return nil, fmt.Errorf("expected resource or info") - } - return []interface{}{ - r.Name, - // r.Spec, //TODO implement formatting for Spec, same as UI? - }, nil - }, - }, - ) - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION} - // SchemaBuilder is used by standard codegen - SchemeBuilder runtime.SchemeBuilder - localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme -) - -// Adds the list of known types to the given scheme. -func AddKnownTypes(scheme *runtime.Scheme) error { - return AddKnownTypesGroup(scheme, SchemeGroupVersion) -} - -// Adds the list of known types to the given scheme and group version. -func AddKnownTypesGroup(scheme *runtime.Scheme, g schema.GroupVersion) error { - scheme.AddKnownTypes(g, - &TimeInterval{}, - &TimeIntervalList{}, - &Receiver{}, - &ReceiverList{}, - &TemplateGroup{}, - &TemplateGroupList{}, - &RoutingTree{}, - &RoutingTreeList{}, - ) - metav1.AddToGroupVersion(scheme, g) - - err := scheme.AddFieldLabelConversionFunc( - TimeIntervalResourceInfo.GroupVersionKind(), - func(label, value string) (string, string, error) { - fieldSet := SelectableTimeIntervalsFields(&TimeInterval{}) - for key := range fieldSet { - if label == key { - return label, value, nil - } - } - return "", "", fmt.Errorf("field label not supported for %s: %s", scope.ScopeNodeResourceInfo.GroupVersionKind(), label) - }, - ) - if err != nil { - return err - } - - err = scheme.AddFieldLabelConversionFunc( - ReceiverResourceInfo.GroupVersionKind(), - func(label, value string) (string, string, error) { - fieldSet := SelectableReceiverFields(&Receiver{}) - for key := range fieldSet { - if label == key { - return label, value, nil - } - } - return "", "", fmt.Errorf("field label not supported for %s: %s", scope.ScopeNodeResourceInfo.GroupVersionKind(), label) - }, - ) - if err != nil { - return err - } - - err = scheme.AddFieldLabelConversionFunc( - TemplateGroupResourceInfo.GroupVersionKind(), - func(label, value string) (string, string, error) { - fieldSet := SelectableTemplateGroupFields(&TemplateGroup{}) - for key := range fieldSet { - if label == key { - return label, value, nil - } - } - return "", "", fmt.Errorf("field label not supported for %s: %s", scope.ScopeNodeResourceInfo.GroupVersionKind(), label) - }, - ) - if err != nil { - return err - } - - return nil -} - -func SelectableTimeIntervalsFields(obj *TimeInterval) fields.Set { - if obj == nil { - return nil - } - return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), fields.Set{ - "metadata.provenance": obj.GetProvenanceStatus(), - "spec.name": obj.Spec.Name, - }) -} - -func SelectableReceiverFields(obj *Receiver) fields.Set { - if obj == nil { - return nil - } - return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), fields.Set{ - "metadata.provenance": obj.GetProvenanceStatus(), - "spec.title": obj.Spec.Title, - }) -} - -func SelectableTemplateGroupFields(obj *TemplateGroup) fields.Set { - if obj == nil { - return nil - } - return generic.MergeFieldsSets(generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false), fields.Set{ - "metadata.provenance": obj.GetProvenanceStatus(), - "spec.title": obj.Spec.Title, - }) -} - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/timeinterval_spec.go b/pkg/apis/alerting_notifications/v0alpha1/timeinterval_spec.go deleted file mode 100644 index f345bda7416..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/timeinterval_spec.go +++ /dev/null @@ -1,38 +0,0 @@ -package v0alpha1 - -// Interval defines model for Interval. -// +k8s:openapi-gen=true -type Interval struct { - // +listType=atomic - DaysOfMonth []string `json:"days_of_month,omitempty"` - - // +listType=atomic - Location *string `json:"location,omitempty"` - - // +listType=atomic - Months []string `json:"months,omitempty"` - - // +listType=atomic - Times []TimeRange `json:"times,omitempty"` - - // +listType=atomic - Weekdays []string `json:"weekdays,omitempty"` - - // +listType=atomic - Years []string `json:"years,omitempty"` -} - -// Spec defines model for Spec. -// +k8s:openapi-gen=true -type TimeIntervalSpec struct { - Name string `json:"name"` - // +listType=atomic - TimeIntervals []Interval `json:"time_intervals"` -} - -// TimeRange defines model for TimeRange. -// +k8s:openapi-gen=true -type TimeRange struct { - EndTime string `json:"end_time"` - StartTime string `json:"start_time"` -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/types.go b/pkg/apis/alerting_notifications/v0alpha1/types.go deleted file mode 100644 index 649ca7f565b..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/types.go +++ /dev/null @@ -1,340 +0,0 @@ -package v0alpha1 - -import ( - "fmt" - "time" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// region TimeInterval - -// +genclient -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TimeInterval struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec TimeIntervalSpec `json:"spec"` -} - -func (o *TimeInterval) GetSpec() any { - return o.Spec -} - -func (o *TimeInterval) SetSpec(spec any) error { - cast, ok := spec.(TimeIntervalSpec) - if !ok { - return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) - } - o.Spec = cast - return nil -} - -func (o *TimeInterval) GetCreatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/createdBy"] -} - -func (o *TimeInterval) SetCreatedBy(createdBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy -} - -func (o *TimeInterval) GetUpdateTimestamp() time.Time { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) - return parsed -} - -func (o *TimeInterval) SetUpdateTimestamp(updateTimestamp time.Time) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) -} - -func (o *TimeInterval) GetUpdatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/updatedBy"] -} - -func (o *TimeInterval) SetUpdatedBy(updatedBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -type TimeIntervalList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []TimeInterval `json:"items"` -} - -// endregion - -// region Receivers - -// +genclient -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type Receiver struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec ReceiverSpec `json:"spec"` -} - -func (o *Receiver) GetSpec() any { - return o.Spec -} - -func (o *Receiver) SetSpec(spec any) error { - cast, ok := spec.(ReceiverSpec) - if !ok { - return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) - } - o.Spec = cast - return nil -} - -func (o *Receiver) GetCreatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/createdBy"] -} - -func (o *Receiver) SetCreatedBy(createdBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy -} - -func (o *Receiver) GetUpdateTimestamp() time.Time { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) - return parsed -} - -func (o *Receiver) SetUpdateTimestamp(updateTimestamp time.Time) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) -} - -func (o *Receiver) GetUpdatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/updatedBy"] -} - -func (o *Receiver) SetUpdatedBy(updatedBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy -} - -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ReceiverList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []Receiver `json:"items"` -} - -// endregion - -// region Templates - -// +genclient -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TemplateGroup struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec TemplateGroupSpec `json:"spec"` -} - -func (o *TemplateGroup) GetSpec() any { - return o.Spec -} - -func (o *TemplateGroup) SetSpec(spec any) error { - cast, ok := spec.(TemplateGroupSpec) - if !ok { - return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) - } - o.Spec = cast - return nil -} - -func (o *TemplateGroup) GetCreatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/createdBy"] -} - -func (o *TemplateGroup) SetCreatedBy(createdBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy -} - -func (o *TemplateGroup) GetUpdateTimestamp() time.Time { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - parsed, _ := time.Parse(o.ObjectMeta.Annotations["grafana.com/updateTimestamp"], time.RFC3339) - return parsed -} - -func (o *TemplateGroup) SetUpdateTimestamp(updateTimestamp time.Time) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) -} - -func (o *TemplateGroup) GetUpdatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/updatedBy"] -} - -func (o *TemplateGroup) SetUpdatedBy(updatedBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy -} - -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TemplateGroupList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []TemplateGroup `json:"items"` -} - -// endregion - -// region Routes - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -type RoutingTree struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec RoutingTreeSpec `json:"spec"` -} - -func (o *RoutingTree) GetSpec() any { - return o.Spec -} - -func (o *RoutingTree) SetSpec(spec any) error { - cast, ok := spec.(RoutingTreeSpec) - if !ok { - return fmt.Errorf("cannot set spec type %#v, not of type Spec", spec) - } - o.Spec = cast - return nil -} - -func (o *RoutingTree) GetCreatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/createdBy"] -} - -func (o *RoutingTree) SetCreatedBy(createdBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/createdBy"] = createdBy -} - -func (o *RoutingTree) GetUpdateTimestamp() time.Time { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - parsed, _ := time.Parse(time.RFC3339, o.ObjectMeta.Annotations["grafana.com/updateTimestamp"]) - return parsed -} - -func (o *RoutingTree) SetUpdateTimestamp(updateTimestamp time.Time) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updateTimestamp"] = updateTimestamp.Format(time.RFC3339) -} - -func (o *RoutingTree) GetUpdatedBy() string { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - return o.ObjectMeta.Annotations["grafana.com/updatedBy"] -} - -func (o *RoutingTree) SetUpdatedBy(updatedBy string) { - if o.ObjectMeta.Annotations == nil { - o.ObjectMeta.Annotations = make(map[string]string) - } - - o.ObjectMeta.Annotations["grafana.com/updatedBy"] = updatedBy -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -type RoutingTreeList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []RoutingTree `json:"items"` -} - -// endregion Routes diff --git a/pkg/apis/alerting_notifications/v0alpha1/types_ext.go b/pkg/apis/alerting_notifications/v0alpha1/types_ext.go deleted file mode 100644 index 34a7cdbd77d..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/types_ext.go +++ /dev/null @@ -1,120 +0,0 @@ -package v0alpha1 - -import ( - "fmt" -) - -const InternalPrefix = "grafana.com/" -const ProvenanceStatusAnnotationKey = InternalPrefix + "provenance" -const ProvenanceStatusNone = "none" - -func (o *TimeInterval) GetProvenanceStatus() string { - if o == nil || o.Annotations == nil { - return "" - } - s, ok := o.Annotations[ProvenanceStatusAnnotationKey] - if !ok || s == "" { - return ProvenanceStatusNone - } - return s -} - -func (o *TimeInterval) SetProvenanceStatus(status string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 1) - } - if status == "" { - status = ProvenanceStatusNone - } - o.Annotations[ProvenanceStatusAnnotationKey] = status -} - -func (o *Receiver) GetProvenanceStatus() string { - if o == nil || o.Annotations == nil { - return "" - } - s, ok := o.Annotations[ProvenanceStatusAnnotationKey] - if !ok || s == "" { - return ProvenanceStatusNone - } - return s -} - -func (o *Receiver) SetProvenanceStatus(status string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 1) - } - if status == "" { - status = ProvenanceStatusNone - } - o.Annotations[ProvenanceStatusAnnotationKey] = status -} - -func (o *Receiver) SetAccessControl(action string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 1) - } - o.Annotations[AccessControlAnnotation(action)] = "true" -} - -// AccessControlAnnotation returns the key for the access control annotation for the given action. -// Ex. grafana.com/access/canDelete. -func AccessControlAnnotation(action string) string { - return fmt.Sprintf("%s%s/%s", InternalPrefix, "access", action) -} - -func (o *Receiver) SetInUse(routesCnt int, rules []string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 2) - } - o.Annotations[InUseAnnotation("routes")] = fmt.Sprintf("%d", routesCnt) - o.Annotations[InUseAnnotation("rules")] = fmt.Sprintf("%d", len(rules)) -} - -// InUseAnnotation returns the key for the in-use annotation for the given resource. -// Ex. grafana.com/inUse/routes, grafana.com/inUse/rules. -func InUseAnnotation(resource string) string { - return fmt.Sprintf("%s%s/%s", InternalPrefix, "inUse", resource) -} - -func (o *TemplateGroup) GetProvenanceStatus() string { - if o == nil || o.Annotations == nil { - return "" - } - s, ok := o.Annotations[ProvenanceStatusAnnotationKey] - if !ok || s == "" { - return ProvenanceStatusNone - } - return s -} - -func (o *TemplateGroup) SetProvenanceStatus(status string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 1) - } - if status == "" { - status = ProvenanceStatusNone - } - o.Annotations[ProvenanceStatusAnnotationKey] = status -} - -func (o *RoutingTree) GetProvenanceStatus() string { - if o == nil || o.Annotations == nil { - return "" - } - s, ok := o.Annotations[ProvenanceStatusAnnotationKey] - if !ok || s == "" { - return ProvenanceStatusNone - } - return s -} - -func (o *RoutingTree) SetProvenanceStatus(status string) { - if o.Annotations == nil { - o.Annotations = make(map[string]string, 1) - } - if status == "" { - status = ProvenanceStatusNone - } - o.Annotations[ProvenanceStatusAnnotationKey] = status -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.deepcopy.go b/pkg/apis/alerting_notifications/v0alpha1/zz_generated.deepcopy.go deleted file mode 100644 index b69f9817c44..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,544 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Integration) DeepCopyInto(out *Integration) { - *out = *in - if in.DisableResolveMessage != nil { - in, out := &in.DisableResolveMessage, &out.DisableResolveMessage - *out = new(bool) - **out = **in - } - if in.SecureFields != nil { - in, out := &in.SecureFields, &out.SecureFields - *out = make(map[string]bool, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - in.Settings.DeepCopyInto(&out.Settings) - if in.Uid != nil { - in, out := &in.Uid, &out.Uid - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Integration. -func (in *Integration) DeepCopy() *Integration { - if in == nil { - return nil - } - out := new(Integration) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Interval) DeepCopyInto(out *Interval) { - *out = *in - if in.DaysOfMonth != nil { - in, out := &in.DaysOfMonth, &out.DaysOfMonth - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Location != nil { - in, out := &in.Location, &out.Location - *out = new(string) - **out = **in - } - if in.Months != nil { - in, out := &in.Months, &out.Months - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Times != nil { - in, out := &in.Times, &out.Times - *out = make([]TimeRange, len(*in)) - copy(*out, *in) - } - if in.Weekdays != nil { - in, out := &in.Weekdays, &out.Weekdays - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Years != nil { - in, out := &in.Years, &out.Years - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Interval. -func (in *Interval) DeepCopy() *Interval { - if in == nil { - return nil - } - out := new(Interval) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Matcher) DeepCopyInto(out *Matcher) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matcher. -func (in *Matcher) DeepCopy() *Matcher { - if in == nil { - return nil - } - out := new(Matcher) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Receiver) DeepCopyInto(out *Receiver) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Receiver. -func (in *Receiver) DeepCopy() *Receiver { - if in == nil { - return nil - } - out := new(Receiver) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Receiver) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ReceiverList) DeepCopyInto(out *ReceiverList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Receiver, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReceiverList. -func (in *ReceiverList) DeepCopy() *ReceiverList { - if in == nil { - return nil - } - out := new(ReceiverList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ReceiverList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ReceiverSpec) DeepCopyInto(out *ReceiverSpec) { - *out = *in - if in.Integrations != nil { - in, out := &in.Integrations, &out.Integrations - *out = make([]Integration, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReceiverSpec. -func (in *ReceiverSpec) DeepCopy() *ReceiverSpec { - if in == nil { - return nil - } - out := new(ReceiverSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Route) DeepCopyInto(out *Route) { - *out = *in - if in.GroupBy != nil { - in, out := &in.GroupBy, &out.GroupBy - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.GroupInterval != nil { - in, out := &in.GroupInterval, &out.GroupInterval - *out = new(string) - **out = **in - } - if in.GroupWait != nil { - in, out := &in.GroupWait, &out.GroupWait - *out = new(string) - **out = **in - } - if in.Matchers != nil { - in, out := &in.Matchers, &out.Matchers - *out = make([]Matcher, len(*in)) - copy(*out, *in) - } - if in.MuteTimeIntervals != nil { - in, out := &in.MuteTimeIntervals, &out.MuteTimeIntervals - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Receiver != nil { - in, out := &in.Receiver, &out.Receiver - *out = new(string) - **out = **in - } - if in.RepeatInterval != nil { - in, out := &in.RepeatInterval, &out.RepeatInterval - *out = new(string) - **out = **in - } - if in.Routes != nil { - in, out := &in.Routes, &out.Routes - *out = make([]Route, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Route. -func (in *Route) DeepCopy() *Route { - if in == nil { - return nil - } - out := new(Route) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RouteDefaults) DeepCopyInto(out *RouteDefaults) { - *out = *in - if in.GroupBy != nil { - in, out := &in.GroupBy, &out.GroupBy - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.GroupInterval != nil { - in, out := &in.GroupInterval, &out.GroupInterval - *out = new(string) - **out = **in - } - if in.GroupWait != nil { - in, out := &in.GroupWait, &out.GroupWait - *out = new(string) - **out = **in - } - if in.RepeatInterval != nil { - in, out := &in.RepeatInterval, &out.RepeatInterval - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteDefaults. -func (in *RouteDefaults) DeepCopy() *RouteDefaults { - if in == nil { - return nil - } - out := new(RouteDefaults) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RoutingTree) DeepCopyInto(out *RoutingTree) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoutingTree. -func (in *RoutingTree) DeepCopy() *RoutingTree { - if in == nil { - return nil - } - out := new(RoutingTree) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RoutingTree) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RoutingTreeList) DeepCopyInto(out *RoutingTreeList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]RoutingTree, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoutingTreeList. -func (in *RoutingTreeList) DeepCopy() *RoutingTreeList { - if in == nil { - return nil - } - out := new(RoutingTreeList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RoutingTreeList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RoutingTreeSpec) DeepCopyInto(out *RoutingTreeSpec) { - *out = *in - in.Defaults.DeepCopyInto(&out.Defaults) - if in.Routes != nil { - in, out := &in.Routes, &out.Routes - *out = make([]Route, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoutingTreeSpec. -func (in *RoutingTreeSpec) DeepCopy() *RoutingTreeSpec { - if in == nil { - return nil - } - out := new(RoutingTreeSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateGroup) DeepCopyInto(out *TemplateGroup) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateGroup. -func (in *TemplateGroup) DeepCopy() *TemplateGroup { - if in == nil { - return nil - } - out := new(TemplateGroup) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TemplateGroup) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateGroupList) DeepCopyInto(out *TemplateGroupList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]TemplateGroup, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateGroupList. -func (in *TemplateGroupList) DeepCopy() *TemplateGroupList { - if in == nil { - return nil - } - out := new(TemplateGroupList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TemplateGroupList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateGroupSpec) DeepCopyInto(out *TemplateGroupSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateGroupSpec. -func (in *TemplateGroupSpec) DeepCopy() *TemplateGroupSpec { - if in == nil { - return nil - } - out := new(TemplateGroupSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TimeInterval) DeepCopyInto(out *TimeInterval) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeInterval. -func (in *TimeInterval) DeepCopy() *TimeInterval { - if in == nil { - return nil - } - out := new(TimeInterval) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TimeInterval) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TimeIntervalList) DeepCopyInto(out *TimeIntervalList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]TimeInterval, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeIntervalList. -func (in *TimeIntervalList) DeepCopy() *TimeIntervalList { - if in == nil { - return nil - } - out := new(TimeIntervalList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TimeIntervalList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TimeIntervalSpec) DeepCopyInto(out *TimeIntervalSpec) { - *out = *in - if in.TimeIntervals != nil { - in, out := &in.TimeIntervals, &out.TimeIntervals - *out = make([]Interval, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeIntervalSpec. -func (in *TimeIntervalSpec) DeepCopy() *TimeIntervalSpec { - if in == nil { - return nil - } - out := new(TimeIntervalSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TimeRange) DeepCopyInto(out *TimeRange) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeRange. -func (in *TimeRange) DeepCopy() *TimeRange { - if in == nil { - return nil - } - out := new(TimeRange) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.defaults.go b/pkg/apis/alerting_notifications/v0alpha1/zz_generated.defaults.go deleted file mode 100644 index 238fc2f4edc..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.defaults.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by defaulter-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// RegisterDefaults adds defaulters functions to the given scheme. -// Public to allow building arbitrary schemes. -// All generated defaulters are covering - they call all nested defaulters. -func RegisterDefaults(scheme *runtime.Scheme) error { - return nil -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi.go b/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi.go deleted file mode 100644 index f046c560b47..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi.go +++ /dev/null @@ -1,932 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by openapi-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - common "k8s.io/kube-openapi/pkg/common" - spec "k8s.io/kube-openapi/pkg/validation/spec" -) - -func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { - return map[string]common.OpenAPIDefinition{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Integration": schema_pkg_apis_alerting_notifications_v0alpha1_Integration(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Interval": schema_pkg_apis_alerting_notifications_v0alpha1_Interval(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Matcher": schema_pkg_apis_alerting_notifications_v0alpha1_Matcher(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Receiver": schema_pkg_apis_alerting_notifications_v0alpha1_Receiver(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.ReceiverList": schema_pkg_apis_alerting_notifications_v0alpha1_ReceiverList(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.ReceiverSpec": schema_pkg_apis_alerting_notifications_v0alpha1_ReceiverSpec(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Route": schema_pkg_apis_alerting_notifications_v0alpha1_Route(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RouteDefaults": schema_pkg_apis_alerting_notifications_v0alpha1_RouteDefaults(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTree": schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTree(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTreeList": schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTreeList(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTreeSpec": schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTreeSpec(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroup": schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroup(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroupList": schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroupList(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroupSpec": schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroupSpec(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeInterval": schema_pkg_apis_alerting_notifications_v0alpha1_TimeInterval(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeIntervalList": schema_pkg_apis_alerting_notifications_v0alpha1_TimeIntervalList(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeIntervalSpec": schema_pkg_apis_alerting_notifications_v0alpha1_TimeIntervalSpec(ref), - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeRange": schema_pkg_apis_alerting_notifications_v0alpha1_TimeRange(ref), - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_Integration(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Integration defines model for Integration.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "disableResolveMessage": { - SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", - }, - }, - "secureFields": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-map-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: false, - Type: []string{"boolean"}, - Format: "", - }, - }, - }, - }, - }, - "settings": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"), - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "uid": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"settings", "type"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_Interval(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Interval defines model for Interval.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "days_of_month": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "location": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "months": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "times": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeRange"), - }, - }, - }, - }, - }, - "weekdays": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "years": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeRange"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_Matcher(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Matcher defines model for Matcher.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "label": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "type": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "value": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"label", "type", "value"}, - }, - }, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_Receiver(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.ReceiverSpec"), - }, - }, - }, - Required: []string{"metadata", "spec"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.ReceiverSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_ReceiverList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Receiver"), - }, - }, - }, - }, - }, - }, - Required: []string{"metadata", "items"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Receiver", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_ReceiverSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "ReceiverSpec defines model for Spec.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "integrations": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Integration"), - }, - }, - }, - }, - }, - "title": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"integrations", "title"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Integration"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_Route(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Route defines model for Route.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "continue": { - SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", - }, - }, - "group_by": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "group_interval": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "group_wait": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "matchers": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Matcher"), - }, - }, - }, - }, - }, - "mute_time_intervals": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "receiver": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "repeat_interval": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "routes": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Route"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Matcher", "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Route"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_RouteDefaults(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "RouteDefaults defines model for RouteDefaults.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "group_by": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "group_interval": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "group_wait": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "receiver": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "repeat_interval": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"receiver"}, - }, - }, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTree(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTreeSpec"), - }, - }, - }, - Required: []string{"metadata", "spec"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTreeSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTreeList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTree"), - }, - }, - }, - }, - }, - }, - Required: []string{"metadata", "items"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RoutingTree", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_RoutingTreeSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Spec defines model for Spec.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "defaults": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RouteDefaults"), - }, - }, - "routes": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Route"), - }, - }, - }, - }, - }, - }, - Required: []string{"defaults", "routes"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Route", "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.RouteDefaults"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroup(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroupSpec"), - }, - }, - }, - Required: []string{"metadata", "spec"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroupSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroupList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroup"), - }, - }, - }, - }, - }, - }, - Required: []string{"metadata", "items"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TemplateGroup", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TemplateGroupSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TemplateGroupSpec defines model for TemplateGroupSpec.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "title": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "content": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"title", "content"}, - }, - }, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TimeInterval(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeIntervalSpec"), - }, - }, - }, - Required: []string{"metadata", "spec"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeIntervalSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TimeIntervalList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeInterval"), - }, - }, - }, - }, - }, - }, - Required: []string{"metadata", "items"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.TimeInterval", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TimeIntervalSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Spec defines model for Spec.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "name": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "time_intervals": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Interval"), - }, - }, - }, - }, - }, - }, - Required: []string{"name", "time_intervals"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1.Interval"}, - } -} - -func schema_pkg_apis_alerting_notifications_v0alpha1_TimeRange(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TimeRange defines model for TimeRange.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "end_time": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "start_time": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"end_time", "start_time"}, - }, - }, - } -} diff --git a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi_violation_exceptions.list b/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi_violation_exceptions.list deleted file mode 100644 index 3b6889dbb81..00000000000 --- a/pkg/apis/alerting_notifications/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ /dev/null @@ -1,19 +0,0 @@ -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,GroupBy -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,Matchers -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,MuteTimeIntervals -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,Routes -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RouteDefaults,GroupBy -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RoutingTreeSpec,Routes -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Interval,DaysOfMonth -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,GroupBy -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,GroupInterval -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,GroupWait -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,MuteTimeIntervals -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,Route,RepeatInterval -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RouteDefaults,GroupBy -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RouteDefaults,GroupInterval -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RouteDefaults,GroupWait -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,RouteDefaults,RepeatInterval -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,TimeIntervalSpec,TimeIntervals -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,TimeRange,EndTime -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1,TimeRange,StartTime diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/integration.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/integration.go deleted file mode 100644 index 9589a5a52a8..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/integration.go +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" -) - -// IntegrationApplyConfiguration represents a declarative configuration of the Integration type for use -// with apply. -type IntegrationApplyConfiguration struct { - DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"` - SecureFields map[string]bool `json:"secureFields,omitempty"` - Settings *v0alpha1.Unstructured `json:"settings,omitempty"` - Type *string `json:"type,omitempty"` - Uid *string `json:"uid,omitempty"` -} - -// IntegrationApplyConfiguration constructs a declarative configuration of the Integration type for use with -// apply. -func Integration() *IntegrationApplyConfiguration { - return &IntegrationApplyConfiguration{} -} - -// WithDisableResolveMessage sets the DisableResolveMessage field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DisableResolveMessage field is set to the value of the last call. -func (b *IntegrationApplyConfiguration) WithDisableResolveMessage(value bool) *IntegrationApplyConfiguration { - b.DisableResolveMessage = &value - return b -} - -// WithSecureFields puts the entries into the SecureFields field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the SecureFields field, -// overwriting an existing map entries in SecureFields field with the same key. -func (b *IntegrationApplyConfiguration) WithSecureFields(entries map[string]bool) *IntegrationApplyConfiguration { - if b.SecureFields == nil && len(entries) > 0 { - b.SecureFields = make(map[string]bool, len(entries)) - } - for k, v := range entries { - b.SecureFields[k] = v - } - return b -} - -// WithSettings sets the Settings field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Settings field is set to the value of the last call. -func (b *IntegrationApplyConfiguration) WithSettings(value v0alpha1.Unstructured) *IntegrationApplyConfiguration { - b.Settings = &value - return b -} - -// WithType sets the Type field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Type field is set to the value of the last call. -func (b *IntegrationApplyConfiguration) WithType(value string) *IntegrationApplyConfiguration { - b.Type = &value - return b -} - -// WithUid sets the Uid field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Uid field is set to the value of the last call. -func (b *IntegrationApplyConfiguration) WithUid(value string) *IntegrationApplyConfiguration { - b.Uid = &value - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/interval.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/interval.go deleted file mode 100644 index 0354cc603ba..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/interval.go +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// IntervalApplyConfiguration represents a declarative configuration of the Interval type for use -// with apply. -type IntervalApplyConfiguration struct { - DaysOfMonth []string `json:"days_of_month,omitempty"` - Location *string `json:"location,omitempty"` - Months []string `json:"months,omitempty"` - Times []TimeRangeApplyConfiguration `json:"times,omitempty"` - Weekdays []string `json:"weekdays,omitempty"` - Years []string `json:"years,omitempty"` -} - -// IntervalApplyConfiguration constructs a declarative configuration of the Interval type for use with -// apply. -func Interval() *IntervalApplyConfiguration { - return &IntervalApplyConfiguration{} -} - -// WithDaysOfMonth adds the given value to the DaysOfMonth field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the DaysOfMonth field. -func (b *IntervalApplyConfiguration) WithDaysOfMonth(values ...string) *IntervalApplyConfiguration { - for i := range values { - b.DaysOfMonth = append(b.DaysOfMonth, values[i]) - } - return b -} - -// WithLocation sets the Location field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Location field is set to the value of the last call. -func (b *IntervalApplyConfiguration) WithLocation(value string) *IntervalApplyConfiguration { - b.Location = &value - return b -} - -// WithMonths adds the given value to the Months field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Months field. -func (b *IntervalApplyConfiguration) WithMonths(values ...string) *IntervalApplyConfiguration { - for i := range values { - b.Months = append(b.Months, values[i]) - } - return b -} - -// WithTimes adds the given value to the Times field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Times field. -func (b *IntervalApplyConfiguration) WithTimes(values ...*TimeRangeApplyConfiguration) *IntervalApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithTimes") - } - b.Times = append(b.Times, *values[i]) - } - return b -} - -// WithWeekdays adds the given value to the Weekdays field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Weekdays field. -func (b *IntervalApplyConfiguration) WithWeekdays(values ...string) *IntervalApplyConfiguration { - for i := range values { - b.Weekdays = append(b.Weekdays, values[i]) - } - return b -} - -// WithYears adds the given value to the Years field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Years field. -func (b *IntervalApplyConfiguration) WithYears(values ...string) *IntervalApplyConfiguration { - for i := range values { - b.Years = append(b.Years, values[i]) - } - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/matcher.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/matcher.go deleted file mode 100644 index cbbe6a6c5be..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/matcher.go +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" -) - -// MatcherApplyConfiguration represents a declarative configuration of the Matcher type for use -// with apply. -type MatcherApplyConfiguration struct { - Label *string `json:"label,omitempty"` - Type *v0alpha1.MatcherType `json:"type,omitempty"` - Value *string `json:"value,omitempty"` -} - -// MatcherApplyConfiguration constructs a declarative configuration of the Matcher type for use with -// apply. -func Matcher() *MatcherApplyConfiguration { - return &MatcherApplyConfiguration{} -} - -// WithLabel sets the Label field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Label field is set to the value of the last call. -func (b *MatcherApplyConfiguration) WithLabel(value string) *MatcherApplyConfiguration { - b.Label = &value - return b -} - -// WithType sets the Type field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Type field is set to the value of the last call. -func (b *MatcherApplyConfiguration) WithType(value v0alpha1.MatcherType) *MatcherApplyConfiguration { - b.Type = &value - return b -} - -// WithValue sets the Value field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Value field is set to the value of the last call. -func (b *MatcherApplyConfiguration) WithValue(value string) *MatcherApplyConfiguration { - b.Value = &value - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiver.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiver.go deleted file mode 100644 index fb663d04903..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiver.go +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// ReceiverApplyConfiguration represents a declarative configuration of the Receiver type for use -// with apply. -type ReceiverApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *ReceiverSpecApplyConfiguration `json:"spec,omitempty"` -} - -// Receiver constructs a declarative configuration of the Receiver type for use with -// apply. -func Receiver(name, namespace string) *ReceiverApplyConfiguration { - b := &ReceiverApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("Receiver") - b.WithAPIVersion("notifications.alerting.grafana.app/v0alpha1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithKind(value string) *ReceiverApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithAPIVersion(value string) *ReceiverApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithName(value string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithGenerateName(value string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithNamespace(value string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithUID(value types.UID) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithResourceVersion(value string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithGeneration(value int64) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *ReceiverApplyConfiguration) WithLabels(entries map[string]string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *ReceiverApplyConfiguration) WithAnnotations(entries map[string]string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *ReceiverApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *ReceiverApplyConfiguration) WithFinalizers(values ...string) *ReceiverApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *ReceiverApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *ReceiverApplyConfiguration) WithSpec(value *ReceiverSpecApplyConfiguration) *ReceiverApplyConfiguration { - b.Spec = value - return b -} - -// GetName retrieves the value of the Name field in the declarative configuration. -func (b *ReceiverApplyConfiguration) GetName() *string { - b.ensureObjectMetaApplyConfigurationExists() - return b.Name -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiverspec.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiverspec.go deleted file mode 100644 index e5f89b53e9b..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/receiverspec.go +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// ReceiverSpecApplyConfiguration represents a declarative configuration of the ReceiverSpec type for use -// with apply. -type ReceiverSpecApplyConfiguration struct { - Integrations []IntegrationApplyConfiguration `json:"integrations,omitempty"` - Title *string `json:"title,omitempty"` -} - -// ReceiverSpecApplyConfiguration constructs a declarative configuration of the ReceiverSpec type for use with -// apply. -func ReceiverSpec() *ReceiverSpecApplyConfiguration { - return &ReceiverSpecApplyConfiguration{} -} - -// WithIntegrations adds the given value to the Integrations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Integrations field. -func (b *ReceiverSpecApplyConfiguration) WithIntegrations(values ...*IntegrationApplyConfiguration) *ReceiverSpecApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithIntegrations") - } - b.Integrations = append(b.Integrations, *values[i]) - } - return b -} - -// WithTitle sets the Title field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Title field is set to the value of the last call. -func (b *ReceiverSpecApplyConfiguration) WithTitle(value string) *ReceiverSpecApplyConfiguration { - b.Title = &value - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/route.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/route.go deleted file mode 100644 index 0a1b1e7bd18..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/route.go +++ /dev/null @@ -1,111 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// RouteApplyConfiguration represents a declarative configuration of the Route type for use -// with apply. -type RouteApplyConfiguration struct { - Continue *bool `json:"continue,omitempty"` - GroupBy []string `json:"group_by,omitempty"` - GroupInterval *string `json:"group_interval,omitempty"` - GroupWait *string `json:"group_wait,omitempty"` - Matchers []MatcherApplyConfiguration `json:"matchers,omitempty"` - MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"` - Receiver *string `json:"receiver,omitempty"` - RepeatInterval *string `json:"repeat_interval,omitempty"` - Routes []RouteApplyConfiguration `json:"routes,omitempty"` -} - -// RouteApplyConfiguration constructs a declarative configuration of the Route type for use with -// apply. -func Route() *RouteApplyConfiguration { - return &RouteApplyConfiguration{} -} - -// WithContinue sets the Continue field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Continue field is set to the value of the last call. -func (b *RouteApplyConfiguration) WithContinue(value bool) *RouteApplyConfiguration { - b.Continue = &value - return b -} - -// WithGroupBy adds the given value to the GroupBy field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the GroupBy field. -func (b *RouteApplyConfiguration) WithGroupBy(values ...string) *RouteApplyConfiguration { - for i := range values { - b.GroupBy = append(b.GroupBy, values[i]) - } - return b -} - -// WithGroupInterval sets the GroupInterval field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GroupInterval field is set to the value of the last call. -func (b *RouteApplyConfiguration) WithGroupInterval(value string) *RouteApplyConfiguration { - b.GroupInterval = &value - return b -} - -// WithGroupWait sets the GroupWait field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GroupWait field is set to the value of the last call. -func (b *RouteApplyConfiguration) WithGroupWait(value string) *RouteApplyConfiguration { - b.GroupWait = &value - return b -} - -// WithMatchers adds the given value to the Matchers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Matchers field. -func (b *RouteApplyConfiguration) WithMatchers(values ...*MatcherApplyConfiguration) *RouteApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithMatchers") - } - b.Matchers = append(b.Matchers, *values[i]) - } - return b -} - -// WithMuteTimeIntervals adds the given value to the MuteTimeIntervals field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the MuteTimeIntervals field. -func (b *RouteApplyConfiguration) WithMuteTimeIntervals(values ...string) *RouteApplyConfiguration { - for i := range values { - b.MuteTimeIntervals = append(b.MuteTimeIntervals, values[i]) - } - return b -} - -// WithReceiver sets the Receiver field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Receiver field is set to the value of the last call. -func (b *RouteApplyConfiguration) WithReceiver(value string) *RouteApplyConfiguration { - b.Receiver = &value - return b -} - -// WithRepeatInterval sets the RepeatInterval field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the RepeatInterval field is set to the value of the last call. -func (b *RouteApplyConfiguration) WithRepeatInterval(value string) *RouteApplyConfiguration { - b.RepeatInterval = &value - return b -} - -// WithRoutes adds the given value to the Routes field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Routes field. -func (b *RouteApplyConfiguration) WithRoutes(values ...*RouteApplyConfiguration) *RouteApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithRoutes") - } - b.Routes = append(b.Routes, *values[i]) - } - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routedefaults.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routedefaults.go deleted file mode 100644 index bf685faa851..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routedefaults.go +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// RouteDefaultsApplyConfiguration represents a declarative configuration of the RouteDefaults type for use -// with apply. -type RouteDefaultsApplyConfiguration struct { - GroupBy []string `json:"group_by,omitempty"` - GroupInterval *string `json:"group_interval,omitempty"` - GroupWait *string `json:"group_wait,omitempty"` - Receiver *string `json:"receiver,omitempty"` - RepeatInterval *string `json:"repeat_interval,omitempty"` -} - -// RouteDefaultsApplyConfiguration constructs a declarative configuration of the RouteDefaults type for use with -// apply. -func RouteDefaults() *RouteDefaultsApplyConfiguration { - return &RouteDefaultsApplyConfiguration{} -} - -// WithGroupBy adds the given value to the GroupBy field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the GroupBy field. -func (b *RouteDefaultsApplyConfiguration) WithGroupBy(values ...string) *RouteDefaultsApplyConfiguration { - for i := range values { - b.GroupBy = append(b.GroupBy, values[i]) - } - return b -} - -// WithGroupInterval sets the GroupInterval field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GroupInterval field is set to the value of the last call. -func (b *RouteDefaultsApplyConfiguration) WithGroupInterval(value string) *RouteDefaultsApplyConfiguration { - b.GroupInterval = &value - return b -} - -// WithGroupWait sets the GroupWait field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GroupWait field is set to the value of the last call. -func (b *RouteDefaultsApplyConfiguration) WithGroupWait(value string) *RouteDefaultsApplyConfiguration { - b.GroupWait = &value - return b -} - -// WithReceiver sets the Receiver field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Receiver field is set to the value of the last call. -func (b *RouteDefaultsApplyConfiguration) WithReceiver(value string) *RouteDefaultsApplyConfiguration { - b.Receiver = &value - return b -} - -// WithRepeatInterval sets the RepeatInterval field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the RepeatInterval field is set to the value of the last call. -func (b *RouteDefaultsApplyConfiguration) WithRepeatInterval(value string) *RouteDefaultsApplyConfiguration { - b.RepeatInterval = &value - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtree.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtree.go deleted file mode 100644 index f801d1815f5..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtree.go +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// RoutingTreeApplyConfiguration represents a declarative configuration of the RoutingTree type for use -// with apply. -type RoutingTreeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *RoutingTreeSpecApplyConfiguration `json:"spec,omitempty"` -} - -// RoutingTree constructs a declarative configuration of the RoutingTree type for use with -// apply. -func RoutingTree(name, namespace string) *RoutingTreeApplyConfiguration { - b := &RoutingTreeApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("RoutingTree") - b.WithAPIVersion("notifications.alerting.grafana.app/v0alpha1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithKind(value string) *RoutingTreeApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithAPIVersion(value string) *RoutingTreeApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithName(value string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithGenerateName(value string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithNamespace(value string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithUID(value types.UID) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithResourceVersion(value string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithGeneration(value int64) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *RoutingTreeApplyConfiguration) WithLabels(entries map[string]string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *RoutingTreeApplyConfiguration) WithAnnotations(entries map[string]string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *RoutingTreeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *RoutingTreeApplyConfiguration) WithFinalizers(values ...string) *RoutingTreeApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *RoutingTreeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *RoutingTreeApplyConfiguration) WithSpec(value *RoutingTreeSpecApplyConfiguration) *RoutingTreeApplyConfiguration { - b.Spec = value - return b -} - -// GetName retrieves the value of the Name field in the declarative configuration. -func (b *RoutingTreeApplyConfiguration) GetName() *string { - b.ensureObjectMetaApplyConfigurationExists() - return b.Name -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtreespec.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtreespec.go deleted file mode 100644 index 1184a7d4244..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/routingtreespec.go +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// RoutingTreeSpecApplyConfiguration represents a declarative configuration of the RoutingTreeSpec type for use -// with apply. -type RoutingTreeSpecApplyConfiguration struct { - Defaults *RouteDefaultsApplyConfiguration `json:"defaults,omitempty"` - Routes []RouteApplyConfiguration `json:"routes,omitempty"` -} - -// RoutingTreeSpecApplyConfiguration constructs a declarative configuration of the RoutingTreeSpec type for use with -// apply. -func RoutingTreeSpec() *RoutingTreeSpecApplyConfiguration { - return &RoutingTreeSpecApplyConfiguration{} -} - -// WithDefaults sets the Defaults field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Defaults field is set to the value of the last call. -func (b *RoutingTreeSpecApplyConfiguration) WithDefaults(value *RouteDefaultsApplyConfiguration) *RoutingTreeSpecApplyConfiguration { - b.Defaults = value - return b -} - -// WithRoutes adds the given value to the Routes field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Routes field. -func (b *RoutingTreeSpecApplyConfiguration) WithRoutes(values ...*RouteApplyConfiguration) *RoutingTreeSpecApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithRoutes") - } - b.Routes = append(b.Routes, *values[i]) - } - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroup.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroup.go deleted file mode 100644 index b4340dcde50..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroup.go +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// TemplateGroupApplyConfiguration represents a declarative configuration of the TemplateGroup type for use -// with apply. -type TemplateGroupApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *TemplateGroupSpecApplyConfiguration `json:"spec,omitempty"` -} - -// TemplateGroup constructs a declarative configuration of the TemplateGroup type for use with -// apply. -func TemplateGroup(name, namespace string) *TemplateGroupApplyConfiguration { - b := &TemplateGroupApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("TemplateGroup") - b.WithAPIVersion("notifications.alerting.grafana.app/v0alpha1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithKind(value string) *TemplateGroupApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithAPIVersion(value string) *TemplateGroupApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithName(value string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithGenerateName(value string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithNamespace(value string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithUID(value types.UID) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithResourceVersion(value string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithGeneration(value int64) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *TemplateGroupApplyConfiguration) WithLabels(entries map[string]string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *TemplateGroupApplyConfiguration) WithAnnotations(entries map[string]string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TemplateGroupApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *TemplateGroupApplyConfiguration) WithFinalizers(values ...string) *TemplateGroupApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *TemplateGroupApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *TemplateGroupApplyConfiguration) WithSpec(value *TemplateGroupSpecApplyConfiguration) *TemplateGroupApplyConfiguration { - b.Spec = value - return b -} - -// GetName retrieves the value of the Name field in the declarative configuration. -func (b *TemplateGroupApplyConfiguration) GetName() *string { - b.ensureObjectMetaApplyConfigurationExists() - return b.Name -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroupspec.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroupspec.go deleted file mode 100644 index 42fcad447be..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/templategroupspec.go +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// TemplateGroupSpecApplyConfiguration represents a declarative configuration of the TemplateGroupSpec type for use -// with apply. -type TemplateGroupSpecApplyConfiguration struct { - Title *string `json:"title,omitempty"` - Content *string `json:"content,omitempty"` -} - -// TemplateGroupSpecApplyConfiguration constructs a declarative configuration of the TemplateGroupSpec type for use with -// apply. -func TemplateGroupSpec() *TemplateGroupSpecApplyConfiguration { - return &TemplateGroupSpecApplyConfiguration{} -} - -// WithTitle sets the Title field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Title field is set to the value of the last call. -func (b *TemplateGroupSpecApplyConfiguration) WithTitle(value string) *TemplateGroupSpecApplyConfiguration { - b.Title = &value - return b -} - -// WithContent sets the Content field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Content field is set to the value of the last call. -func (b *TemplateGroupSpecApplyConfiguration) WithContent(value string) *TemplateGroupSpecApplyConfiguration { - b.Content = &value - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeinterval.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeinterval.go deleted file mode 100644 index 618f6a4d009..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeinterval.go +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" -) - -// TimeIntervalApplyConfiguration represents a declarative configuration of the TimeInterval type for use -// with apply. -type TimeIntervalApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Spec *TimeIntervalSpecApplyConfiguration `json:"spec,omitempty"` -} - -// TimeInterval constructs a declarative configuration of the TimeInterval type for use with -// apply. -func TimeInterval(name, namespace string) *TimeIntervalApplyConfiguration { - b := &TimeIntervalApplyConfiguration{} - b.WithName(name) - b.WithNamespace(namespace) - b.WithKind("TimeInterval") - b.WithAPIVersion("notifications.alerting.grafana.app/v0alpha1") - return b -} - -// WithKind sets the Kind field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Kind field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithKind(value string) *TimeIntervalApplyConfiguration { - b.Kind = &value - return b -} - -// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the APIVersion field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithAPIVersion(value string) *TimeIntervalApplyConfiguration { - b.APIVersion = &value - return b -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithName(value string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value - return b -} - -// WithGenerateName sets the GenerateName field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the GenerateName field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithGenerateName(value string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value - return b -} - -// WithNamespace sets the Namespace field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Namespace field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithNamespace(value string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value - return b -} - -// WithUID sets the UID field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the UID field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithUID(value types.UID) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value - return b -} - -// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ResourceVersion field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithResourceVersion(value string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value - return b -} - -// WithGeneration sets the Generation field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Generation field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithGeneration(value int64) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value - return b -} - -// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value - return b -} - -// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value - return b -} - -// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value - return b -} - -// WithLabels puts the entries into the Labels field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Labels field, -// overwriting an existing map entries in Labels field with the same key. -func (b *TimeIntervalApplyConfiguration) WithLabels(entries map[string]string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Labels[k] = v - } - return b -} - -// WithAnnotations puts the entries into the Annotations field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, the entries provided by each call will be put on the Annotations field, -// overwriting an existing map entries in Annotations field with the same key. -func (b *TimeIntervalApplyConfiguration) WithAnnotations(entries map[string]string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) - } - for k, v := range entries { - b.Annotations[k] = v - } - return b -} - -// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TimeIntervalApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - if values[i] == nil { - panic("nil value passed to WithOwnerReferences") - } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) - } - return b -} - -// WithFinalizers adds the given value to the Finalizers field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the Finalizers field. -func (b *TimeIntervalApplyConfiguration) WithFinalizers(values ...string) *TimeIntervalApplyConfiguration { - b.ensureObjectMetaApplyConfigurationExists() - for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) - } - return b -} - -func (b *TimeIntervalApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { - if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} - } -} - -// WithSpec sets the Spec field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Spec field is set to the value of the last call. -func (b *TimeIntervalApplyConfiguration) WithSpec(value *TimeIntervalSpecApplyConfiguration) *TimeIntervalApplyConfiguration { - b.Spec = value - return b -} - -// GetName retrieves the value of the Name field in the declarative configuration. -func (b *TimeIntervalApplyConfiguration) GetName() *string { - b.ensureObjectMetaApplyConfigurationExists() - return b.Name -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeintervalspec.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeintervalspec.go deleted file mode 100644 index f9f6d4977b7..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timeintervalspec.go +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// TimeIntervalSpecApplyConfiguration represents a declarative configuration of the TimeIntervalSpec type for use -// with apply. -type TimeIntervalSpecApplyConfiguration struct { - Name *string `json:"name,omitempty"` - TimeIntervals []IntervalApplyConfiguration `json:"time_intervals,omitempty"` -} - -// TimeIntervalSpecApplyConfiguration constructs a declarative configuration of the TimeIntervalSpec type for use with -// apply. -func TimeIntervalSpec() *TimeIntervalSpecApplyConfiguration { - return &TimeIntervalSpecApplyConfiguration{} -} - -// WithName sets the Name field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the Name field is set to the value of the last call. -func (b *TimeIntervalSpecApplyConfiguration) WithName(value string) *TimeIntervalSpecApplyConfiguration { - b.Name = &value - return b -} - -// WithTimeIntervals adds the given value to the TimeIntervals field in the declarative configuration -// and returns the receiver, so that objects can be build by chaining "With" function invocations. -// If called multiple times, values provided by each call will be appended to the TimeIntervals field. -func (b *TimeIntervalSpecApplyConfiguration) WithTimeIntervals(values ...*IntervalApplyConfiguration) *TimeIntervalSpecApplyConfiguration { - for i := range values { - if values[i] == nil { - panic("nil value passed to WithTimeIntervals") - } - b.TimeIntervals = append(b.TimeIntervals, *values[i]) - } - return b -} diff --git a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timerange.go b/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timerange.go deleted file mode 100644 index 01e83a9d9da..00000000000 --- a/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1/timerange.go +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by applyconfiguration-gen. DO NOT EDIT. - -package v0alpha1 - -// TimeRangeApplyConfiguration represents a declarative configuration of the TimeRange type for use -// with apply. -type TimeRangeApplyConfiguration struct { - EndTime *string `json:"end_time,omitempty"` - StartTime *string `json:"start_time,omitempty"` -} - -// TimeRangeApplyConfiguration constructs a declarative configuration of the TimeRange type for use with -// apply. -func TimeRange() *TimeRangeApplyConfiguration { - return &TimeRangeApplyConfiguration{} -} - -// WithEndTime sets the EndTime field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the EndTime field is set to the value of the last call. -func (b *TimeRangeApplyConfiguration) WithEndTime(value string) *TimeRangeApplyConfiguration { - b.EndTime = &value - return b -} - -// WithStartTime sets the StartTime field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the StartTime field is set to the value of the last call. -func (b *TimeRangeApplyConfiguration) WithStartTime(value string) *TimeRangeApplyConfiguration { - b.StartTime = &value - return b -} diff --git a/pkg/generated/applyconfiguration/utils.go b/pkg/generated/applyconfiguration/utils.go index 10aa8312bca..d792c0be680 100644 --- a/pkg/generated/applyconfiguration/utils.go +++ b/pkg/generated/applyconfiguration/utils.go @@ -5,11 +5,9 @@ package applyconfiguration import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" + v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" internal "github.com/grafana/grafana/pkg/generated/applyconfiguration/internal" - applyconfigurationservicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/service/v0alpha1" + servicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/service/v0alpha1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" testing "k8s.io/client-go/testing" @@ -19,41 +17,11 @@ import ( // apply configuration type exists for the given GroupVersionKind. func ForKind(kind schema.GroupVersionKind) interface{} { switch kind { - // Group=notifications.alerting.grafana.app, Version=v0alpha1 - case v0alpha1.SchemeGroupVersion.WithKind("Integration"): - return &alertingnotificationsv0alpha1.IntegrationApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("Interval"): - return &alertingnotificationsv0alpha1.IntervalApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("Matcher"): - return &alertingnotificationsv0alpha1.MatcherApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("Receiver"): - return &alertingnotificationsv0alpha1.ReceiverApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("ReceiverSpec"): - return &alertingnotificationsv0alpha1.ReceiverSpecApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("Route"): - return &alertingnotificationsv0alpha1.RouteApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("RouteDefaults"): - return &alertingnotificationsv0alpha1.RouteDefaultsApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("RoutingTree"): - return &alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("RoutingTreeSpec"): - return &alertingnotificationsv0alpha1.RoutingTreeSpecApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("TemplateGroup"): - return &alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("TemplateGroupSpec"): - return &alertingnotificationsv0alpha1.TemplateGroupSpecApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("TimeInterval"): - return &alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("TimeIntervalSpec"): - return &alertingnotificationsv0alpha1.TimeIntervalSpecApplyConfiguration{} - case v0alpha1.SchemeGroupVersion.WithKind("TimeRange"): - return &alertingnotificationsv0alpha1.TimeRangeApplyConfiguration{} - - // Group=service.grafana.app, Version=v0alpha1 - case servicev0alpha1.SchemeGroupVersion.WithKind("ExternalName"): - return &applyconfigurationservicev0alpha1.ExternalNameApplyConfiguration{} - case servicev0alpha1.SchemeGroupVersion.WithKind("ExternalNameSpec"): - return &applyconfigurationservicev0alpha1.ExternalNameSpecApplyConfiguration{} + // Group=service.grafana.app, Version=v0alpha1 + case v0alpha1.SchemeGroupVersion.WithKind("ExternalName"): + return &servicev0alpha1.ExternalNameApplyConfiguration{} + case v0alpha1.SchemeGroupVersion.WithKind("ExternalNameSpec"): + return &servicev0alpha1.ExternalNameSpecApplyConfiguration{} } return nil diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index dc02a208e84..55fa581701a 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -8,7 +8,6 @@ import ( "fmt" "net/http" - notificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/service/v0alpha1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -17,20 +16,13 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface - NotificationsV0alpha1() notificationsv0alpha1.NotificationsV0alpha1Interface ServiceV0alpha1() servicev0alpha1.ServiceV0alpha1Interface } // Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient - notificationsV0alpha1 *notificationsv0alpha1.NotificationsV0alpha1Client - serviceV0alpha1 *servicev0alpha1.ServiceV0alpha1Client -} - -// NotificationsV0alpha1 retrieves the NotificationsV0alpha1Client -func (c *Clientset) NotificationsV0alpha1() notificationsv0alpha1.NotificationsV0alpha1Interface { - return c.notificationsV0alpha1 + serviceV0alpha1 *servicev0alpha1.ServiceV0alpha1Client } // ServiceV0alpha1 retrieves the ServiceV0alpha1Client @@ -82,10 +74,6 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, var cs Clientset var err error - cs.notificationsV0alpha1, err = notificationsv0alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } cs.serviceV0alpha1, err = servicev0alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -111,7 +99,6 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset - cs.notificationsV0alpha1 = notificationsv0alpha1.New(c) cs.serviceV0alpha1 = servicev0alpha1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 8fb5f797700..0db3aa0390a 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -7,8 +7,6 @@ package fake import ( applyconfiguration "github.com/grafana/grafana/pkg/generated/applyconfiguration" clientset "github.com/grafana/grafana/pkg/generated/clientset/versioned" - notificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" - fakenotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake" servicev0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/service/v0alpha1" fakeservicev0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/service/v0alpha1/fake" "k8s.io/apimachinery/pkg/runtime" @@ -104,11 +102,6 @@ var ( _ testing.FakeClient = &Clientset{} ) -// NotificationsV0alpha1 retrieves the NotificationsV0alpha1Client -func (c *Clientset) NotificationsV0alpha1() notificationsv0alpha1.NotificationsV0alpha1Interface { - return &fakenotificationsv0alpha1.FakeNotificationsV0alpha1{Fake: &c.Fake} -} - // ServiceV0alpha1 retrieves the ServiceV0alpha1Client func (c *Clientset) ServiceV0alpha1() servicev0alpha1.ServiceV0alpha1Interface { return &fakeservicev0alpha1.FakeServiceV0alpha1{Fake: &c.Fake} diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go index 00ae96dd36e..bbf12658e76 100644 --- a/pkg/generated/clientset/versioned/fake/register.go +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -5,7 +5,6 @@ package fake import ( - notificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -18,7 +17,6 @@ var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - notificationsv0alpha1.AddToScheme, servicev0alpha1.AddToScheme, } diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go index 6ae4e0deec1..dd6e9619160 100644 --- a/pkg/generated/clientset/versioned/scheme/register.go +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -5,7 +5,6 @@ package scheme import ( - notificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -18,7 +17,6 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - notificationsv0alpha1.AddToScheme, servicev0alpha1.AddToScheme, } diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/alerting_notifications_client.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/alerting_notifications_client.go deleted file mode 100644 index 16770726462..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/alerting_notifications_client.go +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "net/http" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme" - rest "k8s.io/client-go/rest" -) - -type NotificationsV0alpha1Interface interface { - RESTClient() rest.Interface - ReceiversGetter - RoutingTreesGetter - TemplateGroupsGetter - TimeIntervalsGetter -} - -// NotificationsV0alpha1Client is used to interact with features provided by the notifications.alerting.grafana.app group. -type NotificationsV0alpha1Client struct { - restClient rest.Interface -} - -func (c *NotificationsV0alpha1Client) Receivers(namespace string) ReceiverInterface { - return newReceivers(c, namespace) -} - -func (c *NotificationsV0alpha1Client) RoutingTrees(namespace string) RoutingTreeInterface { - return newRoutingTrees(c, namespace) -} - -func (c *NotificationsV0alpha1Client) TemplateGroups(namespace string) TemplateGroupInterface { - return newTemplateGroups(c, namespace) -} - -func (c *NotificationsV0alpha1Client) TimeIntervals(namespace string) TimeIntervalInterface { - return newTimeIntervals(c, namespace) -} - -// NewForConfig creates a new NotificationsV0alpha1Client for the given config. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*NotificationsV0alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - httpClient, err := rest.HTTPClientFor(&config) - if err != nil { - return nil, err - } - return NewForConfigAndClient(&config, httpClient) -} - -// NewForConfigAndClient creates a new NotificationsV0alpha1Client for the given config and http client. -// Note the http client provided takes precedence over the configured transport values. -func NewForConfigAndClient(c *rest.Config, h *http.Client) (*NotificationsV0alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientForConfigAndClient(&config, h) - if err != nil { - return nil, err - } - return &NotificationsV0alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new NotificationsV0alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *NotificationsV0alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new NotificationsV0alpha1Client for the given RESTClient. -func New(c rest.Interface) *NotificationsV0alpha1Client { - return &NotificationsV0alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v0alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *NotificationsV0alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/doc.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/doc.go deleted file mode 100644 index 1c86744fecc..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v0alpha1 diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/doc.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/doc.go deleted file mode 100644 index d96b985b3ea..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_alerting_notifications_client.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_alerting_notifications_client.go deleted file mode 100644 index fce832e1b2f..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_alerting_notifications_client.go +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeNotificationsV0alpha1 struct { - *testing.Fake -} - -func (c *FakeNotificationsV0alpha1) Receivers(namespace string) v0alpha1.ReceiverInterface { - return &FakeReceivers{c, namespace} -} - -func (c *FakeNotificationsV0alpha1) RoutingTrees(namespace string) v0alpha1.RoutingTreeInterface { - return &FakeRoutingTrees{c, namespace} -} - -func (c *FakeNotificationsV0alpha1) TemplateGroups(namespace string) v0alpha1.TemplateGroupInterface { - return &FakeTemplateGroups{c, namespace} -} - -func (c *FakeNotificationsV0alpha1) TimeIntervals(namespace string) v0alpha1.TimeIntervalInterface { - return &FakeTimeIntervals{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeNotificationsV0alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_receiver.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_receiver.go deleted file mode 100644 index c73360086b8..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_receiver.go +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - json "encoding/json" - "fmt" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeReceivers implements ReceiverInterface -type FakeReceivers struct { - Fake *FakeNotificationsV0alpha1 - ns string -} - -var receiversResource = v0alpha1.SchemeGroupVersion.WithResource("receivers") - -var receiversKind = v0alpha1.SchemeGroupVersion.WithKind("Receiver") - -// Get takes name of the receiver, and returns the corresponding receiver object, and an error if there is any. -func (c *FakeReceivers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.Receiver, err error) { - emptyResult := &v0alpha1.Receiver{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(receiversResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.Receiver), err -} - -// List takes label and field selectors, and returns the list of Receivers that match those selectors. -func (c *FakeReceivers) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ReceiverList, err error) { - emptyResult := &v0alpha1.ReceiverList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(receiversResource, receiversKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v0alpha1.ReceiverList{ListMeta: obj.(*v0alpha1.ReceiverList).ListMeta} - for _, item := range obj.(*v0alpha1.ReceiverList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested receivers. -func (c *FakeReceivers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(receiversResource, c.ns, opts)) - -} - -// Create takes the representation of a receiver and creates it. Returns the server's representation of the receiver, and an error, if there is any. -func (c *FakeReceivers) Create(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.CreateOptions) (result *v0alpha1.Receiver, err error) { - emptyResult := &v0alpha1.Receiver{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(receiversResource, c.ns, receiver, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.Receiver), err -} - -// Update takes the representation of a receiver and updates it. Returns the server's representation of the receiver, and an error, if there is any. -func (c *FakeReceivers) Update(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.UpdateOptions) (result *v0alpha1.Receiver, err error) { - emptyResult := &v0alpha1.Receiver{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(receiversResource, c.ns, receiver, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.Receiver), err -} - -// Delete takes name of the receiver and deletes it. Returns an error if one occurs. -func (c *FakeReceivers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(receiversResource, c.ns, name, opts), &v0alpha1.Receiver{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeReceivers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(receiversResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v0alpha1.ReceiverList{}) - return err -} - -// Patch applies the patch and returns the patched receiver. -func (c *FakeReceivers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.Receiver, err error) { - emptyResult := &v0alpha1.Receiver{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(receiversResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.Receiver), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied receiver. -func (c *FakeReceivers) Apply(ctx context.Context, receiver *alertingnotificationsv0alpha1.ReceiverApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.Receiver, err error) { - if receiver == nil { - return nil, fmt.Errorf("receiver provided to Apply must not be nil") - } - data, err := json.Marshal(receiver) - if err != nil { - return nil, err - } - name := receiver.Name - if name == nil { - return nil, fmt.Errorf("receiver.Name must be provided to Apply") - } - emptyResult := &v0alpha1.Receiver{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(receiversResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.Receiver), err -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_routingtree.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_routingtree.go deleted file mode 100644 index 1d6f7badafe..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_routingtree.go +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - json "encoding/json" - "fmt" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeRoutingTrees implements RoutingTreeInterface -type FakeRoutingTrees struct { - Fake *FakeNotificationsV0alpha1 - ns string -} - -var routingtreesResource = v0alpha1.SchemeGroupVersion.WithResource("routingtrees") - -var routingtreesKind = v0alpha1.SchemeGroupVersion.WithKind("RoutingTree") - -// Get takes name of the routingTree, and returns the corresponding routingTree object, and an error if there is any. -func (c *FakeRoutingTrees) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.RoutingTree, err error) { - emptyResult := &v0alpha1.RoutingTree{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(routingtreesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.RoutingTree), err -} - -// List takes label and field selectors, and returns the list of RoutingTrees that match those selectors. -func (c *FakeRoutingTrees) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.RoutingTreeList, err error) { - emptyResult := &v0alpha1.RoutingTreeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(routingtreesResource, routingtreesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v0alpha1.RoutingTreeList{ListMeta: obj.(*v0alpha1.RoutingTreeList).ListMeta} - for _, item := range obj.(*v0alpha1.RoutingTreeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested routingTrees. -func (c *FakeRoutingTrees) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(routingtreesResource, c.ns, opts)) - -} - -// Create takes the representation of a routingTree and creates it. Returns the server's representation of the routingTree, and an error, if there is any. -func (c *FakeRoutingTrees) Create(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.CreateOptions) (result *v0alpha1.RoutingTree, err error) { - emptyResult := &v0alpha1.RoutingTree{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(routingtreesResource, c.ns, routingTree, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.RoutingTree), err -} - -// Update takes the representation of a routingTree and updates it. Returns the server's representation of the routingTree, and an error, if there is any. -func (c *FakeRoutingTrees) Update(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.UpdateOptions) (result *v0alpha1.RoutingTree, err error) { - emptyResult := &v0alpha1.RoutingTree{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(routingtreesResource, c.ns, routingTree, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.RoutingTree), err -} - -// Delete takes name of the routingTree and deletes it. Returns an error if one occurs. -func (c *FakeRoutingTrees) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(routingtreesResource, c.ns, name, opts), &v0alpha1.RoutingTree{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeRoutingTrees) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(routingtreesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v0alpha1.RoutingTreeList{}) - return err -} - -// Patch applies the patch and returns the patched routingTree. -func (c *FakeRoutingTrees) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.RoutingTree, err error) { - emptyResult := &v0alpha1.RoutingTree{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(routingtreesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.RoutingTree), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied routingTree. -func (c *FakeRoutingTrees) Apply(ctx context.Context, routingTree *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.RoutingTree, err error) { - if routingTree == nil { - return nil, fmt.Errorf("routingTree provided to Apply must not be nil") - } - data, err := json.Marshal(routingTree) - if err != nil { - return nil, err - } - name := routingTree.Name - if name == nil { - return nil, fmt.Errorf("routingTree.Name must be provided to Apply") - } - emptyResult := &v0alpha1.RoutingTree{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(routingtreesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.RoutingTree), err -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_templategroup.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_templategroup.go deleted file mode 100644 index ffbd0668e4b..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_templategroup.go +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - json "encoding/json" - "fmt" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeTemplateGroups implements TemplateGroupInterface -type FakeTemplateGroups struct { - Fake *FakeNotificationsV0alpha1 - ns string -} - -var templategroupsResource = v0alpha1.SchemeGroupVersion.WithResource("templategroups") - -var templategroupsKind = v0alpha1.SchemeGroupVersion.WithKind("TemplateGroup") - -// Get takes name of the templateGroup, and returns the corresponding templateGroup object, and an error if there is any. -func (c *FakeTemplateGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.TemplateGroup, err error) { - emptyResult := &v0alpha1.TemplateGroup{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(templategroupsResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TemplateGroup), err -} - -// List takes label and field selectors, and returns the list of TemplateGroups that match those selectors. -func (c *FakeTemplateGroups) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.TemplateGroupList, err error) { - emptyResult := &v0alpha1.TemplateGroupList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(templategroupsResource, templategroupsKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v0alpha1.TemplateGroupList{ListMeta: obj.(*v0alpha1.TemplateGroupList).ListMeta} - for _, item := range obj.(*v0alpha1.TemplateGroupList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested templateGroups. -func (c *FakeTemplateGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(templategroupsResource, c.ns, opts)) - -} - -// Create takes the representation of a templateGroup and creates it. Returns the server's representation of the templateGroup, and an error, if there is any. -func (c *FakeTemplateGroups) Create(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.CreateOptions) (result *v0alpha1.TemplateGroup, err error) { - emptyResult := &v0alpha1.TemplateGroup{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(templategroupsResource, c.ns, templateGroup, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TemplateGroup), err -} - -// Update takes the representation of a templateGroup and updates it. Returns the server's representation of the templateGroup, and an error, if there is any. -func (c *FakeTemplateGroups) Update(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.UpdateOptions) (result *v0alpha1.TemplateGroup, err error) { - emptyResult := &v0alpha1.TemplateGroup{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(templategroupsResource, c.ns, templateGroup, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TemplateGroup), err -} - -// Delete takes name of the templateGroup and deletes it. Returns an error if one occurs. -func (c *FakeTemplateGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(templategroupsResource, c.ns, name, opts), &v0alpha1.TemplateGroup{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTemplateGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(templategroupsResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v0alpha1.TemplateGroupList{}) - return err -} - -// Patch applies the patch and returns the patched templateGroup. -func (c *FakeTemplateGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TemplateGroup, err error) { - emptyResult := &v0alpha1.TemplateGroup{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(templategroupsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TemplateGroup), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied templateGroup. -func (c *FakeTemplateGroups) Apply(ctx context.Context, templateGroup *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TemplateGroup, err error) { - if templateGroup == nil { - return nil, fmt.Errorf("templateGroup provided to Apply must not be nil") - } - data, err := json.Marshal(templateGroup) - if err != nil { - return nil, err - } - name := templateGroup.Name - if name == nil { - return nil, fmt.Errorf("templateGroup.Name must be provided to Apply") - } - emptyResult := &v0alpha1.TemplateGroup{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(templategroupsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TemplateGroup), err -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_timeinterval.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_timeinterval.go deleted file mode 100644 index 08392c1834d..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake/fake_timeinterval.go +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - json "encoding/json" - "fmt" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeTimeIntervals implements TimeIntervalInterface -type FakeTimeIntervals struct { - Fake *FakeNotificationsV0alpha1 - ns string -} - -var timeintervalsResource = v0alpha1.SchemeGroupVersion.WithResource("timeintervals") - -var timeintervalsKind = v0alpha1.SchemeGroupVersion.WithKind("TimeInterval") - -// Get takes name of the timeInterval, and returns the corresponding timeInterval object, and an error if there is any. -func (c *FakeTimeIntervals) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.TimeInterval, err error) { - emptyResult := &v0alpha1.TimeInterval{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(timeintervalsResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TimeInterval), err -} - -// List takes label and field selectors, and returns the list of TimeIntervals that match those selectors. -func (c *FakeTimeIntervals) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.TimeIntervalList, err error) { - emptyResult := &v0alpha1.TimeIntervalList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(timeintervalsResource, timeintervalsKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v0alpha1.TimeIntervalList{ListMeta: obj.(*v0alpha1.TimeIntervalList).ListMeta} - for _, item := range obj.(*v0alpha1.TimeIntervalList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested timeIntervals. -func (c *FakeTimeIntervals) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(timeintervalsResource, c.ns, opts)) - -} - -// Create takes the representation of a timeInterval and creates it. Returns the server's representation of the timeInterval, and an error, if there is any. -func (c *FakeTimeIntervals) Create(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.CreateOptions) (result *v0alpha1.TimeInterval, err error) { - emptyResult := &v0alpha1.TimeInterval{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(timeintervalsResource, c.ns, timeInterval, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TimeInterval), err -} - -// Update takes the representation of a timeInterval and updates it. Returns the server's representation of the timeInterval, and an error, if there is any. -func (c *FakeTimeIntervals) Update(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.UpdateOptions) (result *v0alpha1.TimeInterval, err error) { - emptyResult := &v0alpha1.TimeInterval{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(timeintervalsResource, c.ns, timeInterval, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TimeInterval), err -} - -// Delete takes name of the timeInterval and deletes it. Returns an error if one occurs. -func (c *FakeTimeIntervals) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(timeintervalsResource, c.ns, name, opts), &v0alpha1.TimeInterval{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTimeIntervals) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(timeintervalsResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v0alpha1.TimeIntervalList{}) - return err -} - -// Patch applies the patch and returns the patched timeInterval. -func (c *FakeTimeIntervals) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TimeInterval, err error) { - emptyResult := &v0alpha1.TimeInterval{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(timeintervalsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TimeInterval), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied timeInterval. -func (c *FakeTimeIntervals) Apply(ctx context.Context, timeInterval *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TimeInterval, err error) { - if timeInterval == nil { - return nil, fmt.Errorf("timeInterval provided to Apply must not be nil") - } - data, err := json.Marshal(timeInterval) - if err != nil { - return nil, err - } - name := timeInterval.Name - if name == nil { - return nil, fmt.Errorf("timeInterval.Name must be provided to Apply") - } - emptyResult := &v0alpha1.TimeInterval{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(timeintervalsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v0alpha1.TimeInterval), err -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/generated_expansion.go deleted file mode 100644 index 5d92113ab80..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/generated_expansion.go +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -type ReceiverExpansion interface{} - -type RoutingTreeExpansion interface{} - -type TemplateGroupExpansion interface{} - -type TimeIntervalExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/receiver.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/receiver.go deleted file mode 100644 index 5b608f6fc2b..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/receiver.go +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - scheme "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" -) - -// ReceiversGetter has a method to return a ReceiverInterface. -// A group's client should implement this interface. -type ReceiversGetter interface { - Receivers(namespace string) ReceiverInterface -} - -// ReceiverInterface has methods to work with Receiver resources. -type ReceiverInterface interface { - Create(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.CreateOptions) (*v0alpha1.Receiver, error) - Update(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.UpdateOptions) (*v0alpha1.Receiver, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v0alpha1.Receiver, error) - List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.ReceiverList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.Receiver, err error) - Apply(ctx context.Context, receiver *alertingnotificationsv0alpha1.ReceiverApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.Receiver, err error) - ReceiverExpansion -} - -// receivers implements ReceiverInterface -type receivers struct { - *gentype.ClientWithListAndApply[*v0alpha1.Receiver, *v0alpha1.ReceiverList, *alertingnotificationsv0alpha1.ReceiverApplyConfiguration] -} - -// newReceivers returns a Receivers -func newReceivers(c *NotificationsV0alpha1Client, namespace string) *receivers { - return &receivers{ - gentype.NewClientWithListAndApply[*v0alpha1.Receiver, *v0alpha1.ReceiverList, *alertingnotificationsv0alpha1.ReceiverApplyConfiguration]( - "receivers", - c.RESTClient(), - scheme.ParameterCodec, - namespace, - func() *v0alpha1.Receiver { return &v0alpha1.Receiver{} }, - func() *v0alpha1.ReceiverList { return &v0alpha1.ReceiverList{} }), - } -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/routingtree.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/routingtree.go deleted file mode 100644 index 2996b3983c2..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/routingtree.go +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - scheme "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" -) - -// RoutingTreesGetter has a method to return a RoutingTreeInterface. -// A group's client should implement this interface. -type RoutingTreesGetter interface { - RoutingTrees(namespace string) RoutingTreeInterface -} - -// RoutingTreeInterface has methods to work with RoutingTree resources. -type RoutingTreeInterface interface { - Create(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.CreateOptions) (*v0alpha1.RoutingTree, error) - Update(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.UpdateOptions) (*v0alpha1.RoutingTree, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v0alpha1.RoutingTree, error) - List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.RoutingTreeList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.RoutingTree, err error) - Apply(ctx context.Context, routingTree *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.RoutingTree, err error) - RoutingTreeExpansion -} - -// routingTrees implements RoutingTreeInterface -type routingTrees struct { - *gentype.ClientWithListAndApply[*v0alpha1.RoutingTree, *v0alpha1.RoutingTreeList, *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration] -} - -// newRoutingTrees returns a RoutingTrees -func newRoutingTrees(c *NotificationsV0alpha1Client, namespace string) *routingTrees { - return &routingTrees{ - gentype.NewClientWithListAndApply[*v0alpha1.RoutingTree, *v0alpha1.RoutingTreeList, *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration]( - "routingtrees", - c.RESTClient(), - scheme.ParameterCodec, - namespace, - func() *v0alpha1.RoutingTree { return &v0alpha1.RoutingTree{} }, - func() *v0alpha1.RoutingTreeList { return &v0alpha1.RoutingTreeList{} }), - } -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/templategroup.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/templategroup.go deleted file mode 100644 index 5eb06224934..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/templategroup.go +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - scheme "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" -) - -// TemplateGroupsGetter has a method to return a TemplateGroupInterface. -// A group's client should implement this interface. -type TemplateGroupsGetter interface { - TemplateGroups(namespace string) TemplateGroupInterface -} - -// TemplateGroupInterface has methods to work with TemplateGroup resources. -type TemplateGroupInterface interface { - Create(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.CreateOptions) (*v0alpha1.TemplateGroup, error) - Update(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.UpdateOptions) (*v0alpha1.TemplateGroup, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v0alpha1.TemplateGroup, error) - List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.TemplateGroupList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TemplateGroup, err error) - Apply(ctx context.Context, templateGroup *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TemplateGroup, err error) - TemplateGroupExpansion -} - -// templateGroups implements TemplateGroupInterface -type templateGroups struct { - *gentype.ClientWithListAndApply[*v0alpha1.TemplateGroup, *v0alpha1.TemplateGroupList, *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration] -} - -// newTemplateGroups returns a TemplateGroups -func newTemplateGroups(c *NotificationsV0alpha1Client, namespace string) *templateGroups { - return &templateGroups{ - gentype.NewClientWithListAndApply[*v0alpha1.TemplateGroup, *v0alpha1.TemplateGroupList, *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration]( - "templategroups", - c.RESTClient(), - scheme.ParameterCodec, - namespace, - func() *v0alpha1.TemplateGroup { return &v0alpha1.TemplateGroup{} }, - func() *v0alpha1.TemplateGroupList { return &v0alpha1.TemplateGroupList{} }), - } -} diff --git a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/timeinterval.go b/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/timeinterval.go deleted file mode 100644 index a0a12597e00..00000000000 --- a/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/timeinterval.go +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by client-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" - scheme "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" -) - -// TimeIntervalsGetter has a method to return a TimeIntervalInterface. -// A group's client should implement this interface. -type TimeIntervalsGetter interface { - TimeIntervals(namespace string) TimeIntervalInterface -} - -// TimeIntervalInterface has methods to work with TimeInterval resources. -type TimeIntervalInterface interface { - Create(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.CreateOptions) (*v0alpha1.TimeInterval, error) - Update(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.UpdateOptions) (*v0alpha1.TimeInterval, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v0alpha1.TimeInterval, error) - List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.TimeIntervalList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TimeInterval, err error) - Apply(ctx context.Context, timeInterval *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TimeInterval, err error) - TimeIntervalExpansion -} - -// timeIntervals implements TimeIntervalInterface -type timeIntervals struct { - *gentype.ClientWithListAndApply[*v0alpha1.TimeInterval, *v0alpha1.TimeIntervalList, *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration] -} - -// newTimeIntervals returns a TimeIntervals -func newTimeIntervals(c *NotificationsV0alpha1Client, namespace string) *timeIntervals { - return &timeIntervals{ - gentype.NewClientWithListAndApply[*v0alpha1.TimeInterval, *v0alpha1.TimeIntervalList, *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration]( - "timeintervals", - c.RESTClient(), - scheme.ParameterCodec, - namespace, - func() *v0alpha1.TimeInterval { return &v0alpha1.TimeInterval{} }, - func() *v0alpha1.TimeIntervalList { return &v0alpha1.TimeIntervalList{} }), - } -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/interface.go b/pkg/generated/informers/externalversions/alerting_notifications/interface.go deleted file mode 100644 index 631d480cd39..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/interface.go +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package alerting_notifications - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1" - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" -) - -// Interface provides access to each of this group's versions. -type Interface interface { - // V0alpha1 provides access to shared informers for resources in V0alpha1. - V0alpha1() v0alpha1.Interface -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// V0alpha1 returns a new v0alpha1.Interface. -func (g *group) V0alpha1() v0alpha1.Interface { - return v0alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/interface.go b/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/interface.go deleted file mode 100644 index 641fef4aa7b..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/interface.go +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // Receivers returns a ReceiverInformer. - Receivers() ReceiverInformer - // RoutingTrees returns a RoutingTreeInformer. - RoutingTrees() RoutingTreeInformer - // TemplateGroups returns a TemplateGroupInformer. - TemplateGroups() TemplateGroupInformer - // TimeIntervals returns a TimeIntervalInformer. - TimeIntervals() TimeIntervalInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// Receivers returns a ReceiverInformer. -func (v *version) Receivers() ReceiverInformer { - return &receiverInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// RoutingTrees returns a RoutingTreeInformer. -func (v *version) RoutingTrees() RoutingTreeInformer { - return &routingTreeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// TemplateGroups returns a TemplateGroupInformer. -func (v *version) TemplateGroups() TemplateGroupInformer { - return &templateGroupInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// TimeIntervals returns a TimeIntervalInformer. -func (v *version) TimeIntervals() TimeIntervalInformer { - return &timeIntervalInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/receiver.go b/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/receiver.go deleted file mode 100644 index 194cb68a80d..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/receiver.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - time "time" - - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned" - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" - v0alpha1 "github.com/grafana/grafana/pkg/generated/listers/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// ReceiverInformer provides access to a shared informer and lister for -// Receivers. -type ReceiverInformer interface { - Informer() cache.SharedIndexInformer - Lister() v0alpha1.ReceiverLister -} - -type receiverInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewReceiverInformer constructs a new informer for Receiver type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewReceiverInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredReceiverInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredReceiverInformer constructs a new informer for Receiver type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredReceiverInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().Receivers(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().Receivers(namespace).Watch(context.TODO(), options) - }, - }, - &alertingnotificationsv0alpha1.Receiver{}, - resyncPeriod, - indexers, - ) -} - -func (f *receiverInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredReceiverInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *receiverInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&alertingnotificationsv0alpha1.Receiver{}, f.defaultInformer) -} - -func (f *receiverInformer) Lister() v0alpha1.ReceiverLister { - return v0alpha1.NewReceiverLister(f.Informer().GetIndexer()) -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/routingtree.go b/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/routingtree.go deleted file mode 100644 index 79238d3db65..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/routingtree.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - time "time" - - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned" - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" - v0alpha1 "github.com/grafana/grafana/pkg/generated/listers/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// RoutingTreeInformer provides access to a shared informer and lister for -// RoutingTrees. -type RoutingTreeInformer interface { - Informer() cache.SharedIndexInformer - Lister() v0alpha1.RoutingTreeLister -} - -type routingTreeInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewRoutingTreeInformer constructs a new informer for RoutingTree type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewRoutingTreeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredRoutingTreeInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredRoutingTreeInformer constructs a new informer for RoutingTree type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredRoutingTreeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().RoutingTrees(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().RoutingTrees(namespace).Watch(context.TODO(), options) - }, - }, - &alertingnotificationsv0alpha1.RoutingTree{}, - resyncPeriod, - indexers, - ) -} - -func (f *routingTreeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredRoutingTreeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *routingTreeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&alertingnotificationsv0alpha1.RoutingTree{}, f.defaultInformer) -} - -func (f *routingTreeInformer) Lister() v0alpha1.RoutingTreeLister { - return v0alpha1.NewRoutingTreeLister(f.Informer().GetIndexer()) -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/templategroup.go b/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/templategroup.go deleted file mode 100644 index 2a04ec9ea4e..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/templategroup.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - time "time" - - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned" - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" - v0alpha1 "github.com/grafana/grafana/pkg/generated/listers/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// TemplateGroupInformer provides access to a shared informer and lister for -// TemplateGroups. -type TemplateGroupInformer interface { - Informer() cache.SharedIndexInformer - Lister() v0alpha1.TemplateGroupLister -} - -type templateGroupInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewTemplateGroupInformer constructs a new informer for TemplateGroup type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewTemplateGroupInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredTemplateGroupInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredTemplateGroupInformer constructs a new informer for TemplateGroup type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredTemplateGroupInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().TemplateGroups(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().TemplateGroups(namespace).Watch(context.TODO(), options) - }, - }, - &alertingnotificationsv0alpha1.TemplateGroup{}, - resyncPeriod, - indexers, - ) -} - -func (f *templateGroupInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTemplateGroupInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *templateGroupInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&alertingnotificationsv0alpha1.TemplateGroup{}, f.defaultInformer) -} - -func (f *templateGroupInformer) Lister() v0alpha1.TemplateGroupLister { - return v0alpha1.NewTemplateGroupLister(f.Informer().GetIndexer()) -} diff --git a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/timeinterval.go b/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/timeinterval.go deleted file mode 100644 index 903bb8eb7bc..00000000000 --- a/pkg/generated/informers/externalversions/alerting_notifications/v0alpha1/timeinterval.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by informer-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - "context" - time "time" - - alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned" - internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" - v0alpha1 "github.com/grafana/grafana/pkg/generated/listers/alerting_notifications/v0alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// TimeIntervalInformer provides access to a shared informer and lister for -// TimeIntervals. -type TimeIntervalInformer interface { - Informer() cache.SharedIndexInformer - Lister() v0alpha1.TimeIntervalLister -} - -type timeIntervalInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewTimeIntervalInformer constructs a new informer for TimeInterval type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewTimeIntervalInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredTimeIntervalInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredTimeIntervalInformer constructs a new informer for TimeInterval type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredTimeIntervalInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().TimeIntervals(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.NotificationsV0alpha1().TimeIntervals(namespace).Watch(context.TODO(), options) - }, - }, - &alertingnotificationsv0alpha1.TimeInterval{}, - resyncPeriod, - indexers, - ) -} - -func (f *timeIntervalInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTimeIntervalInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *timeIntervalInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&alertingnotificationsv0alpha1.TimeInterval{}, f.defaultInformer) -} - -func (f *timeIntervalInformer) Lister() v0alpha1.TimeIntervalLister { - return v0alpha1.NewTimeIntervalLister(f.Informer().GetIndexer()) -} diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index cc5cf674386..93a498c5d2a 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -10,7 +10,6 @@ import ( time "time" versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned" - alertingnotifications "github.com/grafana/grafana/pkg/generated/informers/externalversions/alerting_notifications" internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces" service "github.com/grafana/grafana/pkg/generated/informers/externalversions/service" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -241,14 +240,9 @@ type SharedInformerFactory interface { // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer - Notifications() alertingnotifications.Interface Service() service.Interface } -func (f *sharedInformerFactory) Notifications() alertingnotifications.Interface { - return alertingnotifications.New(f, f.namespace, f.tweakListOptions) -} - func (f *sharedInformerFactory) Service() service.Interface { return service.New(f, f.namespace, f.tweakListOptions) } diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index a99bb909577..88cc30aa0f9 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -7,8 +7,7 @@ package externalversions import ( "fmt" - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" + v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -39,18 +38,8 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=notifications.alerting.grafana.app, Version=v0alpha1 - case v0alpha1.SchemeGroupVersion.WithResource("receivers"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().Receivers().Informer()}, nil - case v0alpha1.SchemeGroupVersion.WithResource("routingtrees"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().RoutingTrees().Informer()}, nil - case v0alpha1.SchemeGroupVersion.WithResource("templategroups"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().TemplateGroups().Informer()}, nil - case v0alpha1.SchemeGroupVersion.WithResource("timeintervals"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().TimeIntervals().Informer()}, nil - - // Group=service.grafana.app, Version=v0alpha1 - case servicev0alpha1.SchemeGroupVersion.WithResource("externalnames"): + // Group=service.grafana.app, Version=v0alpha1 + case v0alpha1.SchemeGroupVersion.WithResource("externalnames"): return &genericInformer{resource: resource.GroupResource(), informer: f.Service().V0alpha1().ExternalNames().Informer()}, nil } diff --git a/pkg/generated/listers/alerting_notifications/v0alpha1/expansion_generated.go b/pkg/generated/listers/alerting_notifications/v0alpha1/expansion_generated.go deleted file mode 100644 index 79b5f5c82ba..00000000000 --- a/pkg/generated/listers/alerting_notifications/v0alpha1/expansion_generated.go +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by lister-gen. DO NOT EDIT. - -package v0alpha1 - -// ReceiverListerExpansion allows custom methods to be added to -// ReceiverLister. -type ReceiverListerExpansion interface{} - -// ReceiverNamespaceListerExpansion allows custom methods to be added to -// ReceiverNamespaceLister. -type ReceiverNamespaceListerExpansion interface{} - -// RoutingTreeListerExpansion allows custom methods to be added to -// RoutingTreeLister. -type RoutingTreeListerExpansion interface{} - -// RoutingTreeNamespaceListerExpansion allows custom methods to be added to -// RoutingTreeNamespaceLister. -type RoutingTreeNamespaceListerExpansion interface{} - -// TemplateGroupListerExpansion allows custom methods to be added to -// TemplateGroupLister. -type TemplateGroupListerExpansion interface{} - -// TemplateGroupNamespaceListerExpansion allows custom methods to be added to -// TemplateGroupNamespaceLister. -type TemplateGroupNamespaceListerExpansion interface{} - -// TimeIntervalListerExpansion allows custom methods to be added to -// TimeIntervalLister. -type TimeIntervalListerExpansion interface{} - -// TimeIntervalNamespaceListerExpansion allows custom methods to be added to -// TimeIntervalNamespaceLister. -type TimeIntervalNamespaceListerExpansion interface{} diff --git a/pkg/generated/listers/alerting_notifications/v0alpha1/receiver.go b/pkg/generated/listers/alerting_notifications/v0alpha1/receiver.go deleted file mode 100644 index e07d4f20b03..00000000000 --- a/pkg/generated/listers/alerting_notifications/v0alpha1/receiver.go +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by lister-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" - "k8s.io/client-go/tools/cache" -) - -// ReceiverLister helps list Receivers. -// All objects returned here must be treated as read-only. -type ReceiverLister interface { - // List lists all Receivers in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.Receiver, err error) - // Receivers returns an object that can list and get Receivers. - Receivers(namespace string) ReceiverNamespaceLister - ReceiverListerExpansion -} - -// receiverLister implements the ReceiverLister interface. -type receiverLister struct { - listers.ResourceIndexer[*v0alpha1.Receiver] -} - -// NewReceiverLister returns a new ReceiverLister. -func NewReceiverLister(indexer cache.Indexer) ReceiverLister { - return &receiverLister{listers.New[*v0alpha1.Receiver](indexer, v0alpha1.Resource("receiver"))} -} - -// Receivers returns an object that can list and get Receivers. -func (s *receiverLister) Receivers(namespace string) ReceiverNamespaceLister { - return receiverNamespaceLister{listers.NewNamespaced[*v0alpha1.Receiver](s.ResourceIndexer, namespace)} -} - -// ReceiverNamespaceLister helps list and get Receivers. -// All objects returned here must be treated as read-only. -type ReceiverNamespaceLister interface { - // List lists all Receivers in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.Receiver, err error) - // Get retrieves the Receiver from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v0alpha1.Receiver, error) - ReceiverNamespaceListerExpansion -} - -// receiverNamespaceLister implements the ReceiverNamespaceLister -// interface. -type receiverNamespaceLister struct { - listers.ResourceIndexer[*v0alpha1.Receiver] -} diff --git a/pkg/generated/listers/alerting_notifications/v0alpha1/routingtree.go b/pkg/generated/listers/alerting_notifications/v0alpha1/routingtree.go deleted file mode 100644 index 539c50c24b2..00000000000 --- a/pkg/generated/listers/alerting_notifications/v0alpha1/routingtree.go +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by lister-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" - "k8s.io/client-go/tools/cache" -) - -// RoutingTreeLister helps list RoutingTrees. -// All objects returned here must be treated as read-only. -type RoutingTreeLister interface { - // List lists all RoutingTrees in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.RoutingTree, err error) - // RoutingTrees returns an object that can list and get RoutingTrees. - RoutingTrees(namespace string) RoutingTreeNamespaceLister - RoutingTreeListerExpansion -} - -// routingTreeLister implements the RoutingTreeLister interface. -type routingTreeLister struct { - listers.ResourceIndexer[*v0alpha1.RoutingTree] -} - -// NewRoutingTreeLister returns a new RoutingTreeLister. -func NewRoutingTreeLister(indexer cache.Indexer) RoutingTreeLister { - return &routingTreeLister{listers.New[*v0alpha1.RoutingTree](indexer, v0alpha1.Resource("routingtree"))} -} - -// RoutingTrees returns an object that can list and get RoutingTrees. -func (s *routingTreeLister) RoutingTrees(namespace string) RoutingTreeNamespaceLister { - return routingTreeNamespaceLister{listers.NewNamespaced[*v0alpha1.RoutingTree](s.ResourceIndexer, namespace)} -} - -// RoutingTreeNamespaceLister helps list and get RoutingTrees. -// All objects returned here must be treated as read-only. -type RoutingTreeNamespaceLister interface { - // List lists all RoutingTrees in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.RoutingTree, err error) - // Get retrieves the RoutingTree from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v0alpha1.RoutingTree, error) - RoutingTreeNamespaceListerExpansion -} - -// routingTreeNamespaceLister implements the RoutingTreeNamespaceLister -// interface. -type routingTreeNamespaceLister struct { - listers.ResourceIndexer[*v0alpha1.RoutingTree] -} diff --git a/pkg/generated/listers/alerting_notifications/v0alpha1/templategroup.go b/pkg/generated/listers/alerting_notifications/v0alpha1/templategroup.go deleted file mode 100644 index 67d7df50f96..00000000000 --- a/pkg/generated/listers/alerting_notifications/v0alpha1/templategroup.go +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by lister-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" - "k8s.io/client-go/tools/cache" -) - -// TemplateGroupLister helps list TemplateGroups. -// All objects returned here must be treated as read-only. -type TemplateGroupLister interface { - // List lists all TemplateGroups in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.TemplateGroup, err error) - // TemplateGroups returns an object that can list and get TemplateGroups. - TemplateGroups(namespace string) TemplateGroupNamespaceLister - TemplateGroupListerExpansion -} - -// templateGroupLister implements the TemplateGroupLister interface. -type templateGroupLister struct { - listers.ResourceIndexer[*v0alpha1.TemplateGroup] -} - -// NewTemplateGroupLister returns a new TemplateGroupLister. -func NewTemplateGroupLister(indexer cache.Indexer) TemplateGroupLister { - return &templateGroupLister{listers.New[*v0alpha1.TemplateGroup](indexer, v0alpha1.Resource("templategroup"))} -} - -// TemplateGroups returns an object that can list and get TemplateGroups. -func (s *templateGroupLister) TemplateGroups(namespace string) TemplateGroupNamespaceLister { - return templateGroupNamespaceLister{listers.NewNamespaced[*v0alpha1.TemplateGroup](s.ResourceIndexer, namespace)} -} - -// TemplateGroupNamespaceLister helps list and get TemplateGroups. -// All objects returned here must be treated as read-only. -type TemplateGroupNamespaceLister interface { - // List lists all TemplateGroups in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.TemplateGroup, err error) - // Get retrieves the TemplateGroup from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v0alpha1.TemplateGroup, error) - TemplateGroupNamespaceListerExpansion -} - -// templateGroupNamespaceLister implements the TemplateGroupNamespaceLister -// interface. -type templateGroupNamespaceLister struct { - listers.ResourceIndexer[*v0alpha1.TemplateGroup] -} diff --git a/pkg/generated/listers/alerting_notifications/v0alpha1/timeinterval.go b/pkg/generated/listers/alerting_notifications/v0alpha1/timeinterval.go deleted file mode 100644 index c3a33df619a..00000000000 --- a/pkg/generated/listers/alerting_notifications/v0alpha1/timeinterval.go +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by lister-gen. DO NOT EDIT. - -package v0alpha1 - -import ( - v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" - "k8s.io/client-go/tools/cache" -) - -// TimeIntervalLister helps list TimeIntervals. -// All objects returned here must be treated as read-only. -type TimeIntervalLister interface { - // List lists all TimeIntervals in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.TimeInterval, err error) - // TimeIntervals returns an object that can list and get TimeIntervals. - TimeIntervals(namespace string) TimeIntervalNamespaceLister - TimeIntervalListerExpansion -} - -// timeIntervalLister implements the TimeIntervalLister interface. -type timeIntervalLister struct { - listers.ResourceIndexer[*v0alpha1.TimeInterval] -} - -// NewTimeIntervalLister returns a new TimeIntervalLister. -func NewTimeIntervalLister(indexer cache.Indexer) TimeIntervalLister { - return &timeIntervalLister{listers.New[*v0alpha1.TimeInterval](indexer, v0alpha1.Resource("timeinterval"))} -} - -// TimeIntervals returns an object that can list and get TimeIntervals. -func (s *timeIntervalLister) TimeIntervals(namespace string) TimeIntervalNamespaceLister { - return timeIntervalNamespaceLister{listers.NewNamespaced[*v0alpha1.TimeInterval](s.ResourceIndexer, namespace)} -} - -// TimeIntervalNamespaceLister helps list and get TimeIntervals. -// All objects returned here must be treated as read-only. -type TimeIntervalNamespaceLister interface { - // List lists all TimeIntervals in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v0alpha1.TimeInterval, err error) - // Get retrieves the TimeInterval from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v0alpha1.TimeInterval, error) - TimeIntervalNamespaceListerExpansion -} - -// timeIntervalNamespaceLister implements the TimeIntervalNamespaceLister -// interface. -type timeIntervalNamespaceLister struct { - listers.ResourceIndexer[*v0alpha1.TimeInterval] -} diff --git a/pkg/registry/apis/alerting/notifications/receiver/authorize.go b/pkg/registry/apis/alerting/notifications/receiver/authorize.go index ce357351364..c1ddc7b070f 100644 --- a/pkg/registry/apis/alerting/notifications/receiver/authorize.go +++ b/pkg/registry/apis/alerting/notifications/receiver/authorize.go @@ -22,7 +22,7 @@ type AccessControlService interface { } func Authorize(ctx context.Context, ac AccessControlService, attr authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) { - if attr.GetResource() != resourceInfo.GroupResource().Resource { + if attr.GetResource() != ResourceInfo.GroupResource().Resource { return authorizer.DecisionNoOpinion, "", nil } user, err := identity.GetRequester(ctx) diff --git a/pkg/registry/apis/alerting/notifications/receiver/conversions.go b/pkg/registry/apis/alerting/notifications/receiver/conversions.go index 44ce1bb5d40..6ba2b6b5975 100644 --- a/pkg/registry/apis/alerting/notifications/receiver/conversions.go +++ b/pkg/registry/apis/alerting/notifications/receiver/conversions.go @@ -8,9 +8,9 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" - common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" + gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" ) @@ -42,7 +42,7 @@ func convertToK8sResources( if err != nil { return nil, err } - if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableReceiverFields(k8sResource)) { + if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableFields(k8sResource)) { continue } result.Items = append(result.Items, *k8sResource) @@ -57,7 +57,7 @@ func convertToK8sResource( metadata *ngmodels.ReceiverMetadata, namespacer request.NamespaceMapper, ) (*model.Receiver, error) { - spec := model.ReceiverSpec{ + spec := model.Spec{ Title: receiver.Name, } for _, integration := range receiver.Integrations { @@ -65,13 +65,12 @@ func convertToK8sResource( Uid: &integration.UID, Type: integration.Config.Type, DisableResolveMessage: &integration.DisableResolveMessage, - Settings: common.Unstructured{Object: maps.Clone(integration.Settings)}, + Settings: maps.Clone(integration.Settings), SecureFields: integration.SecureFields(), }) } r := &model.Receiver{ - TypeMeta: resourceInfo.TypeMeta(), ObjectMeta: metav1.ObjectMeta{ UID: types.UID(receiver.GetUID()), // This is needed to make PATCH work Name: receiver.GetUID(), @@ -101,7 +100,7 @@ func convertToK8sResource( } r.SetInUse(metadata.InUseByRoutes, rules) } - + r.UID = gapiutil.CalculateClusterWideUID(r) return r, nil } @@ -130,7 +129,7 @@ func convertToDomainModel(receiver *model.Receiver) (*ngmodels.Receiver, map[str grafanaIntegration := ngmodels.Integration{ Name: receiver.Spec.Title, Config: config, - Settings: maps.Clone(integration.Settings.UnstructuredContent()), + Settings: maps.Clone(integration.Settings), SecureSettings: make(map[string]string), } if integration.Uid != nil { diff --git a/pkg/registry/apis/alerting/notifications/receiver/legacy_storage.go b/pkg/registry/apis/alerting/notifications/receiver/legacy_storage.go index 79a97b640c9..6b1377dc1f3 100644 --- a/pkg/registry/apis/alerting/notifications/receiver/legacy_storage.go +++ b/pkg/registry/apis/alerting/notifications/receiver/legacy_storage.go @@ -11,8 +11,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1" "github.com/grafana/grafana/pkg/apimachinery/identity" - notifications "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" grafanaRest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" alertingac "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" @@ -25,8 +25,6 @@ var ( _ grafanaRest.LegacyStorage = (*legacyStorage)(nil) ) -var resourceInfo = notifications.ReceiverResourceInfo - type ReceiverService interface { GetReceiver(ctx context.Context, q ngmodels.GetReceiverQuery, user identity.Requester) (*ngmodels.Receiver, error) GetReceivers(ctx context.Context, q ngmodels.GetReceiversQuery, user identity.Requester) ([]*ngmodels.Receiver, error) @@ -48,7 +46,7 @@ type legacyStorage struct { } func (s *legacyStorage) New() runtime.Object { - return resourceInfo.NewFunc() + return ResourceInfo.NewFunc() } func (s *legacyStorage) Destroy() {} @@ -58,11 +56,11 @@ func (s *legacyStorage) NamespaceScoped() bool { } func (s *legacyStorage) GetSingularName() string { - return resourceInfo.GetSingularName() + return ResourceInfo.GetSingularName() } func (s *legacyStorage) NewList() runtime.Object { - return resourceInfo.NewListFunc() + return ResourceInfo.NewListFunc() } func (s *legacyStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { @@ -121,7 +119,7 @@ func (s *legacyStorage) Get(ctx context.Context, uid string, _ *metav1.GetOption name, err := legacy_storage.UidToName(uid) if err != nil { - return nil, apierrors.NewNotFound(resourceInfo.GroupResource(), uid) + return nil, apierrors.NewNotFound(ResourceInfo.GroupResource(), uid) } q := ngmodels.GetReceiverQuery{ OrgID: info.OrgID, @@ -176,7 +174,7 @@ func (s *legacyStorage) Create(ctx context.Context, return nil, err } } - p, ok := obj.(*notifications.Receiver) + p, ok := obj.(*model.Receiver) if !ok { return nil, fmt.Errorf("expected receiver but got %s", obj.GetObjectKind().GroupVersionKind()) } @@ -231,7 +229,7 @@ func (s *legacyStorage) Update(ctx context.Context, return nil, false, err } } - p, ok := obj.(*notifications.Receiver) + p, ok := obj.(*model.Receiver) if !ok { return nil, false, fmt.Errorf("expected receiver but got %s", obj.GetObjectKind().GroupVersionKind()) } @@ -280,5 +278,5 @@ func (s *legacyStorage) Delete(ctx context.Context, uid string, deleteValidation } func (s *legacyStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) { - return nil, apierrors.NewMethodNotSupported(resourceInfo.GroupResource(), "deleteCollection") + return nil, apierrors.NewMethodNotSupported(ResourceInfo.GroupResource(), "deleteCollection") } diff --git a/pkg/registry/apis/alerting/notifications/receiver/storage.go b/pkg/registry/apis/alerting/notifications/receiver/storage.go index 36b8932604a..1d691fe30e3 100644 --- a/pkg/registry/apis/alerting/notifications/receiver/storage.go +++ b/pkg/registry/apis/alerting/notifications/receiver/storage.go @@ -1,69 +1,31 @@ package receiver import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apiserver/pkg/registry/generic" - genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" - apistore "k8s.io/apiserver/pkg/storage" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic" - grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" + "github.com/grafana/grafana/pkg/services/apiserver/builder" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" ) -var _ grafanarest.Storage = (*storage)(nil) - -type storage struct { - *genericregistry.Store -} - -func (s storage) Compare(storageObj, legacyObj runtime.Object) bool { - // TODO implement when supported dual write mode is not Mode0 - return false -} - func NewStorage( legacySvc ReceiverService, namespacer request.NamespaceMapper, - scheme *runtime.Scheme, - optsGetter generic.RESTOptionsGetter, - dualWriteBuilder grafanarest.DualWriteBuilder, + opts builder.APIGroupOptions, metadata MetadataService, ) (rest.Storage, error) { legacyStore := &legacyStorage{ service: legacySvc, namespacer: namespacer, - tableConverter: resourceInfo.TableConverter(), + tableConverter: ResourceInfo.TableConverter(), metadata: metadata, } - if optsGetter != nil && dualWriteBuilder != nil { - store, err := grafanaregistry.NewRegistryStore(scheme, resourceInfo, optsGetter) + if opts.OptsGetter != nil && opts.DualWriteBuilder != nil { + store, err := grafanaregistry.NewRegistryStore(opts.Scheme, ResourceInfo, opts.OptsGetter) if err != nil { return nil, err } - return dualWriteBuilder(resourceInfo.GroupResource(), legacyStore, store) + return opts.DualWriteBuilder(ResourceInfo.GroupResource(), legacyStore, store) } return legacyStore, nil } - -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { - if s, ok := obj.(*model.Receiver); ok { - return s.Labels, model.SelectableReceiverFields(s), nil - } - return nil, nil, fmt.Errorf("object of type %T is not supported", obj) -} - -// Matcher returns a generic.SelectionPredicate that matches on label and field selectors. -func Matcher(label labels.Selector, field fields.Selector) apistore.SelectionPredicate { - return apistore.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} diff --git a/pkg/registry/apis/alerting/notifications/receiver/type.go b/pkg/registry/apis/alerting/notifications/receiver/type.go new file mode 100644 index 00000000000..fcf4311c16e --- /dev/null +++ b/pkg/registry/apis/alerting/notifications/receiver/type.go @@ -0,0 +1,62 @@ +package receiver + +import ( + "fmt" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/utils" +) + +var kind = model.Kind() +var GetOpenAPIDefinitions = model.GetOpenAPIDefinitions +var ResourceInfo = utils.NewResourceInfo(kind.Group(), kind.Version(), + kind.GroupVersionResource().Resource, strings.ToLower(kind.Kind()), kind.Kind(), + func() runtime.Object { return kind.ZeroValue() }, + func() runtime.Object { return kind.ZeroListValue() }, + utils.TableColumns{ + Definition: []metav1.TableColumnDefinition{ + {Name: "Name", Type: "string", Format: "name"}, + {Name: "Title", Type: "string", Format: "string", Description: "The receiver name"}, // TODO: Add integration types. + }, + Reader: func(obj any) ([]interface{}, error) { + r, ok := obj.(*model.Receiver) + if ok { + return []interface{}{ + r.Name, + r.Spec.Title, + // r.Spec, //TODO implement formatting for Spec, same as UI? + }, nil + } + return nil, fmt.Errorf("expected resource or info") + }, + }, +) + +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(ResourceInfo.GroupVersion(), + &model.Receiver{}, + &model.ReceiverList{}, + ) + metav1.AddToGroupVersion(scheme, ResourceInfo.GroupVersion()) + + err := scheme.AddFieldLabelConversionFunc( + ResourceInfo.GroupVersionKind(), + func(label, value string) (string, string, error) { + fieldSet := model.SelectableFields(&model.Receiver{}) + for key := range fieldSet { + if label == key { + return label, value, nil + } + } + return "", "", fmt.Errorf("field label not supported for %s: %s", ResourceInfo.GroupVersionKind(), label) + }, + ) + if err != nil { + return err + } + return nil +} diff --git a/pkg/registry/apis/alerting/notifications/register.go b/pkg/registry/apis/alerting/notifications/register.go index 0fd8c19da4d..d5a7780e978 100644 --- a/pkg/registry/apis/alerting/notifications/register.go +++ b/pkg/registry/apis/alerting/notifications/register.go @@ -3,6 +3,7 @@ package notifications import ( "context" "fmt" + "maps" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -12,11 +13,11 @@ import ( "k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/spec3" - notificationsModels "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - receiver "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/receiver" - "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/routing_tree" - "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/template_group" - timeInterval "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/timeinterval" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource" + "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/receiver" + "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/routingtree" + "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/templategroup" + "github.com/grafana/grafana/pkg/registry/apis/alerting/notifications/timeinterval" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/apiserver/builder" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" @@ -35,7 +36,6 @@ type NotificationsAPIBuilder struct { receiverAuth receiver.AccessControlService ng *ngalert.AlertNG namespacer request.NamespaceMapper - gv schema.GroupVersion } func RegisterAPIService( @@ -50,7 +50,6 @@ func RegisterAPIService( builder := &NotificationsAPIBuilder{ ng: ng, namespacer: request.GetNamespaceMapper(cfg), - gv: notificationsModels.SchemeGroupVersion, authz: ng.Api.AccessControl, receiverAuth: ac.NewReceiverAccess[*ngmodels.Receiver](ng.Api.AccessControl, false), } @@ -59,53 +58,75 @@ func RegisterAPIService( } func (t *NotificationsAPIBuilder) GetGroupVersion() schema.GroupVersion { - return t.gv + return resource.GroupVersion } func (t *NotificationsAPIBuilder) InstallSchema(scheme *runtime.Scheme) error { - err := notificationsModels.AddToScheme(scheme) - if err != nil { + if err := receiver.AddKnownTypes(scheme); err != nil { return err } - return scheme.SetVersionPriority(notificationsModels.SchemeGroupVersion) -} - -func (t *NotificationsAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver.APIGroupInfo, opts builder.APIGroupOptions) error { - scheme := opts.Scheme - optsGetter := opts.OptsGetter - dualWriteBuilder := opts.DualWriteBuilder - - intervals, err := timeInterval.NewStorage(t.ng.Api.MuteTimings, t.namespacer, scheme, optsGetter, dualWriteBuilder) - if err != nil { - return fmt.Errorf("failed to initialize time-interval storage: %w", err) + if err := routingtree.AddKnownTypes(scheme); err != nil { + return err } - - recvStorage, err := receiver.NewStorage(t.ng.Api.ReceiverService, t.namespacer, scheme, optsGetter, dualWriteBuilder, t.ng.Api.ReceiverService) - if err != nil { - return fmt.Errorf("failed to initialize receiver storage: %w", err) + if err := templategroup.AddKnownTypes(scheme); err != nil { + return err } - - templ, err := template_group.NewStorage(t.ng.Api.Templates, t.namespacer, scheme, optsGetter, dualWriteBuilder) - if err != nil { - return fmt.Errorf("failed to initialize templates group storage: %w", err) - } - - routeStorage, err := routing_tree.NewStorage(t.ng.Api.Policies, t.namespacer) - if err != nil { - return fmt.Errorf("failed to initialize route storage: %w", err) - } - - apiGroupInfo.VersionedResourcesStorageMap[notificationsModels.VERSION] = map[string]rest.Storage{ - notificationsModels.TimeIntervalResourceInfo.StoragePath(): intervals, - notificationsModels.ReceiverResourceInfo.StoragePath(): recvStorage, - notificationsModels.TemplateGroupResourceInfo.StoragePath(): templ, - notificationsModels.RouteResourceInfo.StoragePath(): routeStorage, + if err := timeinterval.AddKnownTypes(scheme); err != nil { + return err } return nil } +func (t *NotificationsAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver.APIGroupInfo, opts builder.APIGroupOptions) error { + addStorage := func(gvr schema.GroupVersionResource, s rest.Storage) { + v, ok := apiGroupInfo.VersionedResourcesStorageMap[gvr.Version] + if !ok { + v = map[string]rest.Storage{} + apiGroupInfo.VersionedResourcesStorageMap[gvr.Version] = v + } + v[gvr.Resource] = s + } + + intervals, err := timeinterval.NewStorage(t.ng.Api.MuteTimings, t.namespacer, opts) + if err != nil { + return fmt.Errorf("failed to initialize time-interval storage: %w", err) + } + addStorage(timeinterval.ResourceInfo.GroupVersionResource(), intervals) + + recvStorage, err := receiver.NewStorage(t.ng.Api.ReceiverService, t.namespacer, opts, t.ng.Api.ReceiverService) + if err != nil { + return fmt.Errorf("failed to initialize receiver storage: %w", err) + } + addStorage(receiver.ResourceInfo.GroupVersionResource(), recvStorage) + + templ, err := templategroup.NewStorage(t.ng.Api.Templates, t.namespacer, opts) + if err != nil { + return fmt.Errorf("failed to initialize templates group storage: %w", err) + } + addStorage(templategroup.ResourceInfo.GroupVersionResource(), templ) + + routeStorage, err := routingtree.NewStorage(t.ng.Api.Policies, t.namespacer) + if err != nil { + return fmt.Errorf("failed to initialize route storage: %w", err) + } + addStorage(routingtree.ResourceInfo.GroupVersionResource(), routeStorage) + + return nil +} + func (t *NotificationsAPIBuilder) GetOpenAPIDefinitions() common.GetOpenAPIDefinitions { - return notificationsModels.GetOpenAPIDefinitions + return func(c common.ReferenceCallback) map[string]common.OpenAPIDefinition { + tmpl := templategroup.GetOpenAPIDefinitions(c) + tin := timeinterval.GetOpenAPIDefinitions(c) + recv := receiver.GetOpenAPIDefinitions(c) + rest := routingtree.GetOpenAPIDefinitions(c) + result := make(map[string]common.OpenAPIDefinition, len(tmpl)+len(tin)+len(recv)+len(rest)) + maps.Copy(result, tmpl) + maps.Copy(result, tin) + maps.Copy(result, recv) + maps.Copy(result, rest) + return result + } } // PostProcessOpenAPI is a hook to alter OpenAPI3 specification of the API server. @@ -117,10 +138,10 @@ func (t *NotificationsAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3 root := "/apis/" + t.GetGroupVersion().String() + "/" // Hide the ability to list or watch across all tenants - delete(oas.Paths.Paths, root+notificationsModels.ReceiverResourceInfo.GroupResource().Resource) - delete(oas.Paths.Paths, root+notificationsModels.TimeIntervalResourceInfo.GroupResource().Resource) - delete(oas.Paths.Paths, root+notificationsModels.TemplateGroupResourceInfo.GroupResource().Resource) - delete(oas.Paths.Paths, root+notificationsModels.RouteResourceInfo.GroupResource().Resource) + delete(oas.Paths.Paths, root+receiver.ResourceInfo.GroupResource().Resource) + delete(oas.Paths.Paths, root+timeinterval.ResourceInfo.GroupResource().Resource) + delete(oas.Paths.Paths, root+templategroup.ResourceInfo.GroupResource().Resource) + delete(oas.Paths.Paths, root+routingtree.ResourceInfo.GroupResource().Resource) // The root API discovery list sub := oas.Paths.Paths[root] @@ -134,14 +155,14 @@ func (t *NotificationsAPIBuilder) GetAuthorizer() authorizer.Authorizer { return authorizer.AuthorizerFunc( func(ctx context.Context, a authorizer.Attributes) (authorizer.Decision, string, error) { switch a.GetResource() { - case notificationsModels.TemplateGroupResourceInfo.GroupResource().Resource: - return template_group.Authorize(ctx, t.authz, a) - case notificationsModels.TimeIntervalResourceInfo.GroupResource().Resource: - return timeInterval.Authorize(ctx, t.authz, a) - case notificationsModels.ReceiverResourceInfo.GroupResource().Resource: + case templategroup.ResourceInfo.GroupResource().Resource: + return templategroup.Authorize(ctx, t.authz, a) + case timeinterval.ResourceInfo.GroupResource().Resource: + return timeinterval.Authorize(ctx, t.authz, a) + case receiver.ResourceInfo.GroupResource().Resource: return receiver.Authorize(ctx, t.receiverAuth, a) - case notificationsModels.RouteResourceInfo.GroupResource().Resource: - return routing_tree.Authorize(ctx, t.authz, a) + case routingtree.ResourceInfo.GroupResource().Resource: + return routingtree.Authorize(ctx, t.authz, a) } return authorizer.DecisionNoOpinion, "", nil }) diff --git a/pkg/registry/apis/alerting/notifications/routing_tree/authorize.go b/pkg/registry/apis/alerting/notifications/routingtree/authorize.go similarity index 93% rename from pkg/registry/apis/alerting/notifications/routing_tree/authorize.go rename to pkg/registry/apis/alerting/notifications/routingtree/authorize.go index 5394d728e91..e669f841189 100644 --- a/pkg/registry/apis/alerting/notifications/routing_tree/authorize.go +++ b/pkg/registry/apis/alerting/notifications/routingtree/authorize.go @@ -1,4 +1,4 @@ -package routing_tree +package routingtree import ( "context" @@ -10,7 +10,7 @@ import ( ) func Authorize(ctx context.Context, ac accesscontrol.AccessControl, attr authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) { - if attr.GetResource() != resourceInfo.GroupResource().Resource { + if attr.GetResource() != ResourceInfo.GroupResource().Resource { return authorizer.DecisionNoOpinion, "", nil } user, err := identity.GetRequester(ctx) diff --git a/pkg/registry/apis/alerting/notifications/routing_tree/conversions.go b/pkg/registry/apis/alerting/notifications/routingtree/conversions.go similarity index 95% rename from pkg/registry/apis/alerting/notifications/routing_tree/conversions.go rename to pkg/registry/apis/alerting/notifications/routingtree/conversions.go index 70bea2dba7a..7d7d16de825 100644 --- a/pkg/registry/apis/alerting/notifications/routing_tree/conversions.go +++ b/pkg/registry/apis/alerting/notifications/routingtree/conversions.go @@ -1,4 +1,4 @@ -package routing_tree +package routingtree import ( "errors" @@ -12,14 +12,15 @@ import ( promModel "github.com/prometheus/common/model" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" + gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/util" ) func convertToK8sResource(orgID int64, r definitions.Route, version string, namespacer request.NamespaceMapper) (*model.RoutingTree, error) { - spec := model.RoutingTreeSpec{ + spec := model.Spec{ Defaults: model.RouteDefaults{ GroupBy: r.GroupByStr, GroupWait: optionalPrometheusDurationToString(r.GroupWait), @@ -36,10 +37,6 @@ func convertToK8sResource(orgID int64, r definitions.Route, version string, name } var result = &model.RoutingTree{ - TypeMeta: metav1.TypeMeta{ - Kind: model.RouteResourceInfo.GroupVersionKind().Kind, - APIVersion: model.APIVERSION, - }, ObjectMeta: metav1.ObjectMeta{ Name: model.UserDefinedRoutingTreeName, Namespace: namespacer(orgID), @@ -48,6 +45,7 @@ func convertToK8sResource(orgID int64, r definitions.Route, version string, name Spec: spec, } result.SetProvenanceStatus(string(r.Provenance)) + result.UID = gapiutil.CalculateClusterWideUID(result) return result, nil } @@ -83,7 +81,7 @@ func convertRouteToK8sSubRoute(r *definitions.Route) model.Route { for _, key := range keys { m := model.Matcher{ Label: key, - Type: model.MatcherTypeEqualRegex, + Type: model.MatcherTypeEqualTilde, } value, _ := r.MatchRE[key].MarshalYAML() if s, ok := value.(string); ok { diff --git a/pkg/registry/apis/alerting/notifications/routing_tree/legacy_storage.go b/pkg/registry/apis/alerting/notifications/routingtree/legacy_storage.go similarity index 79% rename from pkg/registry/apis/alerting/notifications/routing_tree/legacy_storage.go rename to pkg/registry/apis/alerting/notifications/routingtree/legacy_storage.go index d2b80ba2ffe..00c20880212 100644 --- a/pkg/registry/apis/alerting/notifications/routing_tree/legacy_storage.go +++ b/pkg/registry/apis/alerting/notifications/routingtree/legacy_storage.go @@ -1,4 +1,4 @@ -package routing_tree +package routingtree import ( "context" @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" - notifications "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1" grafanaRest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" @@ -21,8 +21,6 @@ var ( _ grafanaRest.LegacyStorage = (*legacyStorage)(nil) ) -var resourceInfo = notifications.RouteResourceInfo - type RouteService interface { GetPolicyTree(ctx context.Context, orgID int64) (definitions.Route, string, error) UpdatePolicyTree(ctx context.Context, orgID int64, tree definitions.Route, p alerting_models.Provenance, version string) (definitions.Route, string, error) @@ -36,7 +34,7 @@ type legacyStorage struct { } func (s *legacyStorage) New() runtime.Object { - return resourceInfo.NewFunc() + return ResourceInfo.NewFunc() } func (s *legacyStorage) Destroy() {} @@ -46,18 +44,18 @@ func (s *legacyStorage) NamespaceScoped() bool { } func (s *legacyStorage) GetSingularName() string { - return resourceInfo.GetSingularName() + return ResourceInfo.GetSingularName() } func (s *legacyStorage) NewList() runtime.Object { - return resourceInfo.NewListFunc() + return ResourceInfo.NewListFunc() } func (s *legacyStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { return s.tableConverter.ConvertToTable(ctx, object, tableOptions) } -func (s *legacyStorage) getUserDefinedRoutingTree(ctx context.Context) (*notifications.RoutingTree, error) { +func (s *legacyStorage) getUserDefinedRoutingTree(ctx context.Context) (*model.RoutingTree, error) { orgId, err := request.OrgIDForList(ctx) if err != nil { return nil, err @@ -75,16 +73,16 @@ func (s *legacyStorage) List(ctx context.Context, _ *internalversion.ListOptions if err != nil { return nil, err } - return ¬ifications.RoutingTreeList{ - Items: []notifications.RoutingTree{ + return &model.RoutingTreeList{ + Items: []model.RoutingTree{ *user, }, }, nil } func (s *legacyStorage) Get(ctx context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error) { - if name != notifications.UserDefinedRoutingTreeName { - return nil, errors.NewNotFound(resourceInfo.GroupResource(), name) + if name != model.UserDefinedRoutingTreeName { + return nil, errors.NewNotFound(ResourceInfo.GroupResource(), name) } return s.getUserDefinedRoutingTree(ctx) } @@ -94,19 +92,19 @@ func (s *legacyStorage) Create(_ context.Context, _ rest.ValidateObjectFunc, _ *metav1.CreateOptions, ) (runtime.Object, error) { - return nil, errors.NewMethodNotSupported(resourceInfo.GroupResource(), "create") + return nil, errors.NewMethodNotSupported(ResourceInfo.GroupResource(), "create") } func (s *legacyStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, _ rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, _ bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { - if name != notifications.UserDefinedRoutingTreeName { - return nil, false, errors.NewNotFound(resourceInfo.GroupResource(), name) + if name != model.UserDefinedRoutingTreeName { + return nil, false, errors.NewNotFound(ResourceInfo.GroupResource(), name) } info, err := request.NamespaceInfoFrom(ctx, true) if err != nil { return nil, false, err } - old, err := s.Get(ctx, notifications.UserDefinedRoutingTreeName, nil) + old, err := s.Get(ctx, model.UserDefinedRoutingTreeName, nil) if err != nil { return old, false, err } @@ -119,9 +117,9 @@ func (s *legacyStorage) Update(ctx context.Context, name string, objInfo rest.Up return nil, false, err } } - p, ok := obj.(*notifications.RoutingTree) + p, ok := obj.(*model.RoutingTree) if !ok { - return nil, false, fmt.Errorf("expected %s but got %s", notifications.ReceiverResourceInfo.GroupVersionKind(), obj.GetObjectKind().GroupVersionKind()) + return nil, false, fmt.Errorf("expected %s but got %s", ResourceInfo.GroupVersionKind(), obj.GetObjectKind().GroupVersionKind()) } model, version, err := convertToDomainModel(p) @@ -139,8 +137,8 @@ func (s *legacyStorage) Update(ctx context.Context, name string, objInfo rest.Up // Delete implements rest.GracefulDeleter. It is needed for API server to not crash when it registers DeleteCollection method func (s *legacyStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, opts *metav1.DeleteOptions) (runtime.Object, bool, error) { - if name != notifications.UserDefinedRoutingTreeName { - return nil, false, errors.NewNotFound(resourceInfo.GroupResource(), name) + if name != model.UserDefinedRoutingTreeName { + return nil, false, errors.NewNotFound(ResourceInfo.GroupResource(), name) } info, err := request.NamespaceInfoFrom(ctx, true) if err != nil { @@ -162,5 +160,5 @@ func (s *legacyStorage) Delete(ctx context.Context, name string, deleteValidatio } func (s *legacyStorage) DeleteCollection(_ context.Context, _ rest.ValidateObjectFunc, _ *metav1.DeleteOptions, _ *internalversion.ListOptions) (runtime.Object, error) { - return nil, errors.NewMethodNotSupported(resourceInfo.GroupResource(), "delete") + return nil, errors.NewMethodNotSupported(ResourceInfo.GroupResource(), "delete") } diff --git a/pkg/registry/apis/alerting/notifications/routing_tree/storage.go b/pkg/registry/apis/alerting/notifications/routingtree/storage.go similarity index 84% rename from pkg/registry/apis/alerting/notifications/routing_tree/storage.go rename to pkg/registry/apis/alerting/notifications/routingtree/storage.go index b637a2e691d..ecce2112284 100644 --- a/pkg/registry/apis/alerting/notifications/routing_tree/storage.go +++ b/pkg/registry/apis/alerting/notifications/routingtree/storage.go @@ -1,4 +1,4 @@ -package routing_tree +package routingtree import ( "k8s.io/apiserver/pkg/registry/rest" @@ -10,7 +10,7 @@ func NewStorage(legacySvc RouteService, namespacer request.NamespaceMapper) (res legacyStore := &legacyStorage{ service: legacySvc, namespacer: namespacer, - tableConverter: rest.NewDefaultTableConvertor(resourceInfo.GroupResource()), + tableConverter: rest.NewDefaultTableConvertor(ResourceInfo.GroupResource()), } // TODO implement dual write for routes. This API is a special beast - the resource is singleton. return legacyStore, nil diff --git a/pkg/registry/apis/alerting/notifications/routingtree/type.go b/pkg/registry/apis/alerting/notifications/routingtree/type.go new file mode 100644 index 00000000000..698ea33a2eb --- /dev/null +++ b/pkg/registry/apis/alerting/notifications/routingtree/type.go @@ -0,0 +1,29 @@ +package routingtree + +import ( + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/utils" +) + +var kind = model.Kind() +var GetOpenAPIDefinitions = model.GetOpenAPIDefinitions +var ResourceInfo = utils.NewResourceInfo(kind.Group(), kind.Version(), + kind.GroupVersionResource().Resource, strings.ToLower(kind.Kind()), kind.Kind(), + func() runtime.Object { return kind.ZeroValue() }, + func() runtime.Object { return kind.ZeroListValue() }, + utils.TableColumns{}, +) + +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(ResourceInfo.GroupVersion(), + &model.RoutingTree{}, + &model.RoutingTreeList{}, + ) + metav1.AddToGroupVersion(scheme, ResourceInfo.GroupVersion()) + return nil +} diff --git a/pkg/registry/apis/alerting/notifications/template_group/storage.go b/pkg/registry/apis/alerting/notifications/template_group/storage.go deleted file mode 100644 index 49c14ea2863..00000000000 --- a/pkg/registry/apis/alerting/notifications/template_group/storage.go +++ /dev/null @@ -1,67 +0,0 @@ -package template_group - -import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apiserver/pkg/registry/generic" - genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" - "k8s.io/apiserver/pkg/registry/rest" - apistore "k8s.io/apiserver/pkg/storage" - - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" - grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic" - grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" - "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" -) - -var _ grafanarest.Storage = (*storage)(nil) - -type storage struct { - *genericregistry.Store -} - -func (s storage) Compare(storageObj, legacyObj runtime.Object) bool { - // TODO implement when supported dual write mode is not Mode0 - return false -} - -func NewStorage( - legacySvc TemplateService, - namespacer request.NamespaceMapper, - scheme *runtime.Scheme, - optsGetter generic.RESTOptionsGetter, - dualWriteBuilder grafanarest.DualWriteBuilder, -) (rest.Storage, error) { - legacyStore := &legacyStorage{ - service: legacySvc, - namespacer: namespacer, - tableConverter: resourceInfo.TableConverter(), - } - if optsGetter != nil && dualWriteBuilder != nil { - store, err := grafanaregistry.NewRegistryStore(scheme, resourceInfo, optsGetter) - if err != nil { - return nil, err - } - return dualWriteBuilder(resourceInfo.GroupResource(), legacyStore, store) - } - return legacyStore, nil -} - -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { - if s, ok := obj.(*model.TemplateGroup); ok { - return s.Labels, model.SelectableTemplateGroupFields(s), nil - } - return nil, nil, fmt.Errorf("object of type %T is not supported", obj) -} - -// Matcher returns a generic.SelectionPredicate that matches on label and field selectors. -func Matcher(label labels.Selector, field fields.Selector) apistore.SelectionPredicate { - return apistore.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} diff --git a/pkg/registry/apis/alerting/notifications/template_group/authorize.go b/pkg/registry/apis/alerting/notifications/templategroup/authorize.go similarity index 94% rename from pkg/registry/apis/alerting/notifications/template_group/authorize.go rename to pkg/registry/apis/alerting/notifications/templategroup/authorize.go index b9a3f92224a..18d397721fb 100644 --- a/pkg/registry/apis/alerting/notifications/template_group/authorize.go +++ b/pkg/registry/apis/alerting/notifications/templategroup/authorize.go @@ -1,4 +1,4 @@ -package template_group +package templategroup import ( "context" @@ -10,7 +10,7 @@ import ( ) func Authorize(ctx context.Context, ac accesscontrol.AccessControl, attr authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) { - if attr.GetResource() != resourceInfo.GroupResource().Resource { + if attr.GetResource() != ResourceInfo.GroupResource().Resource { return authorizer.DecisionNoOpinion, "", nil } user, err := identity.GetRequester(ctx) diff --git a/pkg/registry/apis/alerting/notifications/template_group/conversions.go b/pkg/registry/apis/alerting/notifications/templategroup/conversions.go similarity index 84% rename from pkg/registry/apis/alerting/notifications/template_group/conversions.go rename to pkg/registry/apis/alerting/notifications/templategroup/conversions.go index 4988f3187f5..f7e5f83057a 100644 --- a/pkg/registry/apis/alerting/notifications/template_group/conversions.go +++ b/pkg/registry/apis/alerting/notifications/templategroup/conversions.go @@ -1,11 +1,13 @@ -package template_group +package templategroup import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1" + gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils" + "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" @@ -15,7 +17,7 @@ func convertToK8sResources(orgID int64, list []definitions.NotificationTemplate, result := &model.TemplateGroupList{} for _, t := range list { item := convertToK8sResource(orgID, t, namespacer) - if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableTemplateGroupFields(item)) { + if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableFields(item)) { continue } result.Items = append(result.Items, *item) @@ -25,19 +27,19 @@ func convertToK8sResources(orgID int64, list []definitions.NotificationTemplate, func convertToK8sResource(orgID int64, template definitions.NotificationTemplate, namespacer request.NamespaceMapper) *model.TemplateGroup { result := &model.TemplateGroup{ - TypeMeta: resourceInfo.TypeMeta(), ObjectMeta: metav1.ObjectMeta{ UID: types.UID(template.UID), Name: template.UID, Namespace: namespacer(orgID), ResourceVersion: template.ResourceVersion, }, - Spec: model.TemplateGroupSpec{ + Spec: model.Spec{ Title: template.Name, Content: template.Template, }, } result.SetProvenanceStatus(string(template.Provenance)) + result.UID = gapiutil.CalculateClusterWideUID(result) return result } diff --git a/pkg/registry/apis/alerting/notifications/template_group/legacy_storage.go b/pkg/registry/apis/alerting/notifications/templategroup/legacy_storage.go similarity index 89% rename from pkg/registry/apis/alerting/notifications/template_group/legacy_storage.go rename to pkg/registry/apis/alerting/notifications/templategroup/legacy_storage.go index 09a783e2af1..1d12bbc8074 100644 --- a/pkg/registry/apis/alerting/notifications/template_group/legacy_storage.go +++ b/pkg/registry/apis/alerting/notifications/templategroup/legacy_storage.go @@ -1,4 +1,4 @@ -package template_group +package templategroup import ( "context" @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" - notifications "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1" grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" @@ -29,20 +29,18 @@ type TemplateService interface { DeleteTemplate(ctx context.Context, orgID int64, nameOrUid string, provenance definitions.Provenance, version string) error } -var resourceInfo = notifications.TemplateGroupResourceInfo - type legacyStorage struct { service TemplateService namespacer request.NamespaceMapper tableConverter rest.TableConvertor } -func (s *legacyStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) { - return nil, errors.NewMethodNotSupported(resourceInfo.GroupResource(), "deleteCollection") +func (s *legacyStorage) DeleteCollection(context.Context, rest.ValidateObjectFunc, *metav1.DeleteOptions, *internalversion.ListOptions) (runtime.Object, error) { + return nil, errors.NewMethodNotSupported(ResourceInfo.GroupResource(), "deleteCollection") } func (s *legacyStorage) New() runtime.Object { - return resourceInfo.NewFunc() + return ResourceInfo.NewFunc() } func (s *legacyStorage) Destroy() {} @@ -52,11 +50,11 @@ func (s *legacyStorage) NamespaceScoped() bool { } func (s *legacyStorage) GetSingularName() string { - return resourceInfo.GetSingularName() + return ResourceInfo.GetSingularName() } func (s *legacyStorage) NewList() runtime.Object { - return resourceInfo.NewListFunc() + return ResourceInfo.NewListFunc() } func (s *legacyStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { @@ -104,7 +102,7 @@ func (s *legacyStorage) Create(ctx context.Context, return nil, err } } - p, ok := obj.(*notifications.TemplateGroup) + p, ok := obj.(*model.TemplateGroup) if !ok { return nil, fmt.Errorf("expected template but got %s", obj.GetObjectKind().GroupVersionKind()) } @@ -148,7 +146,7 @@ func (s *legacyStorage) Update(ctx context.Context, } } - p, ok := obj.(*notifications.TemplateGroup) + p, ok := obj.(*model.TemplateGroup) if !ok { return nil, false, fmt.Errorf("expected template but got %s", obj.GetObjectKind().GroupVersionKind()) } diff --git a/pkg/registry/apis/alerting/notifications/templategroup/storage.go b/pkg/registry/apis/alerting/notifications/templategroup/storage.go new file mode 100644 index 00000000000..d1f0a4c11ec --- /dev/null +++ b/pkg/registry/apis/alerting/notifications/templategroup/storage.go @@ -0,0 +1,29 @@ +package templategroup + +import ( + "k8s.io/apiserver/pkg/registry/rest" + + grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic" + "github.com/grafana/grafana/pkg/services/apiserver/builder" + "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" +) + +func NewStorage( + legacySvc TemplateService, + namespacer request.NamespaceMapper, + opts builder.APIGroupOptions, +) (rest.Storage, error) { + legacyStore := &legacyStorage{ + service: legacySvc, + namespacer: namespacer, + tableConverter: ResourceInfo.TableConverter(), + } + if opts.OptsGetter != nil && opts.DualWriteBuilder != nil { + store, err := grafanaregistry.NewRegistryStore(opts.Scheme, ResourceInfo, opts.OptsGetter) + if err != nil { + return nil, err + } + return opts.DualWriteBuilder(ResourceInfo.GroupResource(), legacyStore, store) + } + return legacyStore, nil +} diff --git a/pkg/registry/apis/alerting/notifications/templategroup/type.go b/pkg/registry/apis/alerting/notifications/templategroup/type.go new file mode 100644 index 00000000000..d1803d5aa33 --- /dev/null +++ b/pkg/registry/apis/alerting/notifications/templategroup/type.go @@ -0,0 +1,59 @@ +package templategroup + +import ( + "fmt" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/utils" +) + +var kind = model.Kind() +var GetOpenAPIDefinitions = model.GetOpenAPIDefinitions +var ResourceInfo = utils.NewResourceInfo(kind.Group(), kind.Version(), + kind.GroupVersionResource().Resource, strings.ToLower(kind.Kind()), kind.Kind(), + func() runtime.Object { return kind.ZeroValue() }, + func() runtime.Object { return kind.ZeroListValue() }, + utils.TableColumns{ + Definition: []metav1.TableColumnDefinition{ + {Name: "Name", Type: "string", Format: "name"}, + }, + Reader: func(obj any) ([]interface{}, error) { + r, ok := obj.(*model.TemplateGroup) + if !ok { + return nil, fmt.Errorf("expected resource or info") + } + return []interface{}{ + r.Name, + }, nil + }, + }, +) + +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(ResourceInfo.GroupVersion(), + &model.TemplateGroup{}, + &model.TemplateGroupList{}, + ) + metav1.AddToGroupVersion(scheme, ResourceInfo.GroupVersion()) + + err := scheme.AddFieldLabelConversionFunc( + ResourceInfo.GroupVersionKind(), + func(label, value string) (string, string, error) { + fieldSet := model.SelectableFields(&model.TemplateGroup{}) + for key := range fieldSet { + if label == key { + return label, value, nil + } + } + return "", "", fmt.Errorf("field label not supported for %s: %s", ResourceInfo.GroupVersionKind(), label) + }, + ) + if err != nil { + return err + } + return nil +} diff --git a/pkg/registry/apis/alerting/notifications/timeinterval/authorize.go b/pkg/registry/apis/alerting/notifications/timeinterval/authorize.go index 2966cbe8434..179ec172ab6 100644 --- a/pkg/registry/apis/alerting/notifications/timeinterval/authorize.go +++ b/pkg/registry/apis/alerting/notifications/timeinterval/authorize.go @@ -3,13 +3,14 @@ package timeinterval import ( "context" + "k8s.io/apiserver/pkg/authorization/authorizer" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "k8s.io/apiserver/pkg/authorization/authorizer" ) func Authorize(ctx context.Context, ac accesscontrol.AccessControl, attr authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) { - if attr.GetResource() != resourceInfo.GroupResource().Resource { + if attr.GetResource() != ResourceInfo.GroupResource().Resource { return authorizer.DecisionNoOpinion, "", nil } user, err := identity.GetRequester(ctx) diff --git a/pkg/registry/apis/alerting/notifications/timeinterval/conversions.go b/pkg/registry/apis/alerting/notifications/timeinterval/conversions.go index 15772b5d2f5..855c81c54e3 100644 --- a/pkg/registry/apis/alerting/notifications/timeinterval/conversions.go +++ b/pkg/registry/apis/alerting/notifications/timeinterval/conversions.go @@ -7,8 +7,9 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" + gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/provisioning" @@ -19,7 +20,7 @@ func convertToK8sResources(orgID int64, intervals []definitions.MuteTimeInterval if err != nil { return nil, err } - var specs []model.TimeIntervalSpec + var specs []model.Spec err = json.Unmarshal(data, &specs) if err != nil { return nil, err @@ -30,7 +31,7 @@ func convertToK8sResources(orgID int64, intervals []definitions.MuteTimeInterval interval := intervals[idx] spec := specs[idx] item := buildTimeInterval(orgID, interval, spec, namespacer) - if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableTimeIntervalsFields(&item)) { + if selector != nil && !selector.Empty() && !selector.Matches(model.SelectableFields(&item)) { continue } result.Items = append(result.Items, item) @@ -43,18 +44,18 @@ func convertToK8sResource(orgID int64, interval definitions.MuteTimeInterval, na if err != nil { return nil, err } - spec := model.TimeIntervalSpec{} + spec := model.Spec{} err = json.Unmarshal(data, &spec) if err != nil { return nil, err } result := buildTimeInterval(orgID, interval, spec, namespacer) + result.UID = gapiutil.CalculateClusterWideUID(&result) return &result, nil } -func buildTimeInterval(orgID int64, interval definitions.MuteTimeInterval, spec model.TimeIntervalSpec, namespacer request.NamespaceMapper) model.TimeInterval { +func buildTimeInterval(orgID int64, interval definitions.MuteTimeInterval, spec model.Spec, namespacer request.NamespaceMapper) model.TimeInterval { i := model.TimeInterval{ - TypeMeta: resourceInfo.TypeMeta(), ObjectMeta: metav1.ObjectMeta{ UID: types.UID(interval.UID), // TODO This is needed to make PATCH work Name: interval.UID, // TODO replace to stable UID when we switch to normal storage @@ -64,6 +65,7 @@ func buildTimeInterval(orgID int64, interval definitions.MuteTimeInterval, spec Spec: spec, } i.SetProvenanceStatus(string(interval.Provenance)) + i.UID = gapiutil.CalculateClusterWideUID(&i) return i } diff --git a/pkg/registry/apis/alerting/notifications/timeinterval/legacy_storage.go b/pkg/registry/apis/alerting/notifications/timeinterval/legacy_storage.go index c586c0b1c1b..7a7ef74165a 100644 --- a/pkg/registry/apis/alerting/notifications/timeinterval/legacy_storage.go +++ b/pkg/registry/apis/alerting/notifications/timeinterval/legacy_storage.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" - notifications "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1" grafanaRest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" @@ -21,8 +21,6 @@ var ( _ grafanaRest.LegacyStorage = (*legacyStorage)(nil) ) -var resourceInfo = notifications.TimeIntervalResourceInfo - type TimeIntervalService interface { GetMuteTimings(ctx context.Context, orgID int64) ([]definitions.MuteTimeInterval, error) CreateMuteTiming(ctx context.Context, mt definitions.MuteTimeInterval, orgID int64) (definitions.MuteTimeInterval, error) @@ -37,7 +35,7 @@ type legacyStorage struct { } func (s *legacyStorage) New() runtime.Object { - return resourceInfo.NewFunc() + return ResourceInfo.NewFunc() } func (s *legacyStorage) Destroy() {} @@ -47,11 +45,11 @@ func (s *legacyStorage) NamespaceScoped() bool { } func (s *legacyStorage) GetSingularName() string { - return resourceInfo.GetSingularName() + return ResourceInfo.GetSingularName() } func (s *legacyStorage) NewList() runtime.Object { - return resourceInfo.NewListFunc() + return ResourceInfo.NewListFunc() } func (s *legacyStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { @@ -88,7 +86,7 @@ func (s *legacyStorage) Get(ctx context.Context, uid string, _ *metav1.GetOption return convertToK8sResource(info.OrgID, mt, s.namespacer) } } - return nil, errors.NewNotFound(resourceInfo.GroupResource(), uid) + return nil, errors.NewNotFound(ResourceInfo.GroupResource(), uid) } func (s *legacyStorage) Create(ctx context.Context, @@ -105,7 +103,7 @@ func (s *legacyStorage) Create(ctx context.Context, return nil, err } } - p, ok := obj.(*notifications.TimeInterval) + p, ok := obj.(*model.TimeInterval) if !ok { return nil, fmt.Errorf("expected time-interval but got %s", obj.GetObjectKind().GroupVersionKind()) } @@ -149,7 +147,7 @@ func (s *legacyStorage) Update(ctx context.Context, return nil, false, err } } - p, ok := obj.(*notifications.TimeInterval) + p, ok := obj.(*model.TimeInterval) if !ok { return nil, false, fmt.Errorf("expected time-interval but got %s", obj.GetObjectKind().GroupVersionKind()) } @@ -190,7 +188,7 @@ func (s *legacyStorage) Delete(ctx context.Context, uid string, deleteValidation if options.Preconditions != nil && options.Preconditions.ResourceVersion != nil { version = *options.Preconditions.ResourceVersion } - p, ok := old.(*notifications.TimeInterval) + p, ok := old.(*model.TimeInterval) if !ok { return nil, false, fmt.Errorf("expected time-interval but got %s", old.GetObjectKind().GroupVersionKind()) } @@ -199,6 +197,6 @@ func (s *legacyStorage) Delete(ctx context.Context, uid string, deleteValidation return old, false, err // false - will be deleted async } -func (s *legacyStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) { - return nil, errors.NewMethodNotSupported(resourceInfo.GroupResource(), "deleteCollection") +func (s *legacyStorage) DeleteCollection(context.Context, rest.ValidateObjectFunc, *metav1.DeleteOptions, *internalversion.ListOptions) (runtime.Object, error) { + return nil, errors.NewMethodNotSupported(ResourceInfo.GroupResource(), "deleteCollection") } diff --git a/pkg/registry/apis/alerting/notifications/timeinterval/storage.go b/pkg/registry/apis/alerting/notifications/timeinterval/storage.go index 63e1943faf8..cba2e236575 100644 --- a/pkg/registry/apis/alerting/notifications/timeinterval/storage.go +++ b/pkg/registry/apis/alerting/notifications/timeinterval/storage.go @@ -1,67 +1,29 @@ package timeinterval import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apiserver/pkg/registry/generic" - genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" - apistore "k8s.io/apiserver/pkg/storage" - model "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic" - grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" + "github.com/grafana/grafana/pkg/services/apiserver/builder" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" ) -var _ grafanarest.Storage = (*storage)(nil) - -type storage struct { - *genericregistry.Store -} - -func (s storage) Compare(storageObj, legacyObj runtime.Object) bool { - // TODO implement when supported dual write mode is not Mode0 - return false -} - func NewStorage( legacySvc TimeIntervalService, namespacer request.NamespaceMapper, - scheme *runtime.Scheme, - optsGetter generic.RESTOptionsGetter, - dualWriteBuilder grafanarest.DualWriteBuilder, + opts builder.APIGroupOptions, ) (rest.Storage, error) { legacyStore := &legacyStorage{ service: legacySvc, namespacer: namespacer, - tableConverter: resourceInfo.TableConverter(), + tableConverter: ResourceInfo.TableConverter(), } - if optsGetter != nil && dualWriteBuilder != nil { - store, err := grafanaregistry.NewRegistryStore(scheme, resourceInfo, optsGetter) + if opts.OptsGetter != nil && opts.DualWriteBuilder != nil { + store, err := grafanaregistry.NewRegistryStore(opts.Scheme, ResourceInfo, opts.OptsGetter) if err != nil { return nil, err } - return dualWriteBuilder(resourceInfo.GroupResource(), legacyStore, store) + return opts.DualWriteBuilder(ResourceInfo.GroupResource(), legacyStore, store) } return legacyStore, nil } - -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { - if s, ok := obj.(*model.TimeInterval); ok { - return s.Labels, model.SelectableTimeIntervalsFields(s), nil - } - return nil, nil, fmt.Errorf("object of type %T is not supported", obj) -} - -// Matcher returns a generic.SelectionPredicate that matches on label and field selectors. -func Matcher(label labels.Selector, field fields.Selector) apistore.SelectionPredicate { - return apistore.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} diff --git a/pkg/registry/apis/alerting/notifications/timeinterval/type.go b/pkg/registry/apis/alerting/notifications/timeinterval/type.go new file mode 100644 index 00000000000..3e49c67e863 --- /dev/null +++ b/pkg/registry/apis/alerting/notifications/timeinterval/type.go @@ -0,0 +1,59 @@ +package timeinterval + +import ( + "fmt" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + + model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/utils" +) + +var kind = model.Kind() +var GetOpenAPIDefinitions = model.GetOpenAPIDefinitions +var ResourceInfo = utils.NewResourceInfo(kind.Group(), kind.Version(), + kind.GroupVersionResource().Resource, strings.ToLower(kind.Kind()), kind.Kind(), + func() runtime.Object { return kind.ZeroValue() }, + func() runtime.Object { return kind.ZeroListValue() }, + utils.TableColumns{ + Definition: []metav1.TableColumnDefinition{ + {Name: "Name", Type: "string", Format: "name"}, + }, + Reader: func(obj any) ([]interface{}, error) { + r, ok := obj.(*model.TimeInterval) + if !ok { + return nil, fmt.Errorf("expected resource or info") + } + return []interface{}{ + r.Name, + }, nil + }, + }, +) + +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(ResourceInfo.GroupVersion(), + &model.TimeInterval{}, + &model.TimeIntervalList{}, + ) + metav1.AddToGroupVersion(scheme, ResourceInfo.GroupVersion()) + + err := scheme.AddFieldLabelConversionFunc( + ResourceInfo.GroupVersionKind(), + func(label, value string) (string, string, error) { + fieldSet := model.SelectableFields(&model.TimeInterval{}) + for key := range fieldSet { + if label == key { + return label, value, nil + } + } + return "", "", fmt.Errorf("field label not supported for %s: %s", ResourceInfo.GroupVersionKind(), label) + }, + ) + if err != nil { + return err + } + return nil +} diff --git a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go index f17d6bb0bc2..67938652c89 100644 --- a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go +++ b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go @@ -20,13 +20,14 @@ import ( "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/dynamic" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/receiver/v0alpha1" common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/generated/clientset/versioned" - notificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" @@ -72,22 +73,19 @@ func TestIntegrationResourceIdentifier(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - client := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + client := newClient(t, helper.Org1.Admin) newResource := &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "Test-Receiver", Integrations: nil, }, } t.Run("create should fail if object name is specified", func(t *testing.T) { - resource := newResource.DeepCopy() + resource := newResource.Copy().(*v0alpha1.Receiver) resource.Name = "new-receiver" _, err := client.Create(ctx, resource, v1.CreateOptions{}) require.Truef(t, errors.IsBadRequest(err), "Expected BadRequest but got %s", err) @@ -113,7 +111,7 @@ func TestIntegrationResourceIdentifier(t *testing.T) { existing, err := client.Get(ctx, resourceID, v1.GetOptions{}) require.NoError(t, err) - updated := existing.DeepCopy() + updated := existing.Copy().(*v0alpha1.Receiver) updated.Spec.Title = "another-newReceiver" actual, err := client.Update(ctx, updated, v1.UpdateOptions{}) @@ -150,12 +148,6 @@ func TestIntegrationResourcePermissions(t *testing.T) { ), }) - newClient := func(t *testing.T, user apis.User) notificationsv0alpha1.ReceiverInterface { - k8sClient, err := versioned.NewForConfig(user.NewRestConfig()) - require.NoError(t, err) - return k8sClient.NotificationsV0alpha1().Receivers("default") - } - admin := org1.Admin viewer := org1.Viewer editor := org1.Editor @@ -318,7 +310,7 @@ func TestIntegrationResourcePermissions(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "receiver-1", Integrations: nil, }, @@ -349,7 +341,7 @@ func TestIntegrationResourcePermissions(t *testing.T) { extractReceiverFromList := func(list *v0alpha1.ReceiverList, name string) *v0alpha1.Receiver { for i := range list.Items { if list.Items[i].Name == name { - return list.Items[i].DeepCopy() + return list.Items[i].Copy().(*v0alpha1.Receiver) } } return nil @@ -362,7 +354,7 @@ func TestIntegrationResourcePermissions(t *testing.T) { require.NotNil(t, expectedGet) // Set expected metadata. - expectedGetWithMetadata := expectedGet.DeepCopy() + expectedGetWithMetadata := expectedGet.Copy().(*v0alpha1.Receiver) // Clear any existing access control metadata. for _, k := range allACMetadata { delete(expectedGetWithMetadata.Annotations, v0alpha1.AccessControlAnnotation(k)) @@ -375,7 +367,7 @@ func TestIntegrationResourcePermissions(t *testing.T) { require.NoError(t, err) expectedListWithMetadata := extractReceiverFromList(expectedList, created.Name) require.NotNil(t, expectedListWithMetadata) - expectedListWithMetadata = expectedListWithMetadata.DeepCopy() + expectedListWithMetadata = expectedListWithMetadata.Copy().(*v0alpha1.Receiver) // Clear any existing access control metadata. for _, k := range allACMetadata { delete(expectedListWithMetadata.Annotations, v0alpha1.AccessControlAnnotation(k)) @@ -575,22 +567,16 @@ func TestIntegrationAccessControl(t *testing.T) { }, } - admin := org1.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) for _, tc := range testCases { t.Run(fmt.Sprintf("user '%s'", tc.user.Identity.GetLogin()), func(t *testing.T) { - k8sClient, err := versioned.NewForConfig(tc.user.NewRestConfig()) - require.NoError(t, err) - client := k8sClient.NotificationsV0alpha1().Receivers("default") + client := newClient(t, tc.user) var expected = &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: fmt.Sprintf("receiver-1-%s", tc.user.Identity.GetLogin()), Integrations: nil, }, @@ -598,7 +584,7 @@ func TestIntegrationAccessControl(t *testing.T) { d, err := json.Marshal(expected) require.NoError(t, err) - newReceiver := expected.DeepCopy() + newReceiver := expected.Copy().(*v0alpha1.Receiver) newReceiver.Spec.Title = fmt.Sprintf("receiver-2-%s", tc.user.Identity.GetLogin()) if tc.canCreate { t.Run("should be able to create receiver", func(t *testing.T) { @@ -630,7 +616,7 @@ func TestIntegrationAccessControl(t *testing.T) { if tc.canRead { // Set expected metadata. - expectedWithMetadata := expected.DeepCopy() + expectedWithMetadata := expected.Copy().(*v0alpha1.Receiver) expectedWithMetadata.SetInUse(0, nil) if tc.canUpdate { expectedWithMetadata.SetAccessControl("canWrite") @@ -678,7 +664,7 @@ func TestIntegrationAccessControl(t *testing.T) { }) } - updatedExpected := expected.DeepCopy() + updatedExpected := expected.Copy().(*v0alpha1.Receiver) updatedExpected.Spec.Integrations = append(updatedExpected.Spec.Integrations, createIntegration(t, "email")) d, err = json.Marshal(updatedExpected) @@ -692,7 +678,7 @@ func TestIntegrationAccessControl(t *testing.T) { expected = updated t.Run("should get NotFound if name does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.Receiver) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsNotFound(err), "Should get NotFound error but got: %s", err) @@ -704,7 +690,7 @@ func TestIntegrationAccessControl(t *testing.T) { require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) t.Run("should get forbidden even if resource does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.Receiver) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) @@ -759,10 +745,7 @@ func TestIntegrationInUseMetadata(t *testing.T) { cliCfg := helper.Org1.Admin.NewRestConfig() legacyCli := alerting.NewAlertingLegacyAPIClient(helper.GetEnv().Server.HTTPServer.Listener.Addr().String(), cliCfg.Username, cliCfg.Password) - adminK8sClient, err := versioned.NewForConfig(cliCfg) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) // Prepare environment and create notification policy and rule that use receiver alertmanagerRaw, err := testData.ReadFile(path.Join("test-data", "notification-settings.json")) require.NoError(t, err) @@ -884,10 +867,7 @@ func TestIntegrationProvisioning(t *testing.T) { org := helper.Org1 admin := org.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) env := helper.GetEnv() ac := acimpl.ProvideAccessControl(env.FeatureToggles, zanzana.NewNoopClient()) db, err := store.ProvideDBStore(env.Cfg, env.FeatureToggles, env.SQLStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac, bus.ProvideBus(tracing.InitializeTracerForTest())) @@ -897,7 +877,7 @@ func TestIntegrationProvisioning(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "test-receiver-1", Integrations: []v0alpha1.Integration{ createIntegration(t, "email"), @@ -920,7 +900,7 @@ func TestIntegrationProvisioning(t *testing.T) { t.Run("should not let update if provisioned", func(t *testing.T) { got, err := adminClient.Get(ctx, created.Name, v1.GetOptions{}) require.NoError(t, err) - updated := got.DeepCopy() + updated := got.Copy().(*v0alpha1.Receiver) updated.Spec.Integrations = append(updated.Spec.Integrations, createIntegration(t, "email")) _, err = adminClient.Update(ctx, updated, v1.UpdateOptions{}) @@ -941,15 +921,12 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) receiver := v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "receiver-1", Integrations: nil, }, @@ -961,13 +938,13 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { require.NotEmpty(t, created.ResourceVersion) t.Run("should forbid if version does not match", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.Receiver) updated.ResourceVersion = "test" _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.Truef(t, errors.IsConflict(err), "should get Forbidden error but got %s", err) }) t.Run("should update if version matches", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.Receiver) updated.Spec.Integrations = append(updated.Spec.Integrations, createIntegration(t, "email")) actualUpdated, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -978,7 +955,7 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { require.NotEqual(t, updated.ResourceVersion, actualUpdated.ResourceVersion) }) t.Run("should fail to update if version is empty", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.Receiver) updated.ResourceVersion = "" updated.Spec.Integrations = append(updated.Spec.Integrations, createIntegration(t, "webhook")) _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) @@ -1027,15 +1004,12 @@ func TestIntegrationPatch(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) receiver := v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "receiver", Integrations: []v0alpha1.Integration{ createIntegration(t, "email"), @@ -1083,9 +1057,9 @@ func TestIntegrationPatch(t *testing.T) { } expected := current.Spec.Integrations[index] - expected.Settings.Remove("username") - expected.Settings.Remove("password") - expected.Settings.Set("authorization_scheme", "bearer") + delete(expected.Settings, "username") + delete(expected.Settings, "password") + expected.Settings["authorization_scheme"] = "bearer" delete(expected.SecureFields, "password") expected.SecureFields["authorization_credentials"] = true @@ -1128,9 +1102,7 @@ func TestIntegrationRejectConfigApiReceiverModification(t *testing.T) { cliCfg := helper.Org1.Admin.NewRestConfig() legacyCli := alerting.NewAlertingLegacyAPIClient(helper.GetEnv().Server.HTTPServer.Listener.Addr().String(), cliCfg.Username, cliCfg.Password) - adminK8sClient, err := versioned.NewForConfig(cliCfg) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") + adminClient := newClient(t, helper.Org1.Admin) alertmanagerRaw, err := testData.ReadFile(path.Join("test-data", "notification-settings.json")) require.NoError(t, err) @@ -1205,10 +1177,7 @@ func TestIntegrationReferentialIntegrity(t *testing.T) { cliCfg := helper.Org1.Admin.NewRestConfig() legacyCli := alerting.NewAlertingLegacyAPIClient(helper.GetEnv().Server.HTTPServer.Listener.Addr().String(), cliCfg.Username, cliCfg.Password) - adminK8sClient, err := versioned.NewForConfig(cliCfg) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) // Prepare environment and create notification policy and rule that use time receiver alertmanagerRaw, err := testData.ReadFile(path.Join("test-data", "notification-settings.json")) require.NoError(t, err) @@ -1240,7 +1209,7 @@ func TestIntegrationReferentialIntegrity(t *testing.T) { t.Run("Update", func(t *testing.T) { t.Run("should rename all references if name changes", func(t *testing.T) { - renamed := receiver.DeepCopy() + renamed := receiver.Copy().(*v0alpha1.Receiver) expectedTitle := renamed.Spec.Title + "-new" renamed.Spec.Title = expectedTitle @@ -1265,7 +1234,7 @@ func TestIntegrationReferentialIntegrity(t *testing.T) { t.Run("should fail if at least one resource is provisioned", func(t *testing.T) { require.NoError(t, err) - renamed := receiver.DeepCopy() + renamed := receiver.Copy().(*v0alpha1.Receiver) renamed.Spec.Title += util.GenerateShortUID() t.Run("provisioned route", func(t *testing.T) { @@ -1318,10 +1287,7 @@ func TestIntegrationCRUD(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - + adminClient := newClient(t, helper.Org1.Admin) var defaultReceiver *v0alpha1.Receiver t.Run("should list the default receiver", func(t *testing.T) { items, err := adminClient.List(ctx, v1.ListOptions{}) @@ -1343,19 +1309,19 @@ func TestIntegrationCRUD(t *testing.T) { t.Run("should be able to update default receiver", func(t *testing.T) { require.NotNil(t, defaultReceiver) - newDefault := defaultReceiver.DeepCopy() + newDefault := defaultReceiver.Copy().(*v0alpha1.Receiver) newDefault.Spec.Integrations = append(newDefault.Spec.Integrations, createIntegration(t, "line")) updatedReceiver, err := adminClient.Update(ctx, newDefault, v1.UpdateOptions{}) require.NoError(t, err) - expected := newDefault.DeepCopy() + expected := newDefault.Copy().(*v0alpha1.Receiver) expected.Spec.Integrations[0].Uid = updatedReceiver.Spec.Integrations[0].Uid // default integration does not have UID before first update lineIntegration := expected.Spec.Integrations[1] lineIntegration.SecureFields = map[string]bool{ "token": true, } - lineIntegration.Settings.Remove("token") + delete(lineIntegration.Settings, "token") assert.Equal(t, "LINE", updatedReceiver.Spec.Integrations[1].Type) // this type is in the schema but not in backend lineIntegration.Type = "LINE" lineIntegration.Uid = updatedReceiver.Spec.Integrations[1].Uid @@ -1369,7 +1335,7 @@ func TestIntegrationCRUD(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: defaultReceiver.Spec.Title, Integrations: nil, }, @@ -1392,12 +1358,12 @@ func TestIntegrationCRUD(t *testing.T) { for _, key := range keys { integrations = append(integrations, createIntegration(t, key)) } - + var err error receiver, err = adminClient.Create(ctx, &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "all-receivers", Integrations: integrations, }, @@ -1436,7 +1402,7 @@ func TestIntegrationCRUD(t *testing.T) { assert.Contains(t, integration.SecureFields, field) assert.Truef(t, integration.SecureFields[field], "secure field should be always true") - value, ok, err := unstructured.NestedString(integration.Settings.Object, strings.Split(field, ".")...) + value, ok, err := unstructured.NestedString(integration.Settings, strings.Split(field, ".")...) assert.NoErrorf(t, err, "failed to read field %s from settings", field) assert.Falsef(t, ok, "secret field %s should not be in settings, value [%s]", field, value) } @@ -1453,17 +1419,17 @@ func TestIntegrationCRUD(t *testing.T) { t.Run(key, func(t *testing.T) { integration := createIntegration(t, key) // Make the integration invalid, so it fails to create. This is usually done by sending empty settings. - clear(integration.Settings.Object) + clear(integration.Settings) if key == "webex" { // Webex integration is special case and passes validation without any settings so we instead set an invalid URL. - integration.Settings.Set("api_url", "(*^$*^%!@#$*()") + integration.Settings["api_url"] = "(*^$*^%!@#$*()" } - receiver, err = adminClient.Create(ctx, &v0alpha1.Receiver{ + receiver, err := adminClient.Create(ctx, &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: fmt.Sprintf("invalid-%s", key), Integrations: []v0alpha1.Integration{integration}, }, @@ -1483,30 +1449,26 @@ func TestIntegrationReceiverListSelector(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().Receivers("default") - - require.NoError(t, err) + adminClient := newClient(t, helper.Org1.Admin) recv1 := &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "test-receiver-1", Integrations: []v0alpha1.Integration{ createIntegration(t, "email"), }, }, } - recv1, err = adminClient.Create(ctx, recv1, v1.CreateOptions{}) + recv1, err := adminClient.Create(ctx, recv1, v1.CreateOptions{}) require.NoError(t, err) recv2 := &v0alpha1.Receiver{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: "test-receiver-2", Integrations: []v0alpha1.Integration{ createIntegration(t, "email"), @@ -1551,7 +1513,7 @@ func TestIntegrationReceiverListSelector(t *testing.T) { t.Run("should filter by multiple filters", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", recv2.Name, "API"), + FieldSelector: fmt.Sprintf("metadata.name=%s,spec.title=%s", recv2.Name, recv2.Spec.Title), }) require.NoError(t, err) require.Len(t, list.Items, 1) @@ -1560,7 +1522,7 @@ func TestIntegrationReceiverListSelector(t *testing.T) { t.Run("should be empty when filter does not match", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", recv2.Name, "unknown"), + FieldSelector: fmt.Sprintf("metadata.name=%s", "unknown"), }) require.NoError(t, err) require.Empty(t, list.Items) @@ -1569,7 +1531,7 @@ func TestIntegrationReceiverListSelector(t *testing.T) { // persistInitialConfig helps create an initial config with new receivers using legacy json. Config API blocks receiver // modifications, so we need to use k8s API to create new receivers before posting the config. -func persistInitialConfig(t *testing.T, amConfig definitions.PostableUserConfig, adminClient notificationsv0alpha1.ReceiverInterface, legacyCli alerting.LegacyApiClient) { +func persistInitialConfig(t *testing.T, amConfig definitions.PostableUserConfig, adminClient *apis.TypedClient[v0alpha1.Receiver, v0alpha1.ReceiverList], legacyCli alerting.LegacyApiClient) { ctx := context.Background() var defaultReceiver *definitions.PostableApiReceiver @@ -1583,7 +1545,7 @@ func persistInitialConfig(t *testing.T, amConfig definitions.PostableUserConfig, ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.ReceiverSpec{ + Spec: v0alpha1.Spec{ Title: receiver.Name, Integrations: []v0alpha1.Integration{}, }, @@ -1593,7 +1555,7 @@ func persistInitialConfig(t *testing.T, amConfig definitions.PostableUserConfig, settings := common.Unstructured{} require.NoError(t, settings.UnmarshalJSON(integration.Settings)) toCreate.Spec.Integrations = append(toCreate.Spec.Integrations, v0alpha1.Integration{ - Settings: settings, + Settings: settings.Object, Type: integration.Type, DisableResolveMessage: util.Pointer(false), }) @@ -1631,7 +1593,7 @@ func createIntegrationWithSettings(t *testing.T, integrationType string, setting settings := common.Unstructured{} require.NoError(t, settings.UnmarshalJSON([]byte(settingsJson))) return v0alpha1.Integration{ - Settings: settings, + Settings: settings.Object, Type: integrationType, DisableResolveMessage: util.Pointer(false), } @@ -1645,3 +1607,19 @@ func createWildcardPermission(actions ...string) resourcepermissions.SetResource ResourceID: "*", } } + +func newClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.Receiver, v0alpha1.ReceiverList] { + t.Helper() + + client, err := dynamic.NewForConfig(user.NewRestConfig()) + require.NoError(t, err) + + return &apis.TypedClient[v0alpha1.Receiver, v0alpha1.ReceiverList]{ + Client: client.Resource( + schema.GroupVersionResource{ + Group: v0alpha1.Kind().Group(), + Version: v0alpha1.Kind().Version(), + Resource: v0alpha1.Kind().Plural(), + }).Namespace("default"), + } +} diff --git a/pkg/tests/apis/alerting/notifications/routing_tree/routing_tree_test.go b/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go similarity index 92% rename from pkg/tests/apis/alerting/notifications/routing_tree/routing_tree_test.go rename to pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go index e71114bc23f..97e11f215ad 100644 --- a/pkg/tests/apis/alerting/notifications/routing_tree/routing_tree_test.go +++ b/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go @@ -1,4 +1,4 @@ -package routing_tree +package routingtree import ( "context" @@ -16,10 +16,11 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/dynamic" - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/routingtree/v0alpha1" "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/generated/clientset/versioned" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" @@ -57,21 +58,19 @@ func TestIntegrationNotAllowedMethods(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - client := adminK8sClient.NotificationsV0alpha1().RoutingTrees("default") + client := newClient(t, helper.Org1.Admin) route := &v0alpha1.RoutingTree{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.RoutingTreeSpec{}, + Spec: v0alpha1.Spec{}, } - _, err = client.Create(ctx, route, v1.CreateOptions{}) + _, err := client.Create(ctx, route, v1.CreateOptions{}) assert.Error(t, err) require.Truef(t, errors.IsMethodNotSupported(err), "Expected MethodNotSupported but got %s", err) - err = client.DeleteCollection(ctx, v1.DeleteOptions{}, v1.ListOptions{}) + err = client.Client.DeleteCollection(ctx, v1.DeleteOptions{}, v1.ListOptions{}) assert.Error(t, err) require.Truef(t, errors.IsMethodNotSupported(err), "Expected MethodNotSupported but got %s", err) } @@ -163,15 +162,11 @@ func TestIntegrationAccessControl(t *testing.T) { } admin := org1.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().RoutingTrees("default") + adminClient := newClient(t, admin) for _, tc := range testCases { t.Run(fmt.Sprintf("user '%s'", tc.user.Identity.GetLogin()), func(t *testing.T) { - k8sClient, err := versioned.NewForConfig(tc.user.NewRestConfig()) - require.NoError(t, err) - client := k8sClient.NotificationsV0alpha1().RoutingTrees("default") + client := newClient(t, tc.user) if tc.canRead { t.Run("should be able to list routing trees", func(t *testing.T) { @@ -212,7 +207,7 @@ func TestIntegrationAccessControl(t *testing.T) { current, err := adminClient.Get(ctx, v0alpha1.UserDefinedRoutingTreeName, v1.GetOptions{}) require.NoError(t, err) - expected := current.DeepCopy() + expected := current.Copy().(*v0alpha1.RoutingTree) expected.Spec.Routes = []v0alpha1.Route{ { Matchers: []v0alpha1.Matcher{ @@ -236,7 +231,7 @@ func TestIntegrationAccessControl(t *testing.T) { expected = updated t.Run("should get NotFound if name does not exist", func(t *testing.T) { - up := expected.DeepCopy() + up := expected.Copy().(*v0alpha1.RoutingTree) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Error(t, err) @@ -250,7 +245,7 @@ func TestIntegrationAccessControl(t *testing.T) { require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) t.Run("should get forbidden even if resource does not exist", func(t *testing.T) { - up := expected.DeepCopy() + up := expected.Copy().(*v0alpha1.RoutingTree) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Error(t, err) @@ -286,7 +281,7 @@ func TestIntegrationAccessControl(t *testing.T) { } }) - err = adminClient.Delete(ctx, v0alpha1.UserDefinedRoutingTreeName, v1.DeleteOptions{}) + err := adminClient.Delete(ctx, v0alpha1.UserDefinedRoutingTreeName, v1.DeleteOptions{}) require.NoError(t, err) } } @@ -302,9 +297,7 @@ func TestIntegrationProvisioning(t *testing.T) { org := helper.Org1 admin := org.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().RoutingTrees("default") + adminClient := newClient(t, admin) env := helper.GetEnv() ac := acimpl.ProvideAccessControl(env.FeatureToggles, zanzana.NewNoopClient()) @@ -323,7 +316,7 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, "API", got.GetProvenanceStatus()) }) t.Run("should not let update if provisioned", func(t *testing.T) { - updated := current.DeepCopy() + updated := current.Copy().(*v0alpha1.RoutingTree) updated.Spec.Routes = []v0alpha1.Route{ { Matchers: []v0alpha1.Matcher{ @@ -355,23 +348,21 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().RoutingTrees("default") + adminClient := newClient(t, helper.Org1.Admin) current, err := adminClient.Get(ctx, v0alpha1.UserDefinedRoutingTreeName, v1.GetOptions{}) require.NoError(t, err) require.NotEmpty(t, current.ResourceVersion) t.Run("should forbid if version does not match", func(t *testing.T) { - updated := current.DeepCopy() + updated := current.Copy().(*v0alpha1.RoutingTree) updated.ResourceVersion = "test" _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.Error(t, err) require.Truef(t, errors.IsConflict(err), "should get Forbidden error but got %s", err) }) t.Run("should update if version matches", func(t *testing.T) { - updated := current.DeepCopy() + updated := current.Copy().(*v0alpha1.RoutingTree) updated.Spec.Defaults.GroupBy = append(updated.Spec.Defaults.GroupBy, "data") actualUpdated, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -381,7 +372,7 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { t.Run("should update if version is empty", func(t *testing.T) { current, err = adminClient.Get(ctx, v0alpha1.UserDefinedRoutingTreeName, v1.GetOptions{}) require.NoError(t, err) - updated := current.DeepCopy() + updated := current.Copy().(*v0alpha1.RoutingTree) updated.ResourceVersion = "" updated.Spec.Routes = append(updated.Spec.Routes, v0alpha1.Route{Continue: true}) @@ -403,9 +394,7 @@ func TestIntegrationDataConsistency(t *testing.T) { cliCfg := helper.Org1.Admin.NewRestConfig() legacyCli := alerting.NewAlertingLegacyAPIClient(helper.GetEnv().Server.HTTPServer.Listener.Addr().String(), cliCfg.Username, cliCfg.Password) - adminK8sClient, err := versioned.NewForConfig(cliCfg) - require.NoError(t, err) - client := adminK8sClient.NotificationsV0alpha1().RoutingTrees("default") + client := newClient(t, helper.Org1.Admin) receiver := "grafana-default-email" timeInterval := "test-time-interval" @@ -641,3 +630,19 @@ func TestIntegrationDataConsistency(t *testing.T) { require.Equal(t, before, after) }) } + +func newClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.RoutingTree, v0alpha1.RoutingTreeList] { + t.Helper() + + client, err := dynamic.NewForConfig(user.NewRestConfig()) + require.NoError(t, err) + + return &apis.TypedClient[v0alpha1.RoutingTree, v0alpha1.RoutingTreeList]{ + Client: client.Resource( + schema.GroupVersionResource{ + Group: v0alpha1.Kind().Group(), + Version: v0alpha1.Kind().Version(), + Resource: v0alpha1.Kind().Plural(), + }).Namespace("default"), + } +} diff --git a/pkg/tests/apis/alerting/notifications/template_group/templates_group_test.go b/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go similarity index 89% rename from pkg/tests/apis/alerting/notifications/template_group/templates_group_test.go rename to pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go index 8c40d6de7df..8e9fb85fc6f 100644 --- a/pkg/tests/apis/alerting/notifications/template_group/templates_group_test.go +++ b/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go @@ -10,11 +10,12 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/dynamic" - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/templategroup/v0alpha1" "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/generated/clientset/versioned" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" @@ -51,22 +52,20 @@ func TestIntegrationResourceIdentifier(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - client := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + client := newClient(t, helper.Org1.Admin) newTemplate := &v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "templateGroup", Content: `{{ define "test" }} test {{ end }}`, }, } t.Run("create should fail if object name is specified", func(t *testing.T) { - template := newTemplate.DeepCopy() + template := newTemplate.Copy().(*v0alpha1.TemplateGroup) template.Name = "new-templateGroup" _, err := client.Create(ctx, template, v1.CreateOptions{}) assert.Error(t, err) @@ -95,7 +94,7 @@ func TestIntegrationResourceIdentifier(t *testing.T) { if existingTemplateGroup == nil { t.Skip() } - updated := existingTemplateGroup.DeepCopy() + updated := existingTemplateGroup.Copy().(*v0alpha1.TemplateGroup) updated.Spec.Title = "another-templateGroup" actual, err := client.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -187,22 +186,17 @@ func TestIntegrationAccessControl(t *testing.T) { }, } - admin := org1.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + adminClient := newClient(t, org1.Admin) for _, tc := range testCases { t.Run(fmt.Sprintf("user '%s'", tc.user.Identity.GetLogin()), func(t *testing.T) { - k8sClient, err := versioned.NewForConfig(tc.user.NewRestConfig()) - require.NoError(t, err) - client := k8sClient.NotificationsV0alpha1().TemplateGroups("default") + client := newClient(t, tc.user) var expected = &v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: fmt.Sprintf("template-group-1-%s", tc.user.Identity.GetLogin()), Content: `{{ define "test" }} test {{ end }}`, }, @@ -270,7 +264,7 @@ func TestIntegrationAccessControl(t *testing.T) { }) } - updatedExpected := expected.DeepCopy() + updatedExpected := expected.Copy().(*v0alpha1.TemplateGroup) updatedExpected.Spec.Content = `{{ define "another-test" }} test {{ end }}` d, err = json.Marshal(updatedExpected) @@ -284,7 +278,7 @@ func TestIntegrationAccessControl(t *testing.T) { expected = updated t.Run("should get NotFound if name does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.TemplateGroup) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsNotFound(err), "Should get NotFound error but got: %s", err) @@ -296,7 +290,7 @@ func TestIntegrationAccessControl(t *testing.T) { require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) t.Run("should get forbidden even if resource does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.TemplateGroup) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) @@ -351,9 +345,7 @@ func TestIntegrationProvisioning(t *testing.T) { org := helper.Org1 admin := org.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + adminClient := newClient(t, admin) env := helper.GetEnv() ac := acimpl.ProvideAccessControl(env.FeatureToggles, zanzana.NewNoopClient()) @@ -364,7 +356,7 @@ func TestIntegrationProvisioning(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "template-group-1", Content: `{{ define "test" }} test {{ end }}`, }, @@ -382,7 +374,7 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, "API", got.GetProvenanceStatus()) }) t.Run("should not let update if provisioned", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TemplateGroup) updated.Spec.Content = `{{ define "another-test" }} test {{ end }}` _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) @@ -403,15 +395,13 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + adminClient := newClient(t, helper.Org1.Admin) template := v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "template-group-1", Content: `{{ define "test" }} test {{ end }}`, }, @@ -423,13 +413,13 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { require.NotEmpty(t, created.ResourceVersion) t.Run("should forbid if version does not match", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TemplateGroup) updated.ResourceVersion = "test" _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.Truef(t, errors.IsConflict(err), "should get Forbidden error but got %s", err) }) t.Run("should update if version matches", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TemplateGroup) updated.Spec.Content = `{{ define "test-another" }} test {{ end }}` actualUpdated, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -437,7 +427,7 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { require.NotEqual(t, updated.ResourceVersion, actualUpdated.ResourceVersion) }) t.Run("should update if version is empty", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TemplateGroup) updated.ResourceVersion = "" updated.Spec.Content = `{{ define "test-another-2" }} test {{ end }}` @@ -489,15 +479,13 @@ func TestIntegrationPatch(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + adminClient := newClient(t, helper.Org1.Admin) template := v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "template-group", Content: `{{ define "test" }} test {{ end }}`, }, @@ -537,7 +525,7 @@ func TestIntegrationPatch(t *testing.T) { result, err := adminClient.Patch(ctx, current.Name, types.JSONPatchType, patchData, v1.PatchOptions{}) require.NoError(t, err) - expectedSpec := *current.Spec.DeepCopy() + expectedSpec := current.Spec expectedSpec.Content = expected require.EqualValues(t, expectedSpec, result.Spec) current = result @@ -551,28 +539,25 @@ func TestIntegrationListSelector(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TemplateGroups("default") + adminClient := newClient(t, helper.Org1.Admin) template1 := &v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "test1", Content: `{{ define "test1" }} test {{ end }}`, }, } - template1, err = adminClient.Create(ctx, template1, v1.CreateOptions{}) + template1, err := adminClient.Create(ctx, template1, v1.CreateOptions{}) require.NoError(t, err) template2 := &v0alpha1.TemplateGroup{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TemplateGroupSpec{ + Spec: v0alpha1.Spec{ Title: "test2", Content: `{{ define "test2" }} test {{ end }}`, }, @@ -614,7 +599,7 @@ func TestIntegrationListSelector(t *testing.T) { t.Run("should filter by multiple filters", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", template2.Name, "API"), + FieldSelector: fmt.Sprintf("metadata.name=%s,spec.title=%s", template2.Name, template2.Spec.Title), }) require.NoError(t, err) require.Len(t, list.Items, 1) @@ -623,9 +608,25 @@ func TestIntegrationListSelector(t *testing.T) { t.Run("should be empty when filter does not match", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", template2.Name, "unknown"), + FieldSelector: fmt.Sprintf("metadata.name=%s", "unknown"), }) require.NoError(t, err) require.Empty(t, list.Items) }) } + +func newClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.TemplateGroup, v0alpha1.TemplateGroupList] { + t.Helper() + + client, err := dynamic.NewForConfig(user.NewRestConfig()) + require.NoError(t, err) + + return &apis.TypedClient[v0alpha1.TemplateGroup, v0alpha1.TemplateGroupList]{ + Client: client.Resource( + schema.GroupVersionResource{ + Group: v0alpha1.Kind().Group(), + Version: v0alpha1.Kind().Version(), + Resource: v0alpha1.Kind().Plural(), + }).Namespace("default"), + } +} diff --git a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go index 6ba9df07f5c..9bda66ef9e1 100644 --- a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go +++ b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go @@ -15,11 +15,13 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/dynamic" - "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1" + "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/resource/timeinterval/v0alpha1/fakes" "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/generated/clientset/versioned" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" @@ -61,22 +63,20 @@ func TestIntegrationResourceIdentifier(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - client := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + client := newClient(t, helper.Org1.Admin) newInterval := &v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "time-newInterval", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } t.Run("create should fail if object name is specified", func(t *testing.T) { - interval := newInterval.DeepCopy() + interval := newInterval.Copy().(*v0alpha1.TimeInterval) interval.Name = "time-newInterval" _, err := client.Create(ctx, interval, v1.CreateOptions{}) require.Truef(t, errors.IsBadRequest(err), "Expected BadRequest but got %s", err) @@ -104,7 +104,7 @@ func TestIntegrationResourceIdentifier(t *testing.T) { if existingInterval == nil { t.Skip() } - updated := existingInterval.DeepCopy() + updated := existingInterval.Copy().(*v0alpha1.TimeInterval) updated.Spec.Name = "another-newInterval" actual, err := client.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -197,24 +197,18 @@ func TestIntegrationTimeIntervalAccessControl(t *testing.T) { }, } - admin := org1.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) for _, tc := range testCases { t.Run(fmt.Sprintf("user '%s'", tc.user.Identity.GetLogin()), func(t *testing.T) { - k8sClient, err := versioned.NewForConfig(tc.user.NewRestConfig()) - require.NoError(t, err) - client := k8sClient.NotificationsV0alpha1().TimeIntervals("default") - + client := newClient(t, tc.user) var expected = &v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: fmt.Sprintf("time-interval-1-%s", tc.user.Identity.GetLogin()), - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } expected.SetProvenanceStatus("") @@ -280,8 +274,8 @@ func TestIntegrationTimeIntervalAccessControl(t *testing.T) { }) } - updatedExpected := expected.DeepCopy() - updatedExpected.Spec.TimeIntervals = v0alpha1.IntervalGenerator{}.GenerateMany(2) + updatedExpected := expected.Copy().(*v0alpha1.TimeInterval) + updatedExpected.Spec.TimeIntervals = fakes.IntervalGenerator{}.GenerateMany(2) d, err = json.Marshal(updatedExpected) require.NoError(t, err) @@ -294,7 +288,7 @@ func TestIntegrationTimeIntervalAccessControl(t *testing.T) { expected = updated t.Run("should get NotFound if name does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.TimeInterval) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsNotFound(err), "Should get NotFound error but got: %s", err) @@ -306,7 +300,7 @@ func TestIntegrationTimeIntervalAccessControl(t *testing.T) { require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) t.Run("should get forbidden even if resource does not exist", func(t *testing.T) { - up := updatedExpected.DeepCopy() + up := updatedExpected.Copy().(*v0alpha1.TimeInterval) up.Name = "notFound" _, err := client.Update(ctx, up, v1.UpdateOptions{}) require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) @@ -361,9 +355,7 @@ func TestIntegrationTimeIntervalProvisioning(t *testing.T) { org := helper.Org1 admin := org.Admin - adminK8sClient, err := versioned.NewForConfig(admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) env := helper.GetEnv() ac := acimpl.ProvideAccessControl(env.FeatureToggles, zanzana.NewNoopClient()) @@ -374,9 +366,9 @@ func TestIntegrationTimeIntervalProvisioning(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "time-interval-1", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, }, v1.CreateOptions{}) require.NoError(t, err) @@ -394,8 +386,8 @@ func TestIntegrationTimeIntervalProvisioning(t *testing.T) { require.Equal(t, "API", got.GetProvenanceStatus()) }) t.Run("should not let update if provisioned", func(t *testing.T) { - updated := created.DeepCopy() - updated.Spec.TimeIntervals = v0alpha1.IntervalGenerator{}.GenerateMany(2) + updated := created.Copy().(*v0alpha1.TimeInterval) + updated.Spec.TimeIntervals = fakes.IntervalGenerator{}.GenerateMany(2) _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.Truef(t, errors.IsForbidden(err), "should get Forbidden error but got %s", err) @@ -415,17 +407,15 @@ func TestIntegrationTimeIntervalOptimisticConcurrency(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) interval := v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "time-interval", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } @@ -435,23 +425,23 @@ func TestIntegrationTimeIntervalOptimisticConcurrency(t *testing.T) { require.NotEmpty(t, created.ResourceVersion) t.Run("should forbid if version does not match", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TimeInterval) updated.ResourceVersion = "test" _, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.Truef(t, errors.IsConflict(err), "should get Forbidden error but got %s", err) }) t.Run("should update if version matches", func(t *testing.T) { - updated := created.DeepCopy() - updated.Spec.TimeIntervals = v0alpha1.IntervalGenerator{}.GenerateMany(2) + updated := created.Copy().(*v0alpha1.TimeInterval) + updated.Spec.TimeIntervals = fakes.IntervalGenerator{}.GenerateMany(2) actualUpdated, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) require.EqualValues(t, updated.Spec, actualUpdated.Spec) require.NotEqual(t, updated.ResourceVersion, actualUpdated.ResourceVersion) }) t.Run("should update if version is empty", func(t *testing.T) { - updated := created.DeepCopy() + updated := created.Copy().(*v0alpha1.TimeInterval) updated.ResourceVersion = "" - updated.Spec.TimeIntervals = v0alpha1.IntervalGenerator{}.GenerateMany(2) + updated.Spec.TimeIntervals = fakes.IntervalGenerator{}.GenerateMany(2) actualUpdated, err := adminClient.Update(ctx, updated, v1.UpdateOptions{}) require.NoError(t, err) @@ -501,17 +491,15 @@ func TestIntegrationTimeIntervalPatch(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) interval := v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "time-interval", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } @@ -534,7 +522,7 @@ func TestIntegrationTimeIntervalPatch(t *testing.T) { }) t.Run("should patch with json patch", func(t *testing.T) { - expected := v0alpha1.IntervalGenerator{}.Generate() + expected := fakes.IntervalGenerator{}.Generate() patch := []map[string]interface{}{ { @@ -549,9 +537,11 @@ func TestIntegrationTimeIntervalPatch(t *testing.T) { result, err := adminClient.Patch(ctx, current.Name, types.JSONPatchType, patchData, v1.PatchOptions{}) require.NoError(t, err) - expectedSpec := *current.Spec.DeepCopy() - expectedSpec.TimeIntervals = []v0alpha1.Interval{ - expected, + expectedSpec := v0alpha1.Spec{ + Name: current.Spec.Name, + TimeIntervals: []v0alpha1.Interval{ + expected, + }, } require.EqualValues(t, expectedSpec, result.Spec) current = result @@ -566,29 +556,27 @@ func TestIntegrationTimeIntervalListSelector(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) interval1 := &v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "test1", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } - interval1, err = adminClient.Create(ctx, interval1, v1.CreateOptions{}) + interval1, err := adminClient.Create(ctx, interval1, v1.CreateOptions{}) require.NoError(t, err) interval2 := &v0alpha1.TimeInterval{ ObjectMeta: v1.ObjectMeta{ Namespace: "default", }, - Spec: v0alpha1.TimeIntervalSpec{ + Spec: v0alpha1.Spec{ Name: "test2", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(2), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(2), }, } interval2, err = adminClient.Create(ctx, interval2, v1.CreateOptions{}) @@ -630,7 +618,7 @@ func TestIntegrationTimeIntervalListSelector(t *testing.T) { t.Run("should filter by multiple filters", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", interval2.Name, "API"), + FieldSelector: fmt.Sprintf("metadata.name=%s,spec.name=%s", interval2.Name, interval2.Spec.Name), }) require.NoError(t, err) require.Len(t, list.Items, 1) @@ -639,7 +627,7 @@ func TestIntegrationTimeIntervalListSelector(t *testing.T) { t.Run("should be empty when filter does not match", func(t *testing.T) { list, err := adminClient.List(ctx, v1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s,metadata.provenance=%s", interval2.Name, "unknown"), + FieldSelector: fmt.Sprintf("metadata.name=%s", "unknown"), }) require.NoError(t, err) require.Empty(t, list.Items) @@ -684,9 +672,7 @@ func TestIntegrationTimeIntervalReferentialIntegrity(t *testing.T) { currentRoute := legacyCli.GetRoute(t) currentRuleGroup := legacyCli.GetRulesGroup(t, folderUID, ruleGroup.Name) - adminK8sClient, err := versioned.NewForConfig(cliCfg) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) intervals, err := adminClient.List(ctx, v1.ListOptions{}) require.NoError(t, err) @@ -710,7 +696,7 @@ func TestIntegrationTimeIntervalReferentialIntegrity(t *testing.T) { t.Run("Update", func(t *testing.T) { t.Run("should rename all references if name changes", func(t *testing.T) { - renamed := interval.DeepCopy() + renamed := interval.Copy().(*v0alpha1.TimeInterval) renamed.Spec.Name += "-new" actual, err := adminClient.Update(ctx, renamed, v1.UpdateOptions{}) @@ -734,7 +720,7 @@ func TestIntegrationTimeIntervalReferentialIntegrity(t *testing.T) { t.Run("should fail if at least one resource is provisioned", func(t *testing.T) { require.NoError(t, err) - renamed := interval.DeepCopy() + renamed := interval.Copy().(*v0alpha1.TimeInterval) renamed.Spec.Name += util.GenerateShortUID() t.Run("provisioned route", func(t *testing.T) { @@ -787,24 +773,22 @@ func TestIntegrationTimeIntervalValidation(t *testing.T) { ctx := context.Background() helper := getTestHelper(t) - adminK8sClient, err := versioned.NewForConfig(helper.Org1.Admin.NewRestConfig()) - require.NoError(t, err) - adminClient := adminK8sClient.NotificationsV0alpha1().TimeIntervals("default") + adminClient := newClient(t, helper.Org1.Admin) testCases := []struct { name string - interval v0alpha1.TimeIntervalSpec + interval v0alpha1.Spec }{ { name: "missing name", - interval: v0alpha1.TimeIntervalSpec{ + interval: v0alpha1.Spec{ Name: "", - TimeIntervals: v0alpha1.IntervalGenerator{}.GenerateMany(1), + TimeIntervals: fakes.IntervalGenerator{}.GenerateMany(1), }, }, { name: "invalid interval", - interval: v0alpha1.TimeIntervalSpec{ + interval: v0alpha1.Spec{ Name: "test", TimeIntervals: []v0alpha1.Interval{ { @@ -823,9 +807,25 @@ func TestIntegrationTimeIntervalValidation(t *testing.T) { }, Spec: tc.interval, } - _, err = adminClient.Create(ctx, i, v1.CreateOptions{}) + _, err := adminClient.Create(ctx, i, v1.CreateOptions{}) require.Error(t, err) require.Truef(t, errors.IsBadRequest(err), "Expected BadRequest, got: %s", err) }) } } + +func newClient(t *testing.T, user apis.User) *apis.TypedClient[v0alpha1.TimeInterval, v0alpha1.TimeIntervalList] { + t.Helper() + + client, err := dynamic.NewForConfig(user.NewRestConfig()) + require.NoError(t, err) + + return &apis.TypedClient[v0alpha1.TimeInterval, v0alpha1.TimeIntervalList]{ + Client: client.Resource( + schema.GroupVersionResource{ + Group: v0alpha1.Kind().Group(), + Version: v0alpha1.Kind().Version(), + Resource: v0alpha1.Kind().Plural(), + }).Namespace("default"), + } +} diff --git a/pkg/tests/apis/helper.go b/pkg/tests/apis/helper.go index 14681edda54..dd4c8e8c03c 100644 --- a/pkg/tests/apis/helper.go +++ b/pkg/tests/apis/helper.go @@ -19,6 +19,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/yaml" + "k8s.io/apimachinery/pkg/types" yamlutil "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" @@ -645,3 +646,87 @@ func (c *K8sTestHelper) CreateTeam(name, email string, orgID int64) team.Team { require.NoError(c.t, err) return team } + +// TypedClient is the struct that implements a typed interface for resource operations +type TypedClient[T any, L any] struct { + Client dynamic.ResourceInterface +} + +func (c *TypedClient[T, L]) Create(ctx context.Context, resource *T, opts metav1.CreateOptions) (*T, error) { + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(resource) + if err != nil { + return nil, err + } + u := &unstructured.Unstructured{Object: unstructuredObj} + result, err := c.Client.Create(ctx, u, opts) + if err != nil { + return nil, err + } + createdObj := new(T) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.Object, createdObj) + if err != nil { + return nil, err + } + return createdObj, nil +} + +func (c *TypedClient[T, L]) Update(ctx context.Context, resource *T, opts metav1.UpdateOptions) (*T, error) { + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(resource) + if err != nil { + return nil, err + } + u := &unstructured.Unstructured{Object: unstructuredObj} + result, err := c.Client.Update(ctx, u, opts) + if err != nil { + return nil, err + } + updatedObj := new(T) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.Object, updatedObj) + if err != nil { + return nil, err + } + return updatedObj, nil +} + +func (c *TypedClient[T, L]) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.Client.Delete(ctx, name, opts) +} + +func (c *TypedClient[T, L]) Get(ctx context.Context, name string, opts metav1.GetOptions) (*T, error) { + result, err := c.Client.Get(ctx, name, opts) + if err != nil { + return nil, err + } + retrievedObj := new(T) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.Object, retrievedObj) + if err != nil { + return nil, err + } + return retrievedObj, nil +} + +func (c *TypedClient[T, L]) List(ctx context.Context, opts metav1.ListOptions) (*L, error) { + result, err := c.Client.List(ctx, opts) + if err != nil { + return nil, err + } + listObj := new(L) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.UnstructuredContent(), listObj) + if err != nil { + return nil, err + } + return listObj, nil +} + +func (c *TypedClient[T, L]) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*T, error) { + result, err := c.Client.Patch(ctx, name, pt, data, opts, subresources...) + if err != nil { + return nil, err + } + patchedObj := new(T) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.Object, patchedObj) + if err != nil { + return nil, err + } + return patchedObj, nil +} diff --git a/public/app/features/alerting/unified/components/contact-points/useContactPoints.ts b/public/app/features/alerting/unified/components/contact-points/useContactPoints.ts index 643af7401f8..a052f34013e 100644 --- a/public/app/features/alerting/unified/components/contact-points/useContactPoints.ts +++ b/public/app/features/alerting/unified/components/contact-points/useContactPoints.ts @@ -88,7 +88,7 @@ type K8sReceiver = ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Re const parseK8sReceiver = (item: K8sReceiver): GrafanaManagedContactPoint => { return { - id: item.metadata.uid || item.spec.title, + id: item.metadata.name || item.metadata.uid || item.spec.title, name: item.spec.title, provisioned: isK8sEntityProvisioned(item), grafana_managed_receiver_configs: item.spec.integrations,