Skip to content

Commit

Permalink
Run the upgrade of a collector instance after the status changes from…
Browse files Browse the repository at this point in the history
… unmanaged to managed (#2086)

* Run the upgrade of a collector instance after the status changes from unmanaged to managed

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

* Add changelog

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

* Use the recorder

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

* Move import

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

* Fix imports

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

* Don't fail when the upgrade cannot be done as part of the reconciliation

Signed-off-by: Israel Blancas <iblancasa@gmail.com>

---------

Signed-off-by: Israel Blancas <iblancasa@gmail.com>
  • Loading branch information
iblancasa authored Sep 14, 2023
1 parent 7d503f6 commit 3dee26b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/1890-run-upgrade-for-previously-unmanaged-instances.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: bug_fix

# 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: "Run the upgrade mechanism when there is a change in an instance to ensure it is upgraded. This is useful for cases where the instance uses the unmanaged state, the operator is upgraded and the instance changes to use a managed state."

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

# (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:
15 changes: 14 additions & 1 deletion pkg/collector/reconcile/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
"github.com/open-telemetry/opentelemetry-operator/internal/version"
collectorupgrade "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade"
)

// Self updates this instance's self data. This should be the last item in the reconciliation, as it causes changes
Expand All @@ -38,6 +39,18 @@ import (
func Self(ctx context.Context, params manifests.Params) error {
changed := params.Instance

up := &collectorupgrade.VersionUpgrade{
Log: params.Log,
Version: version.Get(),
Client: params.Client,
Recorder: params.Recorder,
}
changed, err := up.ManagedInstance(ctx, changed)
if err != nil {
// don't fail to allow setting the status
params.Log.Error(err, "failed to upgrade the OpenTelemetry CR")
}

// this field is only changed for new instances: on existing instances this
// field is reconciled when the operator is first started, i.e. during
// the upgrade mechanism
Expand All @@ -46,7 +59,7 @@ func Self(ctx context.Context, params manifests.Params) error {
changed.Status.Version = version.OpenTelemetryCollector()
}

if err := updateScaleSubResourceStatus(ctx, params.Client, &changed); err != nil {
if err = updateScaleSubResourceStatus(ctx, params.Client, &changed); err != nil {
return fmt.Errorf("failed to update the scale subresource status for the OpenTelemetry CR: %w", err)
}

Expand Down

0 comments on commit 3dee26b

Please sign in to comment.