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

internal/manifests/collector: switch internally to v1alpha2 #2532

Merged
merged 19 commits into from
Feb 5, 2024

Conversation

frzifus
Copy link
Member

@frzifus frzifus commented Jan 18, 2024

Description:

This PR replaces the internal dependency in internal/manifests/collector on v1alpha1 in the course of the migration to v1alpha2.

To convert the v1alpha1 CR fetched and passed from the controller it adds a internal/api/convert.v1alpha1to2() function to upgrade to v1alpha2.

The next step is to migrate opampbridge, targetallocator and manifests. It should then be possible to perform the final conversion from v1alpha1 to v1alpha2 and back in the reconcile loop.

Link to tracking Issue:

Testing:

Documentation:

@frzifus frzifus force-pushed the v1alphav2 branch 2 times, most recently from 4499392 to ffea150 Compare January 18, 2024 16:10
@frzifus frzifus added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jan 18, 2024
@frzifus frzifus force-pushed the v1alphav2 branch 2 times, most recently from 0eec778 to e5040f6 Compare January 18, 2024 16:58
@frzifus frzifus marked this pull request as ready for review January 18, 2024 17:00
@frzifus frzifus requested a review from a team January 18, 2024 17:00
@iblancasa
Copy link
Contributor

Could you add some description/link to the issue to explain what are you implementing here?

@frzifus
Copy link
Member Author

frzifus commented Jan 18, 2024

@iblancasa ive added a description. Does it make sense to you?

internal/manifests/collector/annotations.go Outdated Show resolved Hide resolved
pkg/sidecar/pod.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts, but it does feel like we're on a good path here!

internal/api/convert/v1alpha.go Outdated Show resolved Hide resolved
internal/api/convert/v1alpha.go Outdated Show resolved Hide resolved
Pods: m.Pods,
}
}
out.Spec.OpenTelemetryCommonFields.Autoscaler = &v1alpha2.AutoscalerSpec{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to worry about the deprecated min and max replica fields?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did say no. Since you are still able to set min/max in the AutoscalerSpec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since they are deprecated and this is a version bump... I would say this is the perfect moment to remove them

Copy link
Member Author

@frzifus frzifus Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep the change as minimal as possible. We can add/remove/change behavior afterwards.

internal/api/convert/v1alpha.go Outdated Show resolved Hide resolved
internal/api/convert/v1alpha.go Show resolved Hide resolved
internal/manifests/collector/container.go Outdated Show resolved Hide resolved
internal/manifests/collector/container.go Outdated Show resolved Hide resolved
internal/manifests/collector/daemonset.go Outdated Show resolved Hide resolved
internal/manifests/collector/rbac.go Outdated Show resolved Hide resolved
@frzifus frzifus force-pushed the v1alphav2 branch 4 times, most recently from 778c94d to ee38503 Compare January 23, 2024 14:16
internal/api/convert/v1alpha_test.go Outdated Show resolved Hide resolved
internal/api/convert/v1alpha_test.go Outdated Show resolved Hide resolved
internal/manifests/collector/rbac.go Outdated Show resolved Hide resolved
pkg/sidecar/pod.go Outdated Show resolved Hide resolved
@frzifus
Copy link
Member Author

frzifus commented Jan 23, 2024

Seems there are still some tests failing that compare strings.
e.g.:

- "collector.yaml": "receivers:\n  examplereceiver:\n    endpoint: \"0.0.0.0:12345\"\nexporters:\n  logging:\nservice:\n  pipelines:\n    metrics:\n      receivers: [examplereceiver]\n      exporters: [logging]\n",
+ "collector.yaml": "exporters:\n    logging: null\nreceivers:\n    prometheus:\n        config: {}\n        target_allocator:\n            collector_id: ${POD_NAME}\n            endpoint: http://test-targetallocator:80\n            interval: 30s\nservice:\n    pipelines:\n        metrics:\n            exporters:\n                - logging\n            receivers:\n                - prometheus\n",

Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM I would add require statements for returned error that was added to many manifest files

internal/manifests/collector/daemonset_test.go Outdated Show resolved Hide resolved
internal/manifests/collector/daemonset_test.go Outdated Show resolved Hide resolved
@frzifus
Copy link
Member Author

frzifus commented Jan 24, 2024

Well, now the formatting in the e2e tests seems to be slightly different. 🦝

internal/api/convert/v1alpha.go Show resolved Hide resolved
Pods: m.Pods,
}
}
out.Spec.OpenTelemetryCommonFields.Autoscaler = &v1alpha2.AutoscalerSpec{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since they are deprecated and this is a version bump... I would say this is the perfect moment to remove them

internal/api/convert/v1alpha.go Show resolved Hide resolved
internal/api/convert/v1alpha_test.go Show resolved Hide resolved
internal/manifests/collector/annotations.go Outdated Show resolved Hide resolved
internal/manifests/collector/config_replace.go Outdated Show resolved Hide resolved
internal/manifests/collector/configmap.go Show resolved Hide resolved
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
}

