Skip to content

Commit

Permalink
Revert "Revert" Add reconciliation for Collector v1beta1 CRD (#2703)"… (
Browse files Browse the repository at this point in the history
#2813)

* Revert "Revert" Add reconciliation for Collector v1beta1 CRD (#2703)" (#2800)"

This reverts commit 57024fc.

* Fix image

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

* Clarify hostport

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

* Fix issue after israel

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

* Fix

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>

---------

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay authored Apr 12, 2024
1 parent 13d80e9 commit 7e576c9
Show file tree
Hide file tree
Showing 66 changed files with 31,835 additions and 11,778 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, 1907]

# (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/).
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true,maxDescLen=200"
MANIFEST_DIR ?= config/crd/bases
# 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 Expand Up @@ -171,7 +173,7 @@ release-artifacts: set-image-controller
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=$(MANIFEST_DIR)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=${MANIFEST_DIR}

# Run tests
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
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
24 changes: 12 additions & 12 deletions apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ func tov1beta1Ports(in []PortsSpec) []v1beta1.PortsSpec {
for _, p := range in {
ports = append(ports, v1beta1.PortsSpec{
ServicePort: v1.ServicePort{
Name: p.Name,
Protocol: p.Protocol,
AppProtocol: p.AppProtocol,
Port: p.Port,
TargetPort: p.TargetPort,
NodePort: p.NodePort,
Name: p.ServicePort.Name,
Protocol: p.ServicePort.Protocol,
AppProtocol: p.ServicePort.AppProtocol,
Port: p.ServicePort.Port,
TargetPort: p.ServicePort.TargetPort,
NodePort: p.ServicePort.NodePort,
},
HostPort: p.HostPort,
})
Expand Down Expand Up @@ -276,12 +276,12 @@ func tov1alpha1Ports(in []v1beta1.PortsSpec) []PortsSpec {
for _, p := range in {
ports = append(ports, PortsSpec{
ServicePort: v1.ServicePort{
Name: p.Name,
Protocol: p.Protocol,
AppProtocol: p.AppProtocol,
Port: p.Port,
TargetPort: p.TargetPort,
NodePort: p.NodePort,
Name: p.ServicePort.Name,
Protocol: p.ServicePort.Protocol,
AppProtocol: p.ServicePort.AppProtocol,
Port: p.ServicePort.Port,
TargetPort: p.ServicePort.TargetPort,
NodePort: p.ServicePort.NodePort,
},
HostPort: p.HostPort,
})
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func Test_tov1beta1AndBack(t *testing.T) {
ServicePort: v1.ServicePort{
Name: "otlp",
},
HostPort: 0,
HostPort: 4317,
}},
Env: []v1.EnvVar{
{
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 @@ -448,8 +448,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
159 changes: 157 additions & 2 deletions bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ 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
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 @@ -496,9 +580,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 @@ -523,6 +607,18 @@ spec:
name: OpenTelemetry Community
version: 0.98.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 @@ -583,6 +679,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 @@ -700,6 +816,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 @@ -719,3 +855,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 7e576c9

Please sign in to comment.