mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-18 22:14:22 +00:00
supervisor-oidc: hoist OIDC discovery handler for testing
Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
package supervisorconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
corev1informers "k8s.io/client-go/informers/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog/v2"
|
||||
@@ -12,14 +15,30 @@ import (
|
||||
"go.pinniped.dev/internal/controllerlib"
|
||||
)
|
||||
|
||||
const (
|
||||
issuerConfigMapKey = "issuer"
|
||||
)
|
||||
|
||||
// IssuerSetter can be notified of a valid issuer with its SetIssuer function. If there is no
|
||||
// longer any valid issuer, then nil can be passed to this interface.
|
||||
//
|
||||
// Implementations of this type should be thread-safe to support calls from multiple goroutines.
|
||||
type IssuerSetter interface {
|
||||
SetIssuer(issuer *string)
|
||||
}
|
||||
|
||||
type dynamicConfigWatcherController struct {
|
||||
k8sClient kubernetes.Interface
|
||||
configMapInformer corev1informers.ConfigMapInformer
|
||||
configMapName string
|
||||
configMapNamespace string
|
||||
issuerSetter IssuerSetter
|
||||
k8sClient kubernetes.Interface
|
||||
configMapInformer corev1informers.ConfigMapInformer
|
||||
}
|
||||
|
||||
func NewDynamicConfigWatcherController(
|
||||
serverInstallationNamespace string,
|
||||
configMapName string,
|
||||
issuerObserver IssuerSetter,
|
||||
k8sClient kubernetes.Interface,
|
||||
configMapInformer corev1informers.ConfigMapInformer,
|
||||
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||
@@ -28,8 +47,11 @@ func NewDynamicConfigWatcherController(
|
||||
controllerlib.Config{
|
||||
Name: "DynamicConfigWatcherController",
|
||||
Syncer: &dynamicConfigWatcherController{
|
||||
k8sClient: k8sClient,
|
||||
configMapInformer: configMapInformer,
|
||||
configMapNamespace: serverInstallationNamespace,
|
||||
configMapName: configMapName,
|
||||
issuerSetter: issuerObserver,
|
||||
k8sClient: k8sClient,
|
||||
configMapInformer: configMapInformer,
|
||||
},
|
||||
},
|
||||
withInformer(
|
||||
@@ -44,9 +66,47 @@ func NewDynamicConfigWatcherController(
|
||||
func (c *dynamicConfigWatcherController) Sync(ctx controllerlib.Context) error {
|
||||
// TODO Watch the configmap to find the issuer name, ingress url, etc.
|
||||
// TODO Update some kind of in-memory representation of the configuration so the discovery endpoint can use it.
|
||||
// TODO The discovery endpoint would return an error until all missing configuration options are filled in.
|
||||
// TODO The discovery endpoint would return an error until all missing configuration options are
|
||||
// filled in.
|
||||
|
||||
klog.InfoS("DynamicConfigWatcherController sync finished")
|
||||
configMap, err := c.configMapInformer.
|
||||
Lister().
|
||||
ConfigMaps(c.configMapNamespace).
|
||||
Get(c.configMapName)
|
||||
notFound := k8serrors.IsNotFound(err)
|
||||
if err != nil && !notFound {
|
||||
return fmt.Errorf("failed to get %s/%s secret: %w", c.configMapNamespace, c.configMapName, err)
|
||||
}
|
||||
|
||||
if notFound {
|
||||
klog.InfoS(
|
||||
"dynamicConfigWatcherController Sync found no configmap",
|
||||
"configmap",
|
||||
klog.KRef(c.configMapNamespace, c.configMapName),
|
||||
)
|
||||
c.issuerSetter.SetIssuer(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
issuer, ok := configMap.Data[issuerConfigMapKey]
|
||||
if !ok {
|
||||
klog.InfoS(
|
||||
"dynamicConfigWatcherController Sync found no issuer",
|
||||
"configmap",
|
||||
klog.KObj(configMap),
|
||||
)
|
||||
c.issuerSetter.SetIssuer(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
klog.InfoS(
|
||||
"dynamicConfigWatcherController Sync issuer",
|
||||
"configmap",
|
||||
klog.KObj(configMap),
|
||||
"issuer",
|
||||
issuer,
|
||||
)
|
||||
c.issuerSetter.SetIssuer(&issuer)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user