Skip to content

Update AlertmanagerConfig's status subresource on Alertmanager reconciliations - #8148

Closed
yp969803 wants to merge 15 commits into
prometheus-operator:mainfrom
yp969803:issue7996
Closed

yp969803 wants to merge 15 commits into
prometheus-operator:mainfrom
yp969803:issue7996

Conversation

@yp969803

@yp969803 yp969803 commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Description

Closes: #7996

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.


@yp969803
yp969803 requested a review from a team as a code owner December 8, 2025 14:40
@pull-request-size pull-request-size Bot added size/S and removed size/XS labels Dec 9, 2025
@pull-request-size pull-request-size Bot added size/M and removed size/S labels Dec 9, 2025
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Dec 9, 2025
Comment thread pkg/alertmanager/operator.go Outdated
}

func (c *Operator) provisionAlertmanagerConfiguration(ctx context.Context, am *monitoringv1.Alertmanager, store *assets.StoreBuilder) error {
func (c *Operator) getAlertmanagerVersion(am *monitoringv1.Alertmanager) (semver.Version, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nit) it doesn't have to be an Operator method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@simonpasquier

Copy link
Copy Markdown
Contributor

It seems that the test needs some fixing but overall LGTM.

@yp969803

Copy link
Copy Markdown
Contributor Author

getting this error while running locally

panic: failed to map kind "" to a resource name

goroutine 390 [running]:
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring.KindToResource({0x0, 0x0})
        /home/yash/go/src/github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/resource.go:83 +0xa8
github.com/prometheus-operator/prometheus-operator/pkg/operator.toGroupVersionResource({0x2ad9b98?, 0xc0007ce780?})
        /home/yash/go/src/github.com/prometheus-operator/prometheus-operator/pkg/operator/config_resource.go:332 +0xab
github.com/prometheus-operator/prometheus-operator/pkg/operator.(*ConfigResourceSyncer).UpdateBinding(0xc00098a728, {0x2afc690, 0xc0000f6190}, {0x2b25330, 0xc0007ce780}, {0xc00097e7e0, 0x1, 0x1})
        /home/yash/go/src/github.com/prometheus-operator/prometheus-operator/pkg/operator/config_resource.go:212 +0x7d9
github.com/prometheus-operator/prometheus-operator/pkg/alertmanager.(*Operator).updateConfigResourcesStatus(0x2afc690?, {0x2afc690, 0xc0000f6190}, 0xc0008e8508, 0xc0004f78c0)
        /home/yash/go/src/github.com/prometheus-operator/prometheus-operator/pkg/alertmanager/operator.go:745 +0x34e
github.com/prometheus-operator/prometheus-operator/pkg/alertmanager.(*Operator).sync(0xc00037ad88, {0x2afc690, 0xc0000f6190}, {0xc0005ca160, 0xc})

@yp969803

Copy link
Copy Markdown
Contributor Author

error is happening here, k is "" for alertmanagerConfig @simonpasquier

func KindToResource(k string) string {
	
	kind, found := kindToResource[k]
	if !found {
		panic(fmt.Sprintf("failed to map kind %q to a resource name", k))
	}
	return kind
}

@simonpasquier

Copy link
Copy Markdown
Contributor

I suspect that the Alertmanager controller needs to call k8sutil.AddTypeInformationToObject() after retrieving AlertmanagerConfigs from the informer.

@yp969803

Copy link
Copy Markdown
Contributor Author

@simonpasquier i have added the typeinfo , but now the panic is happening in UpdateStatus

if _, err = crs.client.Resource(toGroupVersionResource(configResource)).Namespace(configResource.GetNamespace()).UpdateStatus(
			ctx,
			obj,
			metav1.UpdateOptions{
				FieldManager:    PrometheusOperatorFieldManager,
				FieldValidation: metav1.FieldValidationStrict,
			},
		); err != nil {
			return fmt.Errorf("failed to update status: %w", err)
		}

This is the error msg

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x1ec3a08]

Comment thread pkg/alertmanager/operator.go Outdated
return
}

if err := k8sutil.AddTypeInformationToObject(amConfig); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it should probably happen right after c.accessor.MetaNamespaceKey() and we can also call obj.DeepCopy()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// configurations.
type Operator struct {
kclient kubernetes.Interface
dclient dynamic.Interface

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

didn't we forget to initialize dclient?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@kartikangiras

kartikangiras commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

@simonpasquier I raised a new pull request for this change following the same logic with improved changes as discussed with @yp969803 on slack.

@slashpai

slashpai commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

@simonpasquier I raised a new pull request for this change following the same logic with improved changes as discussed with @yp969803 on slack.

Kindly add @yp969803 as Co-Authored By in commit message

@github-actions github-actions Bot added stale and removed stale labels Mar 10, 2026
@github-actions github-actions Bot added the stale label May 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request is being closed because it had no activity in the last 180 days. This is not a signal from the maintainers that the PR has no value. We appreciate the time and effort that you put into this work. If you're willing to re-open it, the maintainers will do their best to review it.

@github-actions github-actions Bot closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update AlertmanagerConfig's status subresource on Alertmanager reconciliations

4 participants