Move docker config from configmap to secret
@@ -649,6 +649,21 @@ func createConfigMap(apiConfigMapRef string, key string, value string, ns string
}, nil
}
+// createSecret creates a config file with the given data
+func createSecret(secretName string, key string, value string, ns string, owner []metav1.OwnerReference) (*corev1.Secret, error) {
+
+ return &corev1.Secret{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: secretName,
+ Namespace: ns,
+ OwnerReferences: owner,
+ },
+ Data: map[string][]byte{
+ key: []byte(value),
+ },
+ }, nil
+}
+
//Swagger handling
func mgwSwaggerLoader(swaggerDataMap map[string]string) (*openapi3.Swagger, string, error) {
var swaggerData string
@@ -1045,31 +1060,31 @@ func dockerConfigCreator(r *ReconcileAPI, operatorOwner []metav1.OwnerReference)
return err
}
- //Writes the created template to a configmap
- dockerConf, er := createConfigMap(dockerConfig, "config.json", output, wso2NameSpaceConst, operatorOwner)
+ //Writes the created template to a secret
+ dockerConf, er := createSecret(dockerConfig, "config.json", output, wso2NameSpaceConst, operatorOwner)
if er != nil {
- log.Error(er, "error in docker-config configmap creation")
+ log.Error(er, "error in docker-config secret creation")
return er
}
// Check if this configmap already exists
- foundmap := &corev1.ConfigMap{}
- err = r.client.Get(context.TODO(), types.NamespacedName{Name: dockerConf.Name, Namespace: dockerConf.Namespace}, foundmap)
+ foundsecret := &corev1.Secret{}
+ err = r.client.Get(context.TODO(), types.NamespacedName{Name: dockerConf.Name, Namespace: dockerConf.Namespace}, foundsecret)
if err != nil && errors.IsNotFound(err) {
- log.Info("Creating a new Config map", "Namespace", dockerConf.Namespace, "confmap.Name", dockerConf.Name)
+ log.Info("Creating a new docker-config secret", "Namespace", dockerConf.Namespace, "secret.Name", dockerConf.Name)
err = r.client.Create(context.TODO(), dockerConf)
if err != nil {
log.Error(err, "error ")
return err
}
- // confmap created successfully
+ // secret created successfully
return nil
} else if err != nil {
log.Error(err, "error ")
return err
}
- log.Info("Map already exists", "confmap.Namespace", foundmap.Namespace, "confmap.Name", foundmap.Name)
+ log.Info("Docker config secret already exists", "secret.Namespace", foundsecret.Namespace, "secret.Name", foundsecret.Name)
log.Info("Updating Config map", "confmap.Namespace", dockerConf.Namespace, "confmap.Name", dockerConf.Name)
err = r.client.Update(context.TODO(), dockerConf)
if err != nil {
@@ -1176,10 +1191,8 @@ func getVolumes(apiConfMap string) ([]corev1.VolumeMount, []corev1.Volume) {
{
Name: dockerConfig,
VolumeSource: corev1.VolumeSource{
- ConfigMap: &corev1.ConfigMapVolumeSource{
- LocalObjectReference: corev1.LocalObjectReference{
- Name: dockerConfig,
- },
+ Secret: &corev1.SecretVolumeSource{
+ SecretName: dockerConfig,
},
},
},
