Skip to content

Commit cb2ac38

Browse files
committed
[WIP] Gracefully handle config changes
1 parent 22bad28 commit cb2ac38

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

pkg/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
RedirectContainerPortName = "custom-route-redirect"
3939
ServiceCAConfigMapName = "service-ca"
4040
SessionSecretName = "session-secret"
41+
SessionStorageVolumeName = "session-storage"
4142
TargetNamespace = "openshift-console"
4243
TrustedCABundleKey = "ca-bundle.crt"
4344
TrustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"

pkg/console/operator/sync_v400.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,17 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
9595
return statusHandler.FlushAndReturn(err)
9696
}
9797

98+
sessionSecret, err := co.syncSessionSecret(ctx, updatedOperatorConfig, controllerContext.Recorder())
99+
if err != nil {
100+
return statusHandler.FlushAndReturn(err)
101+
}
102+
98103
var (
99-
targetNamespaceAuthServerCA *corev1.ConfigMap
100104
sessionSecret *corev1.Secret
105+
targetNamespaceAuthServerCA *corev1.ConfigMap
106+
authServerCAConfig *corev1.ConfigMap
101107
)
108+
102109
switch authnConfig.Spec.Type {
103110
case configv1.AuthenticationTypeOIDC:
104111
if len(authnConfig.Spec.OIDCProviders) > 0 {
@@ -112,11 +119,6 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
112119
}
113120
}
114121
}
115-
116-
sessionSecret, err = co.syncSessionSecret(ctx, updatedOperatorConfig, controllerContext.Recorder())
117-
if err != nil {
118-
return statusHandler.FlushAndReturn(err)
119-
}
120122
}
121123

122124
customLogosErr, customLogosErrReason := co.SyncCustomLogos(updatedOperatorConfig)

pkg/console/subresource/configmap/configmap.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
const (
2424
consoleConfigYamlFile = "console-config.yaml"
2525
defaultLogoutURL = ""
26+
sessionDir = "/var/sessions"
2627
pluginProxyEndpoint = "/api/proxy/plugin/"
2728
)
2829

