Skip to content

Commit

Permalink
feat(operator): introduce KeptnMetrics CRD and controller (#643)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com>
Co-authored-by: Moritz Wiesinger <moritz.wiesinger@dynatrace.com>
  • Loading branch information
odubajDT and mowies committed Jan 18, 2023
1 parent 2e47b92 commit 96170df
Show file tree
Hide file tree
Showing 19 changed files with 663 additions and 59 deletions.
9 changes: 9 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@ resources:
kind: KeptnEvaluation
path: github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2
version: v1alpha2
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: metrics
kind: KeptnMetric
path: github.com/keptn/lifecycle-toolkit/operator/apis/metrics/v1alpha1
version: v1alpha1
version: "3"
36 changes: 36 additions & 0 deletions operator/apis/metrics/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the metrics v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=metrics.keptn.sh
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "metrics.keptn.sh", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
78 changes: 78 additions & 0 deletions operator/apis/metrics/v1alpha1/keptnmetric_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// KeptnMetricSpec defines the desired state of KeptnMetric
type KeptnMetricSpec struct {
// Provider represents the provider object
Provider ProviderRef `json:"provider"`
// Query represents the query to be run
Query string `json:"query"`
// FetchIntervalSeconds represents the update frequency in seconds that is used to update the metric
FetchIntervalSeconds uint `json:"fetchIntervalSeconds"`
}

// KeptnMetricStatus defines the observed state of KeptnMetric
type KeptnMetricStatus struct {
// Value represents the resulting value
Value string `json:"value"`
// RawValue represents the resulting value in raw format
RawValue []byte `json:"rawValue"`
// LastUpdated represents the time when the status data was last updated
LastUpdated metav1.Time `json:"lastUpdated"`
}

// ProviderRef represents the provider object
type ProviderRef struct {
// Name of the provider
Name string `json:"name"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Provider",type=string,JSONPath=`.spec.provider.name`
//+kubebuilder:printcolumn:name="Query",type=string,JSONPath=`.spec.query`
//+kubebuilder:printcolumn:name="Value",type=string,JSONPath=`.status.value`

// KeptnMetric is the Schema for the keptnmetrics API
type KeptnMetric struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KeptnMetricSpec `json:"spec,omitempty"`
Status KeptnMetricStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// KeptnMetricList contains a list of KeptnMetric
type KeptnMetricList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KeptnMetric `json:"items"`
}

func init() {
SchemeBuilder.Register(&KeptnMetric{}, &KeptnMetricList{})
}
137 changes: 137 additions & 0 deletions operator/apis/metrics/v1alpha1/zz_generated.deepcopy.go

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

93 changes: 93 additions & 0 deletions operator/config/crd/bases/metrics.keptn.sh_keptnmetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnmetrics.metrics.keptn.sh
spec:
group: metrics.keptn.sh
names:
kind: KeptnMetric
listKind: KeptnMetricList
plural: keptnmetrics
singular: keptnmetric
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.source
name: Provider
type: string
- jsonPath: .spec.query
name: Query
type: string
- jsonPath: .status.value
name: Value
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: KeptnMetric is the Schema for the keptnmetrics API
properties:
apiVersion:
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
kind:
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
metadata:
type: object
spec:
description: KeptnMetricSpec defines the desired state of KeptnMetric
properties:
fetchIntervalSeconds:
description: FetchIntervalSeconds represents the update frequency
in seconds that is used to update the metric
type: integer
provider:
description: Provider represents the provider object
properties:
name:
description: Name of the provider
type: string
required:
- name
type: object
query:
description: Query represents the query to be run
type: string
required:
- fetchIntervalSeconds
- provider
- query
type: object
status:
description: KeptnMetricStatus defines the observed state of KeptnMetric
properties:
lastUpdated:
description: LastUpdated represents the time when the status data
was last updated
format: date-time
type: string
rawValue:
description: RawValue represents the resulting value in raw format
format: byte
type: string
value:
description: Value represents the resulting value
type: string
required:
- lastUpdated
- rawValue
- value
type: object
type: object
served: true
storage: true
subresources:
status: {}
2 changes: 2 additions & 0 deletions operator/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resources:
- bases/lifecycle.keptn.sh_keptnevaluationdefinitions.yaml
- bases/lifecycle.keptn.sh_keptnevaluationproviders.yaml
- bases/lifecycle.keptn.sh_keptnevaluations.yaml
- bases/metrics.keptn.sh_keptnmetrics.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -25,6 +26,7 @@ patchesStrategicMerge:
#- patches/webhook_in_keptnevaluationdefinitions.yaml
- patches/webhook_in_keptnevaluationproviders.yaml
#- patches/webhook_in_keptnevaluations.yaml
#- patches/webhook_in_keptnmetrics.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
1 change: 1 addition & 0 deletions operator/config/crd/patches/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Ignore autogen patch file for crds
cainjection_in_*.yaml
cainjection_in_*_*.yaml
Loading

0 comments on commit 96170df

Please sign in to comment.