Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common Fields for V2 Types #2493

Merged
merged 7 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/common-fields-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Introduce common fields to the v2 types that can be reused for any CRDs.
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved

# One or more tracking issues related to the change
issues: [901]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
159 changes: 159 additions & 0 deletions apis/v1alpha2/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright The OpenTelemetry Authors
//
// 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 v1alpha2

import (
v1 "k8s.io/api/core/v1"

"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)

type OpenTelemetryCommonFields struct {
// ManagementState defines if the CR should be managed by the operator or not.
// Default is managed.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:default:=managed
ManagementState v1alpha1.ManagementStateType `json:"managementState,omitempty"`
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
// Resources to set on generated pods.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// NodeSelector to schedule generated pods.
// This only works with the following OpenTelemetryCollector mode's: daemonset, statefulset, and deployment.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Args is the set of arguments to pass to the main container's binary.
// +optional
Args map[string]string `json:"args,omitempty"`
// Replicas is the number of pod instances for the underlying replicaset. Set this if you are not using autoscaling.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Autoscaler specifies the pod autoscaling configuration to use
// for the workload.
// +optional
Autoscaler *v1alpha1.AutoscalerSpec `json:"autoscaler,omitempty"`
// PodDisruptionBudget specifies the pod disruption budget configuration to use
// for the generated workload.
// +optional
PodDisruptionBudget *v1alpha1.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
// SecurityContext configures the container security context for
// the generated main container.
//
// In deployment, daemonset, or statefulset mode, this controls
// the security context settings for the primary application
// container.
//
// In sidecar mode, this controls the security context for the
// injected sidecar container.
//
// +optional
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext configures the pod security context for the
// generated pod, when running as a deployment, daemonset,
// or statefulset.
//
// In sidecar mode, the opentelemetry-operator will ignore this setting.
//
// +optional
PodSecurityContext *v1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// PodAnnotations is the set of annotations that will be attached to
// the generated pods.
// +optional
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
// the operator will not automatically create a ServiceAccount.
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`
// Image indicates the container image to use for the generated pods.
// +optional
Image string `json:"image,omitempty"`
// ImagePullPolicy indicates the pull policy to be used for retrieving the container image.
// +optional
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
// VolumeMounts represents the mount points to use in the underlying deployment(s).
// +optional
// +listType=atomic
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
// Ports allows a set of ports to be exposed by the underlying v1.Service. By default, the operator
// will attempt to infer the required ports by parsing the .Spec.Config property but this property can be
// used to open additional ports that can't be inferred by the operator, like for custom receivers.
// +optional
// +listType=atomic
Ports []v1.ServicePort `json:"ports,omitempty"`
// Environment variables to set on the generated pods.
// +optional
Env []v1.EnvVar `json:"env,omitempty"`
// List of sources to populate environment variables on the generated pods.
// +optional
EnvFrom []v1.EnvFromSource `json:"envFrom,omitempty"`
// VolumeClaimTemplates will provide stable storage using PersistentVolumes.
// This only works with the following OpenTelemetryCollector mode's: statefulset.
// +optional
// +listType=atomic
VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
// Toleration to schedule the generated pods.
// This only works with the following OpenTelemetryCollector mode's: daemonset, statefulset, and deployment.
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// Volumes represents which volumes to use in the underlying deployment(s).
// +optional
// +listType=atomic
Volumes []v1.Volume `json:"volumes,omitempty"`
// If specified, indicates the pod's scheduling constraints
// +optional
Affinity *v1.Affinity `json:"affinity,omitempty"`
// Actions that the management system should take in response to container lifecycle events. Cannot be updated.
// +optional
Lifecycle *v1.Lifecycle `json:"lifecycle,omitempty"`
// Duration in seconds the pod needs to terminate gracefully upon probe failure.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
// TopologySpreadConstraints embedded kubernetes pod configuration option,
// controls how pods are spread across your cluster among failure-domains
// such as regions, zones, nodes, and other user-defined topology domains
// https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
// This only works with the following OpenTelemetryCollector mode's: statefulset, and deployment.
// +optional
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
// If specified, indicates the pod's priority.
// If not specified, the pod priority will be default or zero if there is no
// default.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
// InitContainers allows injecting initContainers to the generated pod definition.
// These init containers can be used to fetch secrets for injection into the
// configuration from external sources, run added checks, etc. Any errors during the execution of
// an initContainer will lead to a restart of the Pod. More info:
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
// +optional
InitContainers []v1.Container `json:"initContainers,omitempty"`
// AdditionalContainers allows injecting additional containers into the generated pod definition.
// These sidecar containers can be used for authentication proxies, log shipping sidecars, agents for shipping
// metrics to their cloud, or in general sidecars that do not support automatic injection.
// This only works with the following OpenTelemetryCollector mode's: daemonset, statefulset, and deployment.
//
// Container names managed by the operator:
// * `otc-container`
//
// Overriding containers managed by the operator is outside the scope of what the maintainers will support and by
// doing so, you wil accept the risk of it breaking things.
//
// +optional
AdditionalContainers []v1.Container `json:"additionalContainers,omitempty"`
}
147 changes: 2 additions & 145 deletions apis/v1alpha2/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,173 +17,38 @@
package v1alpha2

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

"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)

// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
type OpenTelemetryCollectorSpec struct {
// ManagementState defines if the CR should be managed by the operator or not.
// Default is managed.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:default:=managed
ManagementState v1alpha1.ManagementStateType `json:"managementState,omitempty"`
// Resources to set on the OpenTelemetry Collector pods.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// NodeSelector to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Args is the set of arguments to pass to the OpenTelemetry Collector binary
// +optional
Args map[string]string `json:"args,omitempty"`
// Replicas is the number of pod instances for the underlying OpenTelemetry Collector. Set this if your are not using autoscaling
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Autoscaler specifies the pod autoscaling configuration to use
// for the OpenTelemetryCollector workload.
//
// +optional
Autoscaler *v1alpha1.AutoscalerSpec `json:"autoscaler,omitempty"`
// PodDisruptionBudget specifies the pod disruption budget configuration to use
// for the OpenTelemetryCollector workload.
//
// +optional
PodDisruptionBudget *v1alpha1.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
// SecurityContext configures the container security context for
// the opentelemetry-collector container.
//
// In deployment, daemonset, or statefulset mode, this controls
// the security context settings for the primary application
// container.
//
// In sidecar mode, this controls the security context for the
// injected sidecar container.
//
// +optional
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext configures the pod security context for the
// opentelemetry-collector pod, when running as a deployment, daemonset,
// or statefulset.
//
// In sidecar mode, the opentelemetry-operator will ignore this setting.
//
// +optional
PodSecurityContext *v1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// PodAnnotations is the set of annotations that will be attached to
// Collector and Target Allocator pods.
// +optional
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// Common defines fields that are common to all OpenTelemetry CRD workloads.
Common OpenTelemetryCommonFields `json:",inline"`
// TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not.
// +optional
TargetAllocator v1alpha1.OpenTelemetryTargetAllocator `json:"targetAllocator,omitempty"`
// Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)
// +optional
Mode v1alpha1.Mode `json:"mode,omitempty"`
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
// the operator will not automatically create a ServiceAccount for the collector.
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`
// Image indicates the container image to use for the OpenTelemetry Collector.
// +optional
Image string `json:"image,omitempty"`
// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
// +optional
UpgradeStrategy v1alpha1.UpgradeStrategy `json:"upgradeStrategy"`

// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
// +optional
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
// The empty objects e.g. batch: should be written as batch: {} otherwise they won't work with kustomize or kubectl edit.
// +required
// +kubebuilder:pruning:PreserveUnknownFields
Config Config `json:"config"`

// VolumeMounts represents the mount points to use in the underlying collector deployment(s)
// +optional
// +listType=atomic
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
// Ports allows a set of ports to be exposed by the underlying v1.Service. By default, the operator
// will attempt to infer the required ports by parsing the .Spec.Config property but this property can be
// used to open additional ports that can't be inferred by the operator, like for custom receivers.
// +optional
// +listType=atomic
Ports []v1.ServicePort `json:"ports,omitempty"`
// ENV vars to set on the OpenTelemetry Collector's Pods. These can then in certain cases be
// consumed in the config file for the Collector.
// +optional
Env []v1.EnvVar `json:"env,omitempty"`
// List of sources to populate environment variables on the OpenTelemetry Collector's Pods.
// These can then in certain cases be consumed in the config file for the Collector.
// +optional
EnvFrom []v1.EnvFromSource `json:"envFrom,omitempty"`
// VolumeClaimTemplates will provide stable storage using PersistentVolumes. Only available when the mode=statefulset.
// +optional
// +listType=atomic
VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
// Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// Volumes represents which volumes to use in the underlying collector deployment(s).
// +optional
// +listType=atomic
Volumes []v1.Volume `json:"volumes,omitempty"`
// Ingress is used to specify how OpenTelemetry Collector is exposed. This
// functionality is only available if one of the valid modes is set.
// Valid modes are: deployment, daemonset and statefulset.
// +optional
Ingress v1alpha1.Ingress `json:"ingress,omitempty"`
// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
// If specified, indicates the pod's priority.
// If not specified, the pod priority will be default or zero if there is no
// default.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
// If specified, indicates the pod's scheduling constraints
// +optional
Affinity *v1.Affinity `json:"affinity,omitempty"`
// Actions that the management system should take in response to container lifecycle events. Cannot be updated.
// +optional
Lifecycle *v1.Lifecycle `json:"lifecycle,omitempty"`
// Duration in seconds the pod needs to terminate gracefully upon probe failure.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
// Liveness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector.
// It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
// +optional
LivenessProbe *v1alpha1.Probe `json:"livenessProbe,omitempty"`
// InitContainers allows injecting initContainers to the Collector's pod definition.
// These init containers can be used to fetch secrets for injection into the
// configuration from external sources, run added checks, etc. Any errors during the execution of
// an initContainer will lead to a restart of the Pod. More info:
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
// +optional
InitContainers []v1.Container `json:"initContainers,omitempty"`

// AdditionalContainers allows injecting additional containers into the Collector's pod definition.
// These sidecar containers can be used for authentication proxies, log shipping sidecars, agents for shipping
// metrics to their cloud, or in general sidecars that do not support automatic injection. This option only
// applies to Deployment, DaemonSet, and StatefulSet deployment modes of the collector. It does not apply to the sidecar
// deployment mode. More info about sidecars:
// https://kubernetes.io/docs/tasks/configure-pod-container/share-process-namespace/
//
// Container names managed by the operator:
// * `otc-container`
//
// Overriding containers managed by the operator is outside the scope of what the maintainers will support and by
// doing so, you wil accept the risk of it breaking things.
//
// +optional
AdditionalContainers []v1.Container `json:"additionalContainers,omitempty"`

// ObservabilitySpec defines how telemetry data gets handled.
//
Expand All @@ -192,14 +57,6 @@ type OpenTelemetryCollectorSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability"
Observability v1alpha1.ObservabilitySpec `json:"observability,omitempty"`

// TopologySpreadConstraints embedded kubernetes pod configuration option,
// controls how pods are spread across your cluster among failure-domains
// such as regions, zones, nodes, and other user-defined topology domains
// https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
// This is only relevant to statefulset, and deployment mode
// +optional
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`

// ConfigMaps is a list of ConfigMaps in the same namespace as the OpenTelemetryCollector
// object, which shall be mounted into the Collector Pods.
// Each ConfigMap will be added to the Collector's Deployments as a volume named `configmap-<configmap-name>`.
Expand Down
Loading
Loading