Skip to content

Commit 23a648a

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

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"makefile.configureOnOpen": false
3+
}

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ 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 (
99104
targetNamespaceAuthServerCA *corev1.ConfigMap
100-
sessionSecret *corev1.Secret
101105
)
106+
102107
switch authnConfig.Spec.Type {
103108
case configv1.AuthenticationTypeOIDC:
104109
if len(authnConfig.Spec.OIDCProviders) > 0 {
@@ -112,11 +117,6 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
112117
}
113118
}
114119
}
115-
116-
sessionSecret, err = co.syncSessionSecret(ctx, updatedOperatorConfig, controllerContext.Recorder())
117-
if err != nil {
118-
return statusHandler.FlushAndReturn(err)
119-
}
120120
}
121121

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

pkg/console/subresource/consoleserver/config_builder.go

Lines changed: 7 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
@@ -190,12 +191,17 @@ func (b *ConsoleServerCLIConfigBuilder) Capabilities(capabilities []operatorv1.C
190191
}
191192

192193
func (b *ConsoleServerCLIConfigBuilder) AuthConfig(authnConfig *configv1.Authentication, apiServerURL string) *ConsoleServerCLIConfigBuilder {
194+
b.sessionDir = "/var/sessions"
195+
193196
switch authnConfig.Spec.Type {
194197
// We don't disable auth since the internal OAuth server is not disabled even with auth type 'None'.
195198
case "", configv1.AuthenticationTypeIntegratedOAuth, configv1.AuthenticationTypeNone:
196199
b.authType = "openshift"
197200
b.oauthClientID = api.OAuthClientName
198201
b.CAFile = oauthServingCertFilePath
202+
b.sessionAuthenticationFile = "/var/session-secret/sessionAuthenticationKey"
203+
b.sessionEncryptionFile = "/var/session-secret/sessionEncryptionKey"
204+
199205
return b
200206

201207
case configv1.AuthenticationTypeOIDC:
@@ -419,6 +425,7 @@ func (b *ConsoleServerCLIConfigBuilder) session() Session {
419425
conf := Session{
420426
CookieAuthenticationKeyFile: b.sessionAuthenticationFile,
421427
CookieEncryptionKeyFile: b.sessionEncryptionFile,
428+
SessionDir: b.sessionDir,
422429
}
423430
return conf
424431
}

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)