Support for path to config.json file removed
@@ -5,7 +5,6 @@ import (
"context"
"encoding/base64"
"encoding/json"
- "io/ioutil"
"time"
"github.com/pkg/errors"
@@ -175,7 +174,7 @@ func createSecret(ctx context.Context, client *kubernetes.Clientset, imagePullSe
var out bytes.Buffer
data := make(map[string][]byte)
if imagePullSecret.SecretType == "kubernetes.io/dockerconfigjson" {
- //If secret type is dockerconfigjson, check if required field in data exists
+ //Check if required field in data exists
v, found := imagePullSecret.Data[".dockerconfigjson"]
if !found {
return errors.Errorf("Secret type kubernetes.io/dockerconfigjson requires argument \".dockerconfigjson\"")
@@ -183,11 +182,7 @@ func createSecret(ctx context.Context, client *kubernetes.Clientset, imagePullSe
if len(imagePullSecret.Data) > 1 {
return errors.Errorf("Secret type kubernetes.io/dockerconfigjson accepts only one argument \".dockerconfigjson\"")
}
- //Then, if data is a path to a config file, it is opened
- configFile, err := ioutil.ReadFile(v)
- if err != nil {
- //If data is not a valid path, we assume data is a base64 encoded config.json file
- //Client only accepts Json formated files as data, so we decode and indent it (indentation is required)
+ //K8s client accepts only Json formated files as data, provided data must be decoded and indented (indentation is required)
parsedConfig, err := base64.StdEncoding.DecodeString(v)
if err != nil {
return errors.Wrap(err, "Secret's config file not found or unable to decode data.")
@@ -197,13 +192,9 @@ func createSecret(ctx context.Context, client *kubernetes.Clientset, imagePullSe
return errors.Wrap(err, "Unable to parse encoded data.")
}
data[".dockerconfigjson"] = out.Bytes()
+
} else {
- data[".dockerconfigjson"] = configFile
- }
- } else {
- for k, v := range imagePullSecret.Data {
- data[k] = []byte(v)
- }
+ return errors.Errorf("ImagePullSecret must be of type: kubernetes.io/dockerconfigjson")
}
secret := corev1.Secret{
TypeMeta: metav1.TypeMeta{
