Skip to content

Commit

Permalink
Add reconciliation for Collector v1beta1 CRD (#2703)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay authored Mar 14, 2024
1 parent 403783c commit 1741863
Show file tree
Hide file tree
Showing 64 changed files with 31,341 additions and 16,266 deletions.
25 changes: 25 additions & 0 deletions .chloggen/v1beta1-webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Enable reconciliation of Collector v1beta1 CRD.

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

# (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: |
Users are expected to migrate to `otelcol.v1beta1.opentelemetry.io`.
The support for `otelcol.v1alpha1.opentelemetry.io` will be removed in the future.
Follow [migration guide](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#upgrade-existing-objects-to-a-new-stored-version) for upgrading already created collector instances.
After all `otelcol.v1alpha1.opentelemetry.io` are stored as `v1beta1` update the collector CRD to store only `v1beta1`
`kubectl patch customresourcedefinitions opentelemetrycollectors.opentelemetry.io --subresource='status' --type='merge' -p '{"status":{"storedVersions":["v1beta1"]}}'`.
**Only `AllNamespaces` install mode is now supported** due to the conversion webhook from `v1beta1` to `v1alpha1`.
See [OLM docs](https://olm.operatorframework.io/docs/tasks/install-operator-with-olm/) and
[OLM operator groups docs](https://olm.operatorframework.io/docs/advanced-tasks/operator-scoping-with-operatorgroups/).
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true,maxDescLen=200"
# kubectl apply does not work on large CRDs.
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true,maxDescLen=0"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func warningsGroupedByResource(reviews []*v1.SubjectAccessReview) []string {
func SetupCollectorWebhook(mgr ctrl.Manager, cfg config.Config, reviewer *rbac.Reviewer) error {
cvw := &CollectorWebhook{
reviewer: reviewer,
logger: mgr.GetLogger().WithValues("handler", "CollectorWebhook"),
logger: mgr.GetLogger().WithValues("handler", "CollectorWebhook", "version", "v1alpha1"),
scheme: mgr.GetScheme(),
cfg: cfg,
}
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ type OpenTelemetryCollectorStatus struct {
Replicas int32 `json:"replicas,omitempty"`
}

// +kubebuilder:deprecatedversion:warning="OpenTelemetryCollector v1alpha1 is deprecated. Migrate to v1beta1."
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=otelcol;otelcols
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.scale.replicas,selectorpath=.status.scale.selector
Expand Down
27 changes: 27 additions & 0 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,30 @@ import (
"fmt"
"strings"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
)

var (
_ admission.CustomValidator = &CollectorWebhook{}
_ admission.CustomDefaulter = &CollectorWebhook{}
)

// +kubebuilder:webhook:path=/mutate-opentelemetry-io-v1beta1-opentelemetrycollector,mutating=true,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,verbs=create;update,versions=v1beta1,name=mopentelemetrycollectorbeta.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1beta1-opentelemetrycollector,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1beta1,name=vopentelemetrycollectorcreateupdatebeta.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=delete,path=/validate-opentelemetry-io-v1beta1-opentelemetrycollector,mutating=false,failurePolicy=ignore,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1beta1,name=vopentelemetrycollectordeletebeta.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:object:generate=false

type CollectorWebhook struct {
logger logr.Logger
cfg config.Config
scheme *runtime.Scheme
reviewer *rbac.Reviewer
}

func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
Expand Down Expand Up @@ -77,3 +90,17 @@ func (c CollectorWebhook) validate(r *OpenTelemetryCollector) (admission.Warning
}
return warnings, nil
}

func SetupCollectorWebhook(mgr ctrl.Manager, cfg config.Config, reviewer *rbac.Reviewer) error {
cvw := &CollectorWebhook{
reviewer: reviewer,
logger: mgr.GetLogger().WithValues("handler", "CollectorWebhook", "version", "v1beta1"),
scheme: mgr.GetScheme(),
cfg: cfg,
}
return ctrl.NewWebhookManagedBy(mgr).
For(&OpenTelemetryCollector{}).
WithValidator(cvw).
WithDefaulter(cvw).
Complete()
}
3 changes: 1 addition & 2 deletions apis/v1beta1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +kubebuilder:skip

package v1beta1

import (
Expand All @@ -28,6 +26,7 @@ func init() {

// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=otelcol;otelcols
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.scale.replicas,selectorpath=.status.scale.selector
// +kubebuilder:printcolumn:name="Mode",type="string",JSONPath=".spec.mode",description="Deployment Mode"
Expand Down
2 changes: 0 additions & 2 deletions apis/v1beta1/targetallocator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +kubebuilder:skip

package v1beta1

import (
Expand Down
161 changes: 158 additions & 3 deletions bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,47 @@ metadata:
"spec": {
"config": "receivers:\n otlp:\n protocols: \n grpc:\n http:\n\nexporters:\n debug:\n\nservice:\n pipelines:\n traces:\n receivers: [otlp]\n exporters: [debug]\n"
}
},
{
"apiVersion": "opentelemetry.io/v1beta1",
"kind": "OpenTelemetryCollector",
"metadata": {
"name": "otel"
},
"spec": {
"config": {
"exporters": {
"debug": {}
},
"receivers": {
"otlp": {
"protocols": {
"grpc": {},
"http": {}
}
}
},
"service": {
"pipelines": {
"traces": {
"exporters": [
"debug"
],
"receivers": [
"otlp"
]
}
}
}
}
}
}
]
capabilities: Deep Insights
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-03-08T17:10:13Z"
createdAt: "2024-03-11T13:32:19Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -154,6 +188,56 @@ spec:
displayName: Create ServiceMonitors for OpenTelemetry Collector
path: targetAllocator.observability.metrics.enableMetrics
version: v1alpha1
- description: OpenTelemetryCollector is the Schema for the opentelemetrycollectors
API.
displayName: OpenTelemetry Collector
kind: OpenTelemetryCollector
name: opentelemetrycollectors.opentelemetry.io
resources:
- kind: ConfigMaps
name: ""
version: v1
- kind: DaemonSets
name: ""
version: apps/v1
- kind: Deployment
name: ""
version: apps/v1
- kind: Pod
name: ""
version: v1
- kind: Service
name: ""
version: v1
- kind: StatefulSets
name: ""
version: apps/v1
specDescriptors:
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: observability
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: observability.metrics
- description: EnableMetrics specifies if ServiceMonitor or PodMonitor(for sidecar
mode) should be created for the service managed by the OpenTelemetry Operator.
The operator.observability.prometheus feature gate must be enabled to use
this feature.
displayName: Create ServiceMonitors for OpenTelemetry Collector
path: observability.metrics.enableMetrics
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: targetAllocator.observability
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: targetAllocator.observability.metrics
- description: EnableMetrics specifies if ServiceMonitor or PodMonitor(for sidecar
mode) should be created for the service managed by the OpenTelemetry Operator.
The operator.observability.prometheus feature gate must be enabled to use
this feature.
displayName: Create ServiceMonitors for OpenTelemetry Collector
path: targetAllocator.observability.metrics.enableMetrics
version: v1beta1
description: |-
OpenTelemetry is a collection of tools, APIs, and SDKs. You use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.
Expand Down Expand Up @@ -487,9 +571,9 @@ spec:
serviceAccountName: opentelemetry-operator-controller-manager
strategy: deployment
installModes:
- supported: true
- supported: false
type: OwnNamespace
- supported: true
- supported: false
type: SingleNamespace
- supported: false
type: MultiNamespace
Expand All @@ -514,6 +598,18 @@ spec:
name: OpenTelemetry Community
version: 0.96.0
webhookdefinitions:
- admissionReviewVersions:
- v1alpha1
- v1beta1
containerPort: 443
conversionCRDs:
- opentelemetrycollectors.opentelemetry.io
deploymentName: opentelemetry-operator-controller-manager
generateName: copentelemetrycollectors.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
- admissionReviewVersions:
- v1
containerPort: 443
Expand Down Expand Up @@ -574,6 +670,26 @@ spec:
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector
- admissionReviewVersions:
- v1
containerPort: 443
deploymentName: opentelemetry-operator-controller-manager
failurePolicy: Fail
generateName: mopentelemetrycollectorbeta.kb.io
rules:
- apiGroups:
- opentelemetry.io
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- opentelemetrycollectors
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-opentelemetry-io-v1beta1-opentelemetrycollector
- admissionReviewVersions:
- v1
containerPort: 443
Expand Down Expand Up @@ -691,6 +807,26 @@ spec:
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector
- admissionReviewVersions:
- v1
containerPort: 443
deploymentName: opentelemetry-operator-controller-manager
failurePolicy: Fail
generateName: vopentelemetrycollectorcreateupdatebeta.kb.io
rules:
- apiGroups:
- opentelemetry.io
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- opentelemetrycollectors
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-opentelemetry-io-v1beta1-opentelemetrycollector
- admissionReviewVersions:
- v1
containerPort: 443
Expand All @@ -710,3 +846,22 @@ spec:
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector
- admissionReviewVersions:
- v1
containerPort: 443
deploymentName: opentelemetry-operator-controller-manager
failurePolicy: Ignore
generateName: vopentelemetrycollectordeletebeta.kb.io
rules:
- apiGroups:
- opentelemetry.io
apiVersions:
- v1beta1
operations:
- DELETE
resources:
- opentelemetrycollectors
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-opentelemetry-io-v1beta1-opentelemetrycollector
Loading

0 comments on commit 1741863

Please sign in to comment.