Skip to content

Commit 265939e

Browse files
committed
Add OAuth metadata CM resource sync
Create the OAuth metadata ConfigMap in the target namespace and then use the already existing logic to sync it to openshift-config-managed
1 parent ca12aa1 commit 265939e

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

pkg/operator2/configmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func getMetadata(route *routev1.Route) string {
4444

4545
func getMetadataConfigMap(route *routev1.Route) *corev1.ConfigMap {
4646
meta := defaultMeta()
47-
meta.Namespace = machineConfigNamespace
47+
meta.Name = oauthMetadataName
4848
return &corev1.ConfigMap{
4949
ObjectMeta: meta,
5050
Data: map[string]string{

pkg/operator2/configsync.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import (
1212
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
1313
)
1414

15+
type SyncResourceType string
16+
17+
const (
18+
oauthConfigSyncType SyncResourceType = "oauthconfig"
19+
metadataSyncType SyncResourceType = "oauthmetadata"
20+
removeSyncType SyncResourceType = "removethisdata"
21+
)
22+
1523
func (c *authOperator) handleConfigSync(data *configSyncData) ([]string, error) {
1624
// TODO handle OAuthTemplates
1725

@@ -53,15 +61,15 @@ func (c *authOperator) handleConfigSync(data *configSyncData) ([]string, error)
5361
inUseSecretNames := sets.NewString()
5462

5563
for dest, src := range data.idpConfigMaps {
56-
syncOrDie(c.resourceSyncer.SyncConfigMap, dest, src.src)
64+
syncOrDie(c.resourceSyncer.SyncConfigMap, oauthConfigSyncType, dest, src.src)
5765
inUseConfigMapNames.Insert(dest)
5866
}
5967
for dest, src := range data.idpSecrets {
60-
syncOrDie(c.resourceSyncer.SyncSecret, dest, src.src)
68+
syncOrDie(c.resourceSyncer.SyncSecret, oauthConfigSyncType, dest, src.src)
6169
inUseSecretNames.Insert(dest)
6270
}
6371
for dest, src := range data.tplSecrets {
64-
syncOrDie(c.resourceSyncer.SyncSecret, dest, src.src)
72+
syncOrDie(c.resourceSyncer.SyncSecret, oauthConfigSyncType, dest, src.src)
6573
inUseSecretNames.Insert(dest)
6674
}
6775

@@ -72,10 +80,10 @@ func (c *authOperator) handleConfigSync(data *configSyncData) ([]string, error)
7280
// it does not really matter, we are talking as worse case of
7381
// a few unneeded strings and a few unnecessary deletes
7482
for dest := range notInUseConfigMapNames {
75-
syncOrDie(c.resourceSyncer.SyncConfigMap, dest, "")
83+
syncOrDie(c.resourceSyncer.SyncConfigMap, removeSyncType, dest, "")
7684
}
7785
for dest := range notInUseSecretNames {
78-
syncOrDie(c.resourceSyncer.SyncSecret, dest, "")
86+
syncOrDie(c.resourceSyncer.SyncSecret, removeSyncType, dest, "")
7987
}
8088

8189
// only get the resource versions of the elements in use
@@ -88,6 +96,8 @@ func (c *authOperator) handleConfigSync(data *configSyncData) ([]string, error)
8896
resourceVersionsInUse = append(resourceVersionsInUse, resourceVersionsAll[name])
8997
}
9098

99+
syncOrDie(c.resourceSyncer.SyncConfigMap, metadataSyncType, oauthMetadataName, targetName)
100+
91101
return resourceVersionsInUse, nil
92102
}
93103

@@ -243,18 +253,30 @@ func getTemplatePath(name, key string) string {
243253
return fmt.Sprintf("%s/%s/%s", userConfigPathPrefixTemplate, name, key)
244254
}
245255

246-
func syncOrDie(syncFunc func(dest, src resourcesynccontroller.ResourceLocation) error, dest, src string) {
247-
ns := userConfigNamespace
248-
if len(src) == 0 { // handle delete
249-
ns = ""
256+
func syncOrDie(syncFunc func(dest, src resourcesynccontroller.ResourceLocation) error, t SyncResourceType, dest, src string) {
257+
var srcNs, destNs string
258+
259+
switch t {
260+
case oauthConfigSyncType:
261+
srcNs = userConfigNamespace
262+
destNs = targetName
263+
case metadataSyncType:
264+
srcNs = targetName
265+
destNs = machineConfigNamespace
266+
case removeSyncType:
267+
srcNs = ""
268+
destNs = targetName
269+
default:
270+
panic("Unknown config sync type")
250271
}
272+
251273
if err := syncFunc(
252274
resourcesynccontroller.ResourceLocation{
253-
Namespace: targetName,
275+
Namespace: destNs,
254276
Name: dest,
255277
},
256278
resourcesynccontroller.ResourceLocation{
257-
Namespace: ns,
279+
Namespace: srcNs,
258280
Name: src,
259281
},
260282
); err != nil {

pkg/operator2/operator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const (
6767
cliConfigMount = systemConfigPathConfigMaps + "/" + cliConfigNameAndKey
6868
cliConfigPath = cliConfigMount + "/" + cliConfigNameAndKey
6969

70+
oauthMetadataName = systemConfigPrefix + "metadata"
71+
7072
userConfigPath = "/var/config/user"
7173

7274
servicePort = 443

pkg/operator2/starter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
112112
v1helpers.EnsureOperatorConfigExists(dynamicClient, []byte(resource), gvr)
113113
}
114114

115-
resourceSyncerInformers := v1helpers.NewKubeInformersForNamespaces(kubeClient, targetName, userConfigNamespace)
115+
resourceSyncerInformers := v1helpers.NewKubeInformersForNamespaces(
116+
kubeClient,
117+
targetName,
118+
userConfigNamespace,
119+
machineConfigNamespace,
120+
)
116121

117122
operatorClient := &OperatorClient{
118123
authOperatorConfigInformers,

0 commit comments

Comments
 (0)