0

I am unable to add secret from file using below command :

oc create -f /tmp/config.json

Output : error: unable to decode "/tmp/config.json": Object 'Kind' is missing in '{

# cat /tmp/config.json 

    {
        "auths": {
            "my-repo-location" : {
                "auth": "ZTAxODE0W5V1yndNfoUdYWjRNtU="
            }
        }
    }
dataplumber
  • 375
  • 3
  • 16
  • Using `oc create -f` only works with manifest files. Try looking at `oc create secret -h` you should have some option to create a generic secret from a file. – Will Gordon Jan 08 '20 at 13:03
  • 1
    Now that I'm at my desktop, you should be running `oc create secret generic config --from-file=/tmp/config.json` – Will Gordon Jan 08 '20 at 14:38

1 Answers1

0

As pointed out by @WillGordon's comments you can use oc create secret generic, as shown in the example below:

$ cat config.json 
    {
        "auths": {
            "my-repo-location" : {
                "auth": "ZTAxODE0W5V1yndNfoUdYWjRNtU="
            }
        }
    }


$ oc create secret generic config --from-file=./config.json
secret/config created

$ oc get secret config -o yaml
apiVersion: v1
data:
  config.json: ICAgIHsKICAgICAgICAiYXV0aHMiOiB7CiAgICAgICAgICAgICJteS1yZXBvLWxvY2F0aW9uIiA6IHsKICAgICAgICAgICAgICAgICJhdXRoIjogIlpUQXhPREUwVzVWMXluZE5mb1VkWVdqUk50VT0iCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cg==
kind: Secret
metadata:
  creationTimestamp: 2020-01-10T15:00:21Z
  name: config
  namespace: next
  resourceVersion: "46478941"
  selfLink: /api/v1/namespaces/next/secrets/config
  uid: ec4a4538-33b9-11ea-a9de-005056b7c210
type: Opaque
$

However, if creating a secret for accessing a Docker registry you can use the docker-registry option, as shown below:

oc create secret docker-registry SECRET_NAME \
       --docker-server=DOCKER-IMAGE-REPOSITORY \
       --docker-username=username@email.com \
       --docker-password="password" \
       --docker-email=username@email.com
silveiralexf
  • 514
  • 1
  • 7
  • 23