@@ -104,6 +105,7 @@ func DefaultConfigMap(
104105
NodeArchitectures(nodeArchitectures).
105106
NodeOperatingSystems(nodeOperatingSystems).
106107
AuthConfig(authConfig, apiServerURL).
108+
SessionDir(sessionDir).
107109
Capabilities(operatorConfig.Spec.Customization.Capabilities).
108110
ConfigYAML()
109111
if err != nil {

pkg/console/subresource/consoleserver/config_builder.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type ConsoleServerCLIConfigBuilder struct {
6363
monitoring map[string]string
6464
customHostnameRedirectPort int
6565
inactivityTimeoutSeconds int
66+
sessionDir string
6667
pluginsList map[string]string
6768
pluginsOrder []string
6869
i18nNamespaceList []string
@@ -196,6 +197,9 @@ func (b *ConsoleServerCLIConfigBuilder) AuthConfig(authnConfig *configv1.Authent
196197
b.authType = "openshift"
197198
b.oauthClientID = api.OAuthClientName
198199
b.CAFile = oauthServingCertFilePath
200+
b.sessionAuthenticationFile = "/var/session-secret/sessionAuthenticationKey"
201+
b.sessionEncryptionFile = "/var/session-secret/sessionEncryptionKey"
202+
199203
return b
200204

201205
case configv1.AuthenticationTypeOIDC:
@@ -238,6 +242,11 @@ func (b *ConsoleServerCLIConfigBuilder) InactivityTimeout(timeout int) *ConsoleS
238242
return b
239243
}
240244

245+
func (b *ConsoleServerCLIConfigBuilder) SessionDir(sessionDir string) *ConsoleServerCLIConfigBuilder {
246+
b.sessionDir = sessionDir
247+
return b
248+
}
249+
241250
func (b *ConsoleServerCLIConfigBuilder) Plugins(plugins map[string]string) *ConsoleServerCLIConfigBuilder {
242251
b.pluginsList = plugins
243252
return b

pkg/console/subresource/consoleserver/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type Auth struct {
100100
type Session struct {
101101
CookieEncryptionKeyFile string `yaml:"cookieEncryptionKeyFile,omitempty"`
102102
CookieAuthenticationKeyFile string `yaml:"cookieAuthenticationKeyFile,omitempty"`
103+
SessionDir string `yaml:"sessionDir,omitempty"`
103104
// TODO: move InactivityTimeoutSeconds here
104105
}
105106

pkg/console/subresource/deployment/deployment.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ type volumeConfig struct {
5858
name string
5959
readOnly bool
6060
path string
61-
// isSecret or isConfigMap are mutually exclusive
61+
// isSecret, isConfigMap, and isEmptyDir are mutually exclusive
6262
isSecret bool
6363
isConfigMap bool
64+
isEmptyDir bool
6465
mappedKeys map[string]string
6566
}
6667

@@ -87,7 +88,6 @@ func DefaultDeployment(
8788
withStrategy(deployment, infrastructureConfig)
8889
withConsoleAnnotations(
8990
deployment,
90-
consoleConfigMap,
9191
serviceCAConfigMap,
9292
authnCATrustConfigMap,
9393
trustedCAConfigMap,
@@ -194,7 +194,6 @@ func withStrategy(deployment *appsv1.Deployment, infrastructureConfig *configv1.
194194
// version changes.
195195
func withConsoleAnnotations(
196196
deployment *appsv1.Deployment,
197-
consoleConfigMap *corev1.ConfigMap,
198197
serviceCAConfigMap *corev1.ConfigMap,
199198
authServerCAConfigMap *corev1.ConfigMap,
200199
trustedCAConfigMap *corev1.ConfigMap,
@@ -203,8 +202,9 @@ func withConsoleAnnotations(
203202
proxyConfig *configv1.Proxy,
204203
infrastructureConfig *configv1.Infrastructure,
205204
) {
205+
// Avoid rolling out when the console-config configmap is updated.
206+
// Console now watches the configmap for changes without needing to redeploy.
206207
deployment.ObjectMeta.Annotations = map[string]string{
207-
configMapResourceVersionAnnotation: consoleConfigMap.GetResourceVersion(),
208208
serviceCAConfigMapResourceVersionAnnotation: serviceCAConfigMap.GetResourceVersion(),
209209
trustedCAConfigMapResourceVersionAnnotation: trustedCAConfigMap.GetResourceVersion(),
210210
proxyConfigResourceVersionAnnotation: proxyConfig.GetResourceVersion(),
@@ -304,6 +304,16 @@ func withConsoleVolumes(
304304
},
305305
}
306306
}
307+
if item.isEmptyDir {
308+
vols[i] = corev1.Volume{
309+
Name: item.name,
310+
VolumeSource: corev1.VolumeSource{
311+
EmptyDir: &corev1.EmptyDirVolumeSource{
312+
Medium: corev1.StorageMediumMemory,
313+
},
314+
},
315+
}
316+
}
307317
}
308318
deployment.Spec.Template.Spec.Volumes = vols
309319
}
@@ -519,6 +529,12 @@ func defaultVolumeConfig() []volumeConfig {
519529
path: "/var/service-ca",
520530
isConfigMap: true,
521531
},
532+
{
533+
name: api.SessionStorageVolumeName,
534+
readOnly: false,
535+
path: "/var/sessions",
536+
isEmptyDir: true,
537+
},
522538
}
523539
}
524540

pkg/console/subresource/deployment/deployment_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ func TestWithConsoleAnnotations(t *testing.T) {
632632
ObjectMeta: metav1.ObjectMeta{
633633
Annotations: map[string]string{
634634
workloadManagementAnnotation: workloadManagementAnnotationValue,
635-
configMapResourceVersionAnnotation: consoleConfigMap.GetResourceVersion(),
636635
serviceCAConfigMapResourceVersionAnnotation: serviceCAConfigMap.GetResourceVersion(),
637636
authnCATrustConfigMapResourceVersionAnnotation: oauthServingCertConfigMap.GetResourceVersion(),
638637
trustedCAConfigMapResourceVersionAnnotation: trustedCAConfigMap.GetResourceVersion(),
@@ -649,7 +648,7 @@ func TestWithConsoleAnnotations(t *testing.T) {
649648
}
650649
for _, tt := range tests {
651650
t.Run(tt.name, func(t *testing.T) {
652-
withConsoleAnnotations(tt.args.deployment, tt.args.consoleConfigMap, tt.args.serviceCAConfigMap, tt.args.authServerCAConfigMap, tt.args.trustedCAConfigMap, tt.args.oAuthClientSecret, tt.args.sessionSecret, tt.args.proxyConfig, tt.args.infrastructureConfig)
651+
withConsoleAnnotations(tt.args.deployment, tt.args.serviceCAConfigMap, tt.args.authServerCAConfigMap, tt.args.trustedCAConfigMap, tt.args.oAuthClientSecret, tt.args.sessionSecret, tt.args.proxyConfig, tt.args.infrastructureConfig)
653652
if diff := deep.Equal(tt.args.deployment, tt.want); diff != nil {
654653
t.Error(diff)
655654
}

0 commit comments

Comments
 (0)