question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kubernetes provider can't create a namespace with a name attribute

See original GitHub issue

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave “+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

{
  "name": "tf-cdk",
  "version": "1.0.0",
  "main": "main.js",
  "types": "main.ts",
  "license": "MPL-2.0",
  "private": true,
  "scripts": {
    "get": "cdktf get",
    "build": "yarn get && tsc",
    "synth": "cdktf synth",
    "compile": "tsc",
    "watch": "tsc -w",
    "test": "echo ok",
    "upgrade": "npm i cdktf@latest cdktf-cli@latest",
    "upgrade:next": "npm i cdktf@next cdktf-cli@next"
  },
  "engines": {
    "node": ">=10.12"
  },
  "dependencies": {
    "cdktf": "0.0.10-pre.2655a66d496aff0bbaeae9a518bea153dae3cee0",
    "constructs": "^3.0.4"
  },
  "devDependencies": {
    "@types/node": "^14.0.23",
    "cdktf-cli": "0.0.10",
    "typescript": "^3.9.6"
  }
}

Affected Resource(s)

import { Construct } from 'constructs';
import { App, TerraformStack } from 'cdktf';
import {KubernetesProvider, Namespace} from './.gen/providers/kubernetes';

class MyStack extends TerraformStack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    // define resources here
    new KubernetesProvider(this, 'kind', {});

    new Namespace(this, 'tf-cdk', {
      metadata: [{
        labels: {},
        name: 'tf-cdk'
      }]
    })
  }
}

const app = new App();
new MyStack(app, 'tf-cdk');
app.synth();

Debug Output

main.ts:15:9 - error TS2322: Type '{ labels: {}; name: string; }' is not assignable to type 'NamespaceMetadata'.
  Object literal may only specify known properties, and 'name' does not exist in type 'NamespaceMetadata'.

15         name: 'tf-cdk'
           ~~~~~~~~~~~~~~


Found 1 error.

Expected Behavior

Generated Terraform code in the output directory: cdktf.out

Actual Behavior

⠋ synthesizing ...
Warning: Render methods should be a pure function of props and state; triggering nested component updates from render is not allowed. If necessary, trigger nested updates in componentDidUpdate.

Check the render method of Unknown.
non-zero exit code 1

Steps to Reproduce

Try to create a namespace with a name attribute using the Kubernetes provider

Important Factoids

Name is a valid input for the kubernetes_namespace resource.

In the CDK schema doc in namespace.ts it shows as optional and computed.

            "name": {
              "type": "string",
              "description": "Name of the namespace, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
              "optional": true,
              "computed": true
            },

It’s absent from the NamespaceMetadata interface

export interface NamespaceMetadata {
  /** An unstructured key value map stored with the namespace that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations */
  readonly annotations?: { [key: string]: string };
  /** Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency */
  readonly generateName?: string;
  /** Map of string keys and values that can be used to organize and categorize (scope and select) the namespace. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels */
  readonly labels?: { [key: string]: string };
}

References

None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
skorfmanncommented, Jul 15, 2020

When looking at the schema

      "metadata": {
        "nesting_mode": "list",
        "block": {
          "attributes": {
            "annotations": {
              "type": [
                "map",
                "string"
              ],
              "description": "An unstructured key value map stored with the namespace that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations",
              "optional": true
            },
            "generate_name": {
              "type": "string",
              "description": "Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency",
              "optional": true
            },
            "generation": {
              "type": "number",
              "description": "A sequence number representing a specific generation of the desired state.",
              "computed": true
            },
            "labels": {
              "type": [
                "map",
                "string"
              ],
              "description": "Map of string keys and values that can be used to organize and categorize (scope and select) the namespace. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels",
              "optional": true
            },
            "name": {
              "type": "string",
              "description": "Name of the namespace, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
              "optional": true,
              "computed": true
            },
            "resource_version": {
              "type": "string",
              "description": "An opaque value that represents the internal version of this namespace that can be used by clients to determine when namespace has changed. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency",
              "computed": true
            },
            "self_link": {
              "type": "string",
              "description": "A URL representing this namespace.",
              "computed": true
            },
            "uid": {
              "type": "string",
              "description": "The unique in time and space value for this namespace. More info: http://kubernetes.io/docs/user-guide/identifiers#uids",
              "computed": true
            }
          }
        },
        "min_items": 1,
        "max_items": 1
      },

And comparing it to the docs it looks like we could just guard it by optional being true.

Besides from that, what we certainly don’t support at the moment are attribute references for nested types e.g. generation

0reactions
github-actions[bot]commented, Dec 8, 2022

I’m going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you’ve found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

kubernetes_namespace | Resources | hashicorp/kubernetes
kubernetes_namespace. Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.
Read more >
Namespaces Walkthrough | Kubernetes
We have created a deployment whose replica size is 2 that is running the pod called snowflake with a basic container that serves...
Read more >
Create Namespace Resource - Pulumi
kubernetes.core/v1.Namespace. Namespace provides a scope for Names. Use of multiple namespaces is optional. Create Namespace Resource.
Read more >
Manage Kubernetes Resources via Terraform
You can use the Terraform Kubernetes provider to interact with resources supported ... kind create cluster --name terraform-learn --config kind-config.yaml ...
Read more >
Why does using data source attributes in Kubernetes terraform ...
The trace logs indicate that the kube_config object has empty value for several fields that are passed to the provider.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found