Skip to content

Add redeploy on serving cert and operator pod template change #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2019
Merged
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
16 changes: 11 additions & 5 deletions pkg/operator2/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ const (
injectCABundleAnnotationValue = "true"
)

func (c *authOperator) handleServiceCA() (*corev1.ConfigMap, error) {
func (c *authOperator) handleServiceCA() (*corev1.ConfigMap, *corev1.Secret, error) {
cm := c.configMaps.ConfigMaps(targetName)
secret := c.secrets.Secrets(targetName)
serviceCA, err := cm.Get(serviceCAName, metav1.GetOptions{})
if errors.IsNotFound(err) {
serviceCA, err = cm.Create(defaultServiceCA())
}
if err != nil {
return nil, err
return nil, nil, err
}

if len(serviceCA.Data[serviceCAKey]) == 0 {
return nil, fmt.Errorf("config map has no service ca data: %#v", serviceCA)
return nil, nil, fmt.Errorf("config map has no service ca data: %#v", serviceCA)
}

if err := isValidServiceCA(serviceCA); err != nil {
Expand All @@ -36,10 +37,15 @@ func (c *authOperator) handleServiceCA() (*corev1.ConfigMap, error) {
if err := cm.Delete(serviceCA.Name, opts); err != nil && !errors.IsNotFound(err) {
glog.Infof("failed to delete invalid service CA config map: %v", err)
}
return nil, err
return nil, nil, err
}

return serviceCA, nil
servingCert, err := secret.Get(servingCertName, metav1.GetOptions{})
if err != nil {
return nil, nil, err
}

return serviceCA, servingCert, nil
}

func isValidServiceCA(ca *corev1.ConfigMap) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator2/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getMetadata(route *routev1.Route) string {

func getMetadataConfigMap(route *routev1.Route) *corev1.ConfigMap {
meta := defaultMeta()
meta.Namespace = machineConfigNamespace
meta.Name = oauthMetadataName
return &corev1.ConfigMap{
ObjectMeta: meta,
Data: map[string]string{
Expand Down
22 changes: 15 additions & 7 deletions pkg/operator2/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (
cliConfigMount = systemConfigPathConfigMaps + "/" + cliConfigNameAndKey
cliConfigPath = cliConfigMount + "/" + cliConfigNameAndKey

oauthMetadataName = systemConfigPrefix + "metadata"

userConfigPath = "/var/config/user"

servicePort = 443
Expand Down Expand Up @@ -180,12 +182,7 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
}
resourceVersions = append(resourceVersions, route.GetResourceVersion())

serviceCA, err := c.handleServiceCA()
if err != nil {
return err
}
resourceVersions = append(resourceVersions, serviceCA.GetResourceVersion())

// make sure API server sees our metadata as soon as we've got a route with a host
metadata, _, err := resourceapply.ApplyConfigMap(c.configMaps, c.recorder, getMetadataConfigMap(route))
if err != nil {
return err
Expand All @@ -198,6 +195,12 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
}
resourceVersions = append(resourceVersions, authConfig.GetResourceVersion())

serviceCA, servingCert, err := c.handleServiceCA()
if err != nil {
return err
}
resourceVersions = append(resourceVersions, serviceCA.GetResourceVersion(), servingCert.GetResourceVersion())

service, _, err := resourceapply.ApplyService(c.services, c.recorder, defaultService())
if err != nil {
return err
Expand Down Expand Up @@ -235,9 +238,14 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
}
resourceVersions = append(resourceVersions, cliConfig.GetResourceVersion())

operatorDeployment, err := c.deployments.Deployments(targetNameOperator).Get(targetNameOperator, metav1.GetOptions{})
if err != nil {
return err
}
resourceVersions = append(resourceVersions, operatorDeployment.GetResourceVersion())

// deployment, have RV of all resources
// TODO use ExpectedDeploymentGeneration func
// TODO we also need the RV for the serving-cert secret (servingCertName)
expectedDeployment := defaultDeployment(
operatorConfig,
syncData,
Expand Down
15 changes: 14 additions & 1 deletion pkg/operator2/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
v1helpers.EnsureOperatorConfigExists(dynamicClient, []byte(resource), gvr)
}

resourceSyncerInformers := v1helpers.NewKubeInformersForNamespaces(kubeClient, targetName, userConfigNamespace)
resourceSyncerInformers := v1helpers.NewKubeInformersForNamespaces(
kubeClient,
targetName,
userConfigNamespace,
machineConfigNamespace,
)

operatorClient := &OperatorClient{
authOperatorConfigInformers,
Expand All @@ -127,6 +132,14 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
ctx.EventRecorder,
)

// add syncing for the OAuth metadata ConfigMap
if err := resourceSyncer.SyncConfigMap(
resourcesynccontroller.ResourceLocation{Namespace: machineConfigNamespace, Name: targetName},
resourcesynccontroller.ResourceLocation{Namespace: targetName, Name: oauthMetadataName},
); err != nil {
return err
}

operator := NewAuthenticationOperator(
*operatorClient,
kubeInformersNamespaced,
Expand Down