<p>I have the following code:</p>

<pre><code>secret, err = d.serviceClient.Secrets(namespace).Get(secret.Name, metav1.GetOptions{})
if err != nil {
    // If not found, create a new secret
    if _, err := d.serviceClient.Secrets(namespace).Create(secret); err != nil {
        return errors.Wrap(err, "error creating user secrets")
    }
}
</code></pre>

<p>And the code generating a secret:</p>

<pre><code>func generateDatabaseSecret(message types.Deployment) *apiv1.Secret {
    data := map[string][]byte{
        "TEST":     []byte("test"),
    }
    object := metav1.ObjectMeta{Name: "test"}
    secret := &amp;v1.Secret{Data: data, ObjectMeta: object}

    output, _ := json.Marshal(secret)
    log.Println(string(output))
    return secret
</code></pre>

<p>}</p>

<p>However when I run the above against my Kubernetes cluster, I get the following error:</p>

<pre><code> error creating user secrets: Secret "" is invalid: metadata.name: Required value: name or generateName is required
</code></pre>

<p>Even though the JSON encoded secret is as followed:</p>

<pre><code>{"metadata":{"name":"test","creationTimestamp":null},"data":{"TEST":"bG9jYWxsb3N0"}
</code></pre>

<p>Am I missing something super obvious here? It doesn't make any sense</p>

<p>As David Maze sad in comments, you calling the wrong method <code>Create</code> instead of <code>generateDatabaseSecret</code>.</p>