// PodAnnotations return the spec annotations for OpenTelemetryCollector pod.
func PodAnnotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
func PodAnnotations(instance v1alpha2.OpenTelemetryCollector) (map[string]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: in the future, i think we should make the getConfigMapSHA a method on the collector itself that returns no error. Note worth doing in this PR, but doing so in the future would help us clean up a lot of the error checking this introduces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few thoughts/questions. But overall i think this LGTM. I do think we should merge this after #2567 so that we don't incur a major performance hit from all this marshalling business we're doing now.

func Deployment(params manifests.Params) *appsv1.Deployment {
name := naming.Collector(params.OtelCol.Name)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
func Deployment(params manifests.Params) (*appsv1.Deployment, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think after this change and #2516 go in, i will modify these signatures to not take in the whole manifests.Params object, but only the object they need (i.e. collector in this case)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
)

func PodDisruptionBudget(params manifests.Params) *policyV1.PodDisruptionBudget {
func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget, error) {
otelCol, err := convert.V1Alpha1to2(params.OtelCol)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you open an issue for cleaning this up after this is merged?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collector_id: ${POD_NAME}
endpoint: http://prometheus-cr-targetallocator:80
interval: 30s
prometheus:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we need to change the whitespacing for these now? I saw the indent call above in the serialization and wasn't sure why we need that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y, thats a bit weird. This one works fine. But as soon as we use yaml.Marshal it falls back to ident = 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default yaml.Marshal creates a newEncoder() which is initliazed with ident = 4.

https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/encode.go#L56-L67

@pavolloffay pavolloffay changed the title internal/manifests/collector: switch internally to v1alphav2 internal/manifests/collector: switch internally to v1alpha2 Feb 1, 2024
Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress 🎉

Just one comment, I would prefer avoiding type config -> yaml -> type config translation.

return nil, err
}

confStr, err := otelCol.Spec.Config.Yaml()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typed config is serialized to yaml and then back unserialized to map[interface{}]interface{}

The typed config could be easily converted to map[interface{}]interface{} which is accepted in most signatures

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add another toMap() method and extend the scope of #2591 for it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please book a follow up ticket for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frzifus
Copy link
Member Author

frzifus commented Feb 1, 2024

As discussed on the sig call, we will wait until the next release is published.

@pavolloffay pavolloffay merged commit 769c984 into open-telemetry:main Feb 5, 2024
27 checks passed
@frzifus frzifus deleted the v1alphav2 branch February 5, 2024 15:16
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
…emetry#2532)

* internal/manifests/collector: switch internally to v1alphav2

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: change svc account

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/api/convert: propagate ver upgrade error

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* intern/{api,manifests}: directly call yaml unmarshal

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/api/convert: map DaemonSetUpdateStrategy

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: migrate configmap

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/api/convert: use go-yaml instead of sig-yaml

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* pkg/sidecar: upgrade internal use from v1alpha2 to v1alpha2

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: adapt cm, svc, ingress & route

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/api/convert: fix v1alpha1 to v1alpha2

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: evaluate returned error value in tests

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* apis/v1alpha2: config yaml method

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: use v1alpha2.Config yaml method

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* controllers/builder: adapt ident in unit test

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: fix test

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* tests/e2e: align to new indentation

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* internal/manifests/collector: cleanup

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

---------

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants