Skip to content
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

Copy custom CA config map to additional namespaces #4953

Merged
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
4 changes: 4 additions & 0 deletions pkg/operator/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (c *Client) ApplyNamespacesInformer(namespaces []string, imagePullSecrets [
// we don't fail here...
log.Printf("error ensuring image pull secrets for namespace %s: %s", ns, err.Error())
}
if err := c.ensureEmbeddedClusterCAPresent(ns); err != nil {
// we don't fail here...
log.Printf("error ensuring cluster ca present for namespace %s: %s", ns, err.Error())
}
}

c.imagePullSecrets = imagePullSecrets
Expand Down
57 changes: 57 additions & 0 deletions pkg/operator/client/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,63 @@ func (c *Client) ensureImagePullSecretsPresent(namespace string, imagePullSecret
return nil
}

func (c *Client) ensureEmbeddedClusterCAPresent(namespace string) error {
if !util.IsEmbeddedCluster() {
return nil
}

logger.Debugf("ensuring embedded cluster ca present in namespace %s", namespace)

clientset, err := k8sutil.GetClientset()
if err != nil {
return errors.Wrap(err, "failed to get clientset")
}

configMapName := os.Getenv("SSL_CERT_CONFIGMAP")
sourceConfigMap, err := clientset.CoreV1().ConfigMaps(util.AppNamespace()).Get(context.TODO(), configMapName, metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get source configmap")
}
// This would happen in older EC releases
return nil
}

destConfigMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: configMapName,
Labels: sourceConfigMap.DeepCopy().Labels,
Annotations: sourceConfigMap.DeepCopy().Annotations,
Namespace: namespace,
},
Data: sourceConfigMap.DeepCopy().Data,
}

_, err = clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get destination configmap")
}

_, err = clientset.CoreV1().ConfigMaps(namespace).Create(context.TODO(), destConfigMap, metav1.CreateOptions{})
if err != nil {
return errors.Wrap(err, "failed to create configmap")
}
return nil
}

_, err = clientset.CoreV1().ConfigMaps(namespace).Update(context.TODO(), destConfigMap, metav1.UpdateOptions{})
if err != nil {
return errors.Wrap(err, "failed to update configmap")
}

return nil
}

func (c *Client) ensureResourcesPresent(deployArgs operatortypes.DeployAppArgs) (*deployResult, error) {
var deployRes deployResult

Expand Down
5 changes: 5 additions & 0 deletions pkg/operator/client/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (c *Client) runNamespacesInformer() error {
log.Printf("error ensuring image pull secrets for namespace %s: %s", addedNamespace.Name, err.Error())
}

if err := c.ensureEmbeddedClusterCAPresent(addedNamespace.Name); err != nil {
// we don't fail here...
log.Printf("error ensuring cluster ca present for namespace %s: %s", addedNamespace.Name, err.Error())
}

c.ApplyHooksInformer([]string{addedNamespace.Name})
}
},
Expand Down
Loading