Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
kind: ConfigMap
metadata:
namespace: openshift-config-managed
namespace: openshift-console
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Addressed in #612

2 changes: 1 addition & 1 deletion pkg/console/assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

185 changes: 93 additions & 92 deletions pkg/console/controllers/managedclusters/controller.go

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions pkg/console/operator/sync_v400.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
return statusHandler.FlushAndReturn(routeErr)
}

cm, cmChanged, cmErrReason, cmErr := co.SyncConfigMap(ctx, set.Operator, set.Console, set.Infrastructure, set.OAuth, route, controllerContext.Recorder())
// managed-clusters ConfigMap is managed by another controller and is not required, we don't need to exit the sync loop if it's not present
canMountManagedClusterConfig, managedClusterConfigErrReason, managedClusterConfigErr := co.SyncManagedClusterConfigMap(ctx)
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ManagedClusterConfigSync", managedClusterConfigErrReason, managedClusterConfigErr))
Comment on lines +75 to +76
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I address conditionally adding the managed cluster config file name to the console config in #612.


cm, cmChanged, cmErrReason, cmErr := co.SyncConfigMap(ctx, set.Operator, set.Console, set.Infrastructure, set.OAuth, route, canMountManagedClusterConfig, controllerContext.Recorder())
toUpdate = toUpdate || cmChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ConfigMapSync", cmErrReason, cmErr))
if cmErr != nil {
return statusHandler.FlushAndReturn(cmErr)
}

// managed-clusters ConfigMap is managed by another controller and is not required, we don't need to exit the sync loop if it's not present
canMountManagedClusterConfig, managedClusterConfigErrReason, managedClusterConfigErr := co.SyncManagedClusterConfigMap(ctx)
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ManagedClusterConfigSync", managedClusterConfigErrReason, managedClusterConfigErr))

