Skip to content

Commit

Permalink
feat(openshift): Support extra labels/annotations for deployments and…
Browse files Browse the repository at this point in the history
… pods

Signed-off-by: Guillaume Doussin <[email protected]>
  • Loading branch information
OpenGuidou committed Sep 22, 2023
1 parent 17d7420 commit fe942bb
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 81 deletions.
15 changes: 15 additions & 0 deletions api/v1beta1/cryostat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ type CryostatSpec struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Credentials Database Options"
JmxCredentialsDatabaseOptions *JmxCredentialsDatabaseOptions `json:"jmxCredentialsDatabaseOptions,omitempty"`
// Options to configure the Cryostat resources metadata
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resources metadata"
Metadata *ResourceMetadata `json:"metadata,omitempty"`
}

type ResourceMetadata struct {
// Annotations to add to the resources during its creation.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// Labels to add to the resources during its creation.
// The labels with keys "app" and "component" are reserved
// for use by the operator.
// +optional
Labels map[string]string `json:"labels,omitempty"`
}

type ResourceConfigList struct {
Expand Down
34 changes: 34 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

31 changes: 26 additions & 5 deletions config/crd/bases/operator.cryostat.io_clustercryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ spec:
format: int32
minimum: 1
type: integer
metadata:
description: Options to configure the Cryostat resources metadata
properties:
annotations:
additionalProperties:
type: string
description: Annotations to add to the resources during its creation.
type: object
labels:
additionalProperties:
type: string
description: Labels to add to the resources during its creation.
The labels with keys "app" and "component" are reserved for
use by the operator.
type: object
type: object
minimal:
description: Deploy a pared-down Cryostat instance with no Grafana
Dashboard or JFR Data Source.
Expand Down Expand Up @@ -1097,7 +1113,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2472,7 +2489,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2519,7 +2537,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2566,7 +2585,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -4452,7 +4472,8 @@ spec:
defined in spec.resourceClaims, that are used by
this container. \n This is an alpha field and requires
enabling the DynamicResourceAllocation feature gate.
\n This field is immutable."
\n This field is immutable. It can only be set for
containers."
items:
description: ResourceClaim references one entry
in PodSpec.ResourceClaims.
Expand Down
31 changes: 26 additions & 5 deletions config/crd/bases/operator.cryostat.io_cryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ spec:
format: int32
minimum: 1
type: integer
metadata:
description: Options to configure the Cryostat resources metadata
properties:
annotations:
additionalProperties:
type: string
description: Annotations to add to the resources during its creation.
type: object
labels:
additionalProperties:
type: string
description: Labels to add to the resources during its creation.
The labels with keys "app" and "component" are reserved for
use by the operator.
type: object
type: object
minimal:
description: Deploy a pared-down Cryostat instance with no Grafana
Dashboard or JFR Data Source.
Expand Down Expand Up @@ -1093,7 +1109,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2468,7 +2485,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2515,7 +2533,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -2562,7 +2581,8 @@ spec:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
Expand Down Expand Up @@ -4448,7 +4468,8 @@ spec:
defined in spec.resourceClaims, that are used by
this container. \n This is an alpha field and requires
enabling the DynamicResourceAllocation feature gate.
\n This field is immutable."
\n This field is immutable. It can only be set for
containers."
items:
description: ResourceClaim references one entry
in PodSpec.ResourceClaims.
Expand Down
20 changes: 20 additions & 0 deletions internal/controllers/common/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -68,3 +69,22 @@ func ClusterUniqueName(kind string, name string, namespace string) string {
suffix := fmt.Sprintf("%x", sha256.Sum256([]byte(nn.String())))
return strings.ToLower(kind) + "-" + suffix
}

func MergeLabelsAndAnnotations(dest *metav1.ObjectMeta, srcLabels, srcAnnotations map[string]string) {
// Check and create labels/annotations map if absent
if dest.Labels == nil {
dest.Labels = map[string]string{}
}
if dest.Annotations == nil {
dest.Annotations = map[string]string{}
}

// Merge labels and annotations, preferring those in the source
for k, v := range srcLabels {
dest.Labels[k] = v
}

for k, v := range srcAnnotations {
dest.Annotations[k] = v
}
}
Loading

0 comments on commit fe942bb

Please sign in to comment.