Skip to content

Commit

Permalink
add pod annotations and labels
Browse files Browse the repository at this point in the history
Problem: to use the ORAS operator with the metrics operator we need annotations
Solution: expose annotations and labels in the spec
Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Nov 3, 2023
1 parent 42151c1 commit 6f235cc
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 4 deletions.
18 changes: 17 additions & 1 deletion api/v1alpha2/metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ type Logging struct {
// Pod attributes that can be given to an application or metric
type Pod struct {

// Annotations to add to the pod
//+optional
Annotations map[string]string `json:"annotations"`

// Labels to add to the pod
//+optional
Labels map[string]string `json:"labels"`

// name of service account to associate with pod
//+optional
ServiceAccountName string `json:"serviceAccountName"`
Expand Down Expand Up @@ -205,7 +213,9 @@ type Metric struct {
// Get pod labels for a metric set
func (m *MetricSet) GetPodLabels() map[string]string {

podLabels := map[string]string{}
// Start with those provided by the user
podLabels := m.Spec.Pod.Labels

// This is for autoscaling, although haven't used yet
podLabels["cluster-name"] = m.Name
// This is for the headless service
Expand Down Expand Up @@ -233,6 +243,12 @@ type MetricSet struct {
// Validate a requested metricset
func (m *MetricSet) Validate() bool {

if m.Spec.Pod.Labels == nil {
m.Spec.Pod.Labels = map[string]string{}
}
if m.Spec.Pod.Annotations == nil {
m.Spec.Pod.Annotations = map[string]string{}
}
if len(m.Spec.Metrics) == 0 {
fmt.Printf("😥️ One or more metrics are required.\n")
return false
Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions config/crd/bases/flux-framework.org_metricsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ spec:
description: Pod spec for the application, standalone, or storage
metrics
properties:
annotations:
additionalProperties:
type: string
description: Annotations to add to the pod
type: object
labels:
additionalProperties:
type: string
description: Labels to add to the pod
type: object
nodeSelector:
additionalProperties:
type: string
Expand Down
18 changes: 18 additions & 0 deletions docs/getting_started/custom-resource-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,21 @@ metrics:

Each addon has its own custom options. You can look at examples and at our [addons documentation](addons.md) for more detail on how to add existing volumes
or other custom functionality.


### pod

You can customize variables for the pod, which currently includes labels, annotations, selectors, and a service account name,

```yaml
spec:
pod:
annotations:
key.subkey: value
labels:
dinner: lasagna
serviceAccountName: mySVCAccount
nodeSelector:
key: value
```

10 changes: 10 additions & 0 deletions examples/dist/metrics-operator-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ spec:
pod:
description: Pod spec for the application, standalone, or storage metrics
properties:
annotations:
additionalProperties:
type: string
description: Annotations to add to the pod
type: object
labels:
additionalProperties:
type: string
description: Labels to add to the pod
type: object
nodeSelector:
additionalProperties:
type: string
Expand Down
10 changes: 10 additions & 0 deletions examples/dist/metrics-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ spec:
pod:
description: Pod spec for the application, standalone, or storage metrics
properties:
annotations:
additionalProperties:
type: string
description: Annotations to add to the pod
type: object
labels:
additionalProperties:
type: string
description: Labels to add to the pod
type: object
nodeSelector:
additionalProperties:
type: string
Expand Down
7 changes: 4 additions & 3 deletions pkg/metrics/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ func AssembleReplicatedJob(
// Note there is parameter to limit runtime
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: set.Name,
Namespace: set.Namespace,
Labels: podLabels,
Name: set.Name,
Namespace: set.Namespace,
Labels: podLabels,
Annotations: set.Spec.Pod.Annotations,
},
Spec: corev1.PodSpec{
// matches the service
Expand Down

0 comments on commit 6f235cc

Please sign in to comment.