gaurav agnihotri
gaurav agnihotri

Reputation: 387

How to create kubernetes secret using json file content and stringData field

I am trying to create a secret using JSON file content and stringData like below but giving some error which I am not able to identify after multiple tries.

apiVersion: v1
kind: Secret
metadata:
  name: image-secret
  type: Opaque
stringData:
   creds: _json_key:{"type": "service_account","project_id": "xyz","private_key_id": "9b0eb25b41ae9161123dbfh56mgj","private_key": "-----BEGIN PRIVATE KEY-----\nmch0iiFz1DAdM8vQTXiETI+3gvSnknXQ0M5WmkA1dkiJgyhe3r8tpeb42jo4FCd\nbHLf9eeIql8TKEm9BAk+qnQZq8FykWEnQLuU7APrFNZ0qtYP8t1Y7HSGpdVmmCyK\nykJAGznKaiEf9SJiNy8HqJy1kOhajn1fL3CdcShWcY793qRLyeFyrIZ\n6lfnjSE9IW5iEOBmxEpXf5Q=\n-----END PRIVATE KEY-----\n","client_email": "[email protected].","client_id": "113522222222222222222222222","auth_uri": "https://accounts.google.com,"token_uri": "https://oauth.googleap,"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth/v1/certs","client_x509_cert_url": "https://www.googleapis.com/v1"}

username as _json_key and password is "json file content"

The error which I am getting is as below:-

error: error parsing argocd-image-updater-secret.yaml: error converting YAML to JSON: yaml: line 7: mapping values are not allowed in this context

Upvotes: 0

Views: 414

Answers (1)

mdaniel
mdaniel

Reputation: 33231

You're getting bitten by a yaml-ism, as yaml2json or yamllint would inform you

Error: Cannot parse as YAML (mapping values are not allowed here
  in "<byte string>", line 5, column 28:
       creds: _json_key:{"type": "service_account","project_id" ... 
                               ^)

what you'll want is to fold that scalar so the : is clearly character data and not parsed as a yaml key

metadata:
  name: image-secret
  type: Opaque
stringData:
   creds: >-
     _json_key:{"type": "service_account","project_id": "xyz","private_key_id": "9b0eb25b41ae9161123dbfh56mgj","private_key": "-----BEGIN PRIVATE KEY-----\nmch0iiFz1DAdM8vQTXiETI+3gvSnknXQ0M5WmkA1dkiJgyhe3r8tpeb42jo4FCd\nbHLf9eeIql8TKEm9BAk+qnQZq8FykWEnQLuU7APrFNZ0qtYP8t1Y7HSGpdVmmCyK\nykJAGznKaiEf9SJiNy8HqJy1kOhajn1fL3CdcShWcY793qRLyeFyrIZ\n6lfnjSE9IW5iEOBmxEpXf5Q=\n-----END PRIVATE KEY-----\n","client_email": "[email protected].","client_id": "113522222222222222222222222","auth_uri": "https://accounts.google.com,"token_uri": "https://oauth.googleap,"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth/v1/certs","client_x509_cert_url": "https://www.googleapis.com/v1"}

Upvotes: 1

Related Questions