Skip to content

Conversation

@anjalii-28
Copy link
Contributor

This change updates sharedmain to handle missing shipped ConfigMaps more gracefully
at startup.

Behavior:
-> Missing shipped ConfigMaps are treated as empty (defaults used) instead of panicking

  • A warning is logged when the ConfigMap is not found
  • Watchers remain active and pick up the ConfigMap if it is created later
  • No changes to existing observability restart semantics

Fixes #3195

Testing:

  • Unit tests in pkg/injection/sharedmain pass
  • Local failures in pkg/test/upgrade/shell are due to macOS Bash 3.2, CI runs Bash ≥4

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 13, 2026
@knative-prow
Copy link

knative-prow bot commented Jan 13, 2026

Hi @anjalii-28. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow
Copy link

knative-prow bot commented Jan 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: anjalii-28
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from Leo6Leo and creydr January 13, 2026 10:17
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.61%. Comparing base (93d6642) to head (8b44dc9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3308      +/-   ##
==========================================
- Coverage   74.63%   74.61%   -0.02%     
==========================================
  Files         188      188              
  Lines        8195     8210      +15     
==========================================
+ Hits         6116     6126      +10     
- Misses       1840     1843       +3     
- Partials      239      241       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dprotaso
Copy link
Member

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 14, 2026
}
// ConfigMap doesn't exist and is not defaulted. Log a warning but don't fail.
// The watcher will pick up the ConfigMap if it's created later.
log.Printf("WARNING: ConfigMap %q in namespace %q not found, using defaults and watching for creation", k, i.Namespace)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't use log package. we use a zap logger we'll probably want a new constructor that accepts a logger if we want these errors

Comment on lines +490 to 499
if _, err := kubeclient.Get(ctx).CoreV1().ConfigMaps(system.Namespace()).Get(ctx, cmName,
metav1.GetOptions{}); err == nil {
cmw.Watch(logging.ConfigMapName(), logging.UpdateLevelFromConfigMap(logger, atomicLevel, component))
} else if !apierrors.IsNotFound(err) {
logger.Fatalw("Error reading ConfigMap "+logging.ConfigMapName(), zap.Error(err))
cmw.Watch(cmName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, component))
} else if apierrors.IsNotFound(err) {
// ConfigMap doesn't exist, but we still register a watcher so updates are picked up if it's created later.
logger.Warnw("ConfigMap "+cmName+" not found, using defaults and watching for creation", zap.String("configmap", cmName))
cmw.Watch(cmName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, component))
} else {
logger.Fatalw("Error reading ConfigMap "+cmName, zap.Error(err))
}
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we can simply call Watch now? and not have these if clauses here

Comment on lines +521 to +525
} else if apierrors.IsNotFound(err) {
// ConfigMap doesn't exist, but we still register a watcher so updates are picked up if it's created later.
logger.Warnw("ConfigMap "+cmName+" not found, using defaults and watching for creation", zap.String("configmap", cmName))
cmw.Watch(cmName, observers...)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Likewise we can simplify this and just call Watch and not worry about fetching the config maps?

Copy link
Member

Choose a reason for hiding this comment

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

Also one thing we could do for the observability config map is maybe kill the main context thus triggering a shutdown of the component. Then Kubernetes would restart the pod.


// Check which ConfigMaps exist and mark missing ones (without defaults) as done in the synced callback
// so we don't wait for them indefinitely
i.markMissingConfigMapsAsDone(s)
Copy link
Member

Choose a reason for hiding this comment

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

This behaviour should probably be opt-in for now using an option. Someone might be relying checkObservedResourcesExist to return the error and we don't want to break that.

// so we don't wait for it. The watcher will pick it up if it's created later.
s.MarkKeyAsDone(k)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

should probably return an error if Get returns something besides IsNotFound no?

case err.Error() != tc.expectErr:
t.Fatal("Unexpected error =", err)
// Missing ConfigMaps should not cause Start to fail
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

revert this - we shouldn't change the default behaviour

Copy link
Member

Choose a reason for hiding this comment

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

We should add a separate test for the new behaviour

cmw := cminformer.NewInformedWatcher(kc, system.Namespace())

// Track if the update handler was invoked
var handlerInvoked sync.WaitGroup
Copy link
Member

Choose a reason for hiding this comment

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

It would be simpler to just have a channel that returns ConfigMaps

Copy link
Member

Choose a reason for hiding this comment

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

Then you could drop handlerMutex as well

}

// Give the watcher time to fully start and sync
time.Sleep(500 * time.Millisecond)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably use the config map watchers Wait method here

// Handler was invoked, verify the ConfigMap
handlerMutex.Lock()
defer handlerMutex.Unlock()
if receivedConfigMap == nil {
Copy link
Member

Choose a reason for hiding this comment

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

We use cmp.Diff to make this simpler - see other examples in the codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider changing sharedmain behaviour about panic'ing when a config map is missing

2 participants