serviceCAConfigMap, serviceCAChanged, serviceCAErrReason, serviceCAErr := co.SyncServiceCAConfigMap(ctx, set.Operator)
toUpdate = toUpdate || serviceCAChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ServiceCASync", serviceCAErrReason, serviceCAErr))
Expand Down Expand Up @@ -317,6 +317,7 @@ func (co *consoleOperator) SyncConfigMap(
infrastructureConfig *configv1.Infrastructure,
oauthConfig *configv1.OAuth,
activeConsoleRoute *routev1.Route,
canMountManagedClusterConfig bool,
recorder events.Recorder,
) (consoleConfigMap *corev1.ConfigMap, changed bool, reason string, err error) {

Expand Down Expand Up @@ -349,7 +350,7 @@ func (co *consoleOperator) SyncConfigMap(
}

pluginsEndpointMap := co.GetPluginsEndpointMap(operatorConfig.Spec.Plugins)
defaultConfigmap, _, err := configmapsub.DefaultConfigMap(operatorConfig, consoleConfig, managedConfig, infrastructureConfig, activeConsoleRoute, useDefaultCAFile, inactivityTimeoutSeconds, pluginsEndpointMap)
defaultConfigmap, _, err := configmapsub.DefaultConfigMap(operatorConfig, consoleConfig, managedConfig, infrastructureConfig, activeConsoleRoute, useDefaultCAFile, inactivityTimeoutSeconds, pluginsEndpointMap, canMountManagedClusterConfig)
if err != nil {
return nil, false, "FailedConsoleConfigBuilder", err
}
Expand Down Expand Up @@ -380,7 +381,7 @@ func (co *consoleOperator) SyncManagedClusterConfigMap(ctx context.Context) (boo
// Degraded if managed cluster config map is present but doesn't have the correct data key
_, ok := managedClusterConfigMap.Data[api.ManagedClusterConfigKey]
if !ok {
return false, "MissingManagedClusterConfig", fmt.Errorf("%v ConfigMap is missing %v data key", api.ManagedClusterConfigMapName, api.ManagedClusterConfigKey)
return false, "MissingManagedClusterConfig", fmt.Errorf("%s ConfigMap is missing %s data key", api.ManagedClusterConfigMapName, api.ManagedClusterConfigKey)
}

// Managed cluster config map is present and can be mounted
Expand Down
10 changes: 8 additions & 2 deletions pkg/console/subresource/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ func DefaultConfigMap(
activeConsoleRoute *routev1.Route,
useDefaultCAFile bool,
inactivityTimeoutSeconds int,
pluginsEndpoingMap map[string]string) (consoleConfigmap *corev1.ConfigMap, unsupportedOverridesHaveMerged bool, err error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have implemented similar changes to this file and the related unit test file in #612.

pluginsEndpoingMap map[string]string,
canMountManagedClusterConfig bool) (consoleConfigmap *corev1.ConfigMap, unsupportedOverridesHaveMerged bool, err error) {

managedClusterConfigFile := ""
if canMountManagedClusterConfig {
managedClusterConfigFile = fmt.Sprintf("%s/%s", api.ManagedClusterConfigMountDir, api.ManagedClusterConfigKey)
}

defaultBuilder := &consoleserver.ConsoleServerCLIConfigBuilder{}
defaultConfig, err := defaultBuilder.Host(activeConsoleRoute.Spec.Host).
Expand All @@ -53,7 +59,7 @@ func DefaultConfigMap(
OAuthServingCert(useDefaultCAFile).
APIServerURL(getApiUrl(infrastructureConfig)).
InactivityTimeout(inactivityTimeoutSeconds).
ManagedClusterConfigFile(fmt.Sprintf("%v/%v", api.ManagedClusterConfigMountDir, api.ManagedClusterConfigKey)).
ManagedClusterConfigFile(managedClusterConfigFile).
ConfigYAML()
if err != nil {
klog.Errorf("failed to generate default console-config config: %v", err)
Expand Down
110 changes: 86 additions & 24 deletions pkg/console/subresource/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ const (
// To manually run these tests: go test -v ./pkg/console/subresource/configmap/...
func TestDefaultConfigMap(t *testing.T) {
type args struct {
operatorConfig *operatorv1.Console
consoleConfig *configv1.Console
managedConfig *corev1.ConfigMap
infrastructureConfig *configv1.Infrastructure
rt *routev1.Route
useDefaultCAFile bool
inactivityTimeoutSeconds int
enabledPlugins map[string]string
operatorConfig *operatorv1.Console
consoleConfig *configv1.Console
managedConfig *corev1.ConfigMap
infrastructureConfig *configv1.Infrastructure
rt *routev1.Route
useDefaultCAFile bool
inactivityTimeoutSeconds int
enabledPlugins map[string]string
canMountManagedClusterConfig bool
}
tests := []struct {
name string
Expand All @@ -63,8 +64,9 @@ func TestDefaultConfigMap(t *testing.T) {
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -114,8 +116,9 @@ providers: {}
Host: host,
},
},
useDefaultCAFile: false,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: false,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -174,8 +177,9 @@ customization:
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -243,8 +247,9 @@ customization:
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -317,8 +322,9 @@ customization:
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -393,8 +399,9 @@ customization:
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -451,8 +458,9 @@ providers:
Host: customHostname,
},
},
useDefaultCAFile: false,
inactivityTimeoutSeconds: 0,
useDefaultCAFile: false,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -503,8 +511,9 @@ providers: {}
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 60,
useDefaultCAFile: true,
inactivityTimeoutSeconds: 60,
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -561,6 +570,7 @@ providers: {}
"plugin1": "plugin1_url",
"plugin2": "plugin2_url",
},
canMountManagedClusterConfig: true,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -590,6 +600,57 @@ providers: {}
plugins:
plugin1: plugin1_url
plugin2: plugin2_url
`,
},
},
},
{
name: "Test canMountManagedClusterConfig set to false",
args: args{
operatorConfig: &operatorv1.Console{},
consoleConfig: &configv1.Console{},
managedConfig: &corev1.ConfigMap{},
infrastructureConfig: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
APIServerURL: mockAPIServer,
},
},
rt: &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: api.OpenShiftConsoleName,
},
Spec: routev1.RouteSpec{
Host: host,
},
},
useDefaultCAFile: true,
inactivityTimeoutSeconds: 0,
canMountManagedClusterConfig: false,
},
want: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: api.OpenShiftConsoleConfigMapName,
Namespace: api.OpenShiftConsoleNamespace,
Labels: map[string]string{"app": api.OpenShiftConsoleName},
Annotations: map[string]string{},
},
Data: map[string]string{configKey: `kind: ConsoleConfig
apiVersion: console.openshift.io/v1
auth:
clientID: console
clientSecretFile: /var/oauth-config/clientSecret
oauthEndpointCAFile: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
clusterInfo:
consoleBaseAddress: https://` + host + `
masterPublicURL: ` + mockAPIServer + `
customization:
branding: ` + DEFAULT_BRAND + `
documentationBaseURL: ` + DEFAULT_DOC_URL + `
servingInfo:
bindAddress: https://[::]:8443
certFile: /var/serving-cert/tls.crt
keyFile: /var/serving-cert/tls.key
providers: {}
`,
},
},
Expand All @@ -606,6 +667,7 @@ plugins:
tt.args.useDefaultCAFile,
tt.args.inactivityTimeoutSeconds,
tt.args.enabledPlugins,
tt.args.canMountManagedClusterConfig,
)

// marshall the exampleYaml to map[string]interface{} so we can use it in diff below
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/subresource/configmap/managed_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
URL: "test-url",
CAFile: "/var/api/ca",
},
Oauth: consoleserver.ManagedClusterOAuthConfig{
OAuth: consoleserver.ManagedClusterOAuthConfig{
ClientID: "test-client-id",
ClientSecret: "test-client-secret",
CAFile: "/var/oauth/ca",
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/subresource/consoleserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ type ManagedClusterOAuthConfig struct {
type ManagedClusterConfig struct {
Name string `json:"name" yaml:"name"` // ManagedCluster name, provided through ACM
APIServer ManagedClusterAPIServerConfig `json:"apiServer" yaml:"apiServer"`
Oauth ManagedClusterOAuthConfig `json:"oauth" yaml:"oauth"`
OAuth ManagedClusterOAuthConfig `json:"oauth" yaml:"oauth"`
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package managedclusterview
package managedcluster
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer to keep MCV/MCA subresource modules separated by kind.


import (
operatorv1 "github.com/openshift/api/operator/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package managedclusterview
package managedcluster

import (
operatorv1 "github.com/openshift/api/operator/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

// openshift

"github.com/openshift/console-operator/pkg/console/assets"
"github.com/openshift/console-operator/pkg/console/subresource/util"
// acm - TODO conflicts adding package to go.mod with several dependencies
// managedclusterviewv1beta1 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/action/v1beta1"
)

func DefaultCreateOAuthClient(cr *operatorv1.Console, cn string, sec string, redirects []string) *unstructured.Unstructured {
managedClusterAction := CreateOAuthClientStub(cn)
withDefaultCreateOAuthClientInfo(managedClusterAction, cn, sec, redirects)
return managedClusterAction
}

func withDefaultCreateOAuthClientInfo(mca *unstructured.Unstructured, cn string, sec string, redirects []string) {
unstructured.SetNestedField(mca.Object, cn, "metadata", "namespace")
unstructured.SetNestedField(mca.Object, sec, "spec", "kube", "template", "secret")
unstructured.SetNestedStringSlice(mca.Object, redirects, "spec", "kube", "template", "redirectURIs")
}

func CreateOAuthClientStub(cn string) *unstructured.Unstructured {
return util.ReadUnstructuredOrDie(assets.MustAsset("managedclusteractions/console-managed-cluster-action-create-oauth-client.yaml"))
}

func DefaultViewOAuthClient(cr *operatorv1.Console, cn string) *unstructured.Unstructured {
managedClusterView := ViewOAuthClientStub(cn)
withDefaultViewOAuthClientInfo(managedClusterView, cn)
Expand All @@ -27,6 +42,22 @@ func ViewOAuthClientStub(cn string) *unstructured.Unstructured {
return util.ReadUnstructuredOrDie(assets.MustAsset("managedclusterviews/console-managed-cluster-view-oauth-client.yaml"))
}

func GetActionGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "view.open-cluster-management.io",
Version: "v1beta1",
Resource: "managedclusterviews",
}
}

func GetViewGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "action.open-cluster-management.io",
Version: "v1beta1",
Resource: "managedclusteractions",
}
}

func GetStatus(mcv *unstructured.Unstructured) (bool, error) {
conditions, found, err := unstructured.NestedSlice(mcv.Object, "status", "conditions")
if err != nil || !found || len(conditions) == 0 {
Expand Down Expand Up @@ -57,11 +88,3 @@ func GetNamespace(mcv *unstructured.Unstructured) (string, error) {
}
return namespace, nil
}

func GetGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "view.open-cluster-management.io",
Version: "v1beta1",
Resource: "managedclusterviews",
}
}
Loading