-
Notifications
You must be signed in to change notification settings - Fork 111
CONSOLE-3322: Update cluster-authentication-operator not to go degraded without console #583
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
Changes from all commits
cad2b81
0a1714b
3da2e5c
a6c1ea8
022752c
c779d16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ import ( | |
| "github.com/openshift/library-go/pkg/operator/configobserver" | ||
| "github.com/openshift/library-go/pkg/operator/events" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
|
|
||
| "github.com/openshift/cluster-authentication-operator/pkg/controllers/configobservation" | ||
| ) | ||
|
|
||
|
|
@@ -20,12 +22,28 @@ func ObserveConsoleURL(genericlisters configobserver.Listers, recorder events.Re | |
| listers := genericlisters.(configobservation.Listers) | ||
| errs := []error{} | ||
|
|
||
| consoleConfig, err := listers.ConsoleLister.Get("cluster") | ||
| clusterVersionConfig, err := listers.ClusterVersionLister.Get("version") | ||
| if err != nil { | ||
| return existingConfig, append(errs, err) | ||
| } | ||
|
|
||
| isConsoleCapabilityEnabled := false | ||
| for _, capability := range clusterVersionConfig.Status.Capabilities.EnabledCapabilities { | ||
| if capability == configv1.ClusterVersionCapabilityConsole { | ||
| isConsoleCapabilityEnabled = true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't the execution be stopped with a hardcoded value once the capability is not allowed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should 👍 |
||
| break | ||
| } | ||
| } | ||
| if !isConsoleCapabilityEnabled { | ||
| return existingConfig, nil | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrap this whole piece with the condition block and remove the capability special case from the error handling |
||
| consoleConfig, err := listers.ConsoleLister.Get("cluster") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nil exception panic here in case the capability is not enabled |
||
| if err != nil { | ||
| return existingConfig, append(errs, err) | ||
| } | ||
| observedAssetURL := consoleConfig.Status.ConsoleURL | ||
|
|
||
| if _, err := url.Parse(observedAssetURL); err != nil { // should never happen | ||
| return existingConfig, append(errs, fmt.Errorf("failed to parse consoleURL %q: %w", observedAssetURL, err)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,38 +17,58 @@ import ( | |
|
|
||
| func TestObserveConsoleURL(t *testing.T) { | ||
| existingConfig := configWithConsoleURL("https://teh.console.my") | ||
| noConfig := map[string]interface{}(nil) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| consoleConfig *configv1.ConsoleStatus | ||
| clusterVersion *configv1.ClusterVersionStatus | ||
| existingConfig map[string]interface{} | ||
| expectedConfig map[string]interface{} | ||
| expectedErrs []string | ||
| expectedUpdateEvent bool | ||
| }{ | ||
| { | ||
| name: "NoConsoleConfig", | ||
| name: "NoConsoleConfigConsoleCapabilityEnabled", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens when the capability is not enabled but someone creates the CRD and the object?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I think the cluster would be in an inconsistent state since the the CRD would be there but quite a lot of other resrouces would be missing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unless you can prevent it, yes. Add a unit test, please.
Cluster admin and likely anyone installing an operator. |
||
| consoleConfig: nil, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{configv1.ClusterVersionCapabilityConsole}}}, | ||
| existingConfig: existingConfig, | ||
| expectedConfig: existingConfig, | ||
| expectedErrs: []string{"\"cluster\" not found"}, | ||
| }, | ||
| { | ||
| name: "NoConsoleConfigConsoleCapabilityDisabled", | ||
| consoleConfig: nil, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{}}}, | ||
| existingConfig: noConfig, | ||
| expectedConfig: noConfig, | ||
| }, | ||
| { | ||
| name: "ConsoleConfigConsoleCapabilityDisabled", | ||
| consoleConfig: &configv1.ConsoleStatus{ConsoleURL: "https://teh.console.my"}, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{}}}, | ||
| existingConfig: configWithConsoleURL(""), | ||
| expectedConfig: configWithConsoleURL(""), | ||
| }, | ||
| { | ||
| name: "SameConfig", | ||
| consoleConfig: &configv1.ConsoleStatus{ConsoleURL: "https://teh.console.my"}, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{configv1.ClusterVersionCapabilityConsole}}}, | ||
| existingConfig: existingConfig, | ||
| expectedConfig: existingConfig, | ||
| }, | ||
| { | ||
| name: "UpdatedConsoleConfig", | ||
| consoleConfig: &configv1.ConsoleStatus{ConsoleURL: "https://my-new.console.url"}, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{configv1.ClusterVersionCapabilityConsole}}}, | ||
| existingConfig: existingConfig, | ||
| expectedConfig: configWithConsoleURL("https://my-new.console.url"), | ||
| expectedUpdateEvent: true, | ||
| }, | ||
| { | ||
| name: "UnparsableConsoleURL", | ||
| consoleConfig: &configv1.ConsoleStatus{ConsoleURL: "https://my-new.console.url:port"}, | ||
| clusterVersion: &configv1.ClusterVersionStatus{Capabilities: configv1.ClusterVersionCapabilitiesStatus{EnabledCapabilities: []configv1.ClusterVersionCapability{configv1.ClusterVersionCapabilityConsole}}}, | ||
| existingConfig: existingConfig, | ||
| expectedConfig: existingConfig, | ||
| expectedErrs: []string{ | ||
|
|
@@ -58,9 +78,9 @@ func TestObserveConsoleURL(t *testing.T) { | |
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{}) | ||
| consoleIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{}) | ||
| if tt.consoleConfig != nil { | ||
| if err := indexer.Add(&configv1.Console{ | ||
| if err := consoleIndexer.Add(&configv1.Console{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "cluster", | ||
| }, | ||
|
|
@@ -69,8 +89,20 @@ func TestObserveConsoleURL(t *testing.T) { | |
| t.Fatal(err) | ||
| } | ||
| } | ||
| clusterVersionIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{}) | ||
| if tt.clusterVersion != nil { | ||
| if err := clusterVersionIndexer.Add(&configv1.ClusterVersion{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "version", | ||
| }, | ||
| Status: *tt.clusterVersion, | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| listers := configobservation.Listers{ | ||
| ConsoleLister: configlistersv1.NewConsoleLister(indexer), | ||
| ConsoleLister: configlistersv1.NewConsoleLister(consoleIndexer), | ||
| ClusterVersionLister: configlistersv1.NewClusterVersionLister(clusterVersionIndexer), | ||
| } | ||
|
|
||
| eventRecorder := events.NewInMemoryRecorder(tt.name) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could
breakhere, but 🤷, iterating through the remainder of the list isn't expensive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a
breakin the next line now, so this thread can be marked resolved.