-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
observe router secrets for servingInfo - named certificates
- Loading branch information
Showing
6 changed files
with
99 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
pkg/operator2/configobservation/routersecret/observe_router_secret.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package routersecret | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
"github.com/openshift/library-go/pkg/operator/configobserver" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
|
||
"github.com/openshift/cluster-authentication-operator/pkg/operator2/configobservation" | ||
) | ||
|
||
func ObserveRouterSecret(genericlisters configobserver.Listers, recorder events.Recorder, previouslyObservedConfig map[string]interface{}) (map[string]interface{}, []error) { | ||
namedCertificatesPath := []string{"servingInfo", "namedCertificates"} | ||
listers := genericlisters.(configobservation.Listers) | ||
errs := []error{} | ||
|
||
currentNamedCertificates, _, err := unstructured.NestedFieldCopy(previouslyObservedConfig, namedCertificatesPath...) | ||
if err != nil { | ||
return previouslyObservedConfig, append(errs, err) | ||
} | ||
|
||
currentNamedCertificatesSlice := []interface{}{} | ||
if currentNamedCertificates != nil { | ||
currentNamedCertificatesSlice = currentNamedCertificates.([]interface{}) | ||
} | ||
|
||
// TODO: this was previously causing "FailedRouterSecret" degraded condition | ||
routerSecret, err := listers.SecretsLister.Secrets("openshift-authentication").Get("v4-0-config-system-router-certs") | ||
if err != nil { | ||
return previouslyObservedConfig, append(errs, err) | ||
} | ||
|
||
// FIXME: treat the error | ||
observedNamedCertificates, err := routerSecretToSNI(routerSecret) | ||
|
||
observedConfig := map[string]interface{}{} | ||
if err := unstructured.SetNestedField( | ||
observedConfig, | ||
observedNamedCertificates, | ||
namedCertificatesPath..., | ||
); err != nil { | ||
return previouslyObservedConfig, append(errs, err) | ||
} | ||
|
||
if !equality.Semantic.DeepEqual(currentNamedCertificatesSlice, observedNamedCertificates) { | ||
recorder.Eventf("ObserveRouterSecret", "namedCertificates changed to %#v", observedNamedCertificates) | ||
} | ||
|
||
return observedConfig, errs | ||
} | ||
|
||
func routerSecretToSNI(routerSecret *corev1.Secret) ([]interface{}, error) { | ||
var certs []configv1.NamedCertificate | ||
// make sure the output slice of named certs is sorted by domain so that the generated config is deterministic | ||
for _, domain := range sets.StringKeySet(routerSecret.Data).List() { | ||
certs = append(certs, configv1.NamedCertificate{ | ||
Names: []string{"*." + domain}, // ingress domain is always a wildcard | ||
CertInfo: configv1.CertInfo{ // the cert and key are appended together | ||
CertFile: "/var/config/system/secrets/v4-0-config-system-router-certs/" + domain, | ||
KeyFile: "/var/config/system/secrets/v4-0-config-system-router-certs/" + domain, | ||
}, | ||
}) | ||
} | ||
|
||
// TODO: the following is a bit perverted, I wonder if it could be done differently | ||
configBytes, err := json.Marshal(certs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: we may want to actually round-trip this to remove the fields that can be omitted | ||
unstructuredCertConfig := []interface{}{} | ||
if err := json.NewDecoder(bytes.NewBuffer(configBytes)).Decode(&unstructuredCertConfig); err != nil { | ||
return nil, fmt.Errorf("decode of observed config failed with error: %v", err) | ||
} | ||
|
||
return unstructuredCertConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters