Skip to content

apply method didn't work with provided namespace  #296

@ahrechanychenko

Description

@ahrechanychenko
(Pdb) from kubernetes import config
(Pdb) from openshift.dynamic import DynamicClient
(Pdb) k8s_client = config.new_client_from_config()
(Pdb) dyn_client = DynamicClient(k8s_client)
(Pdb) data = yaml.safe_load(open("test.yaml"))
(Pdb) data
{'kind': 'Service', 'spec': {'ports': [{'targetPort': 8080, 'protocol': 'TCP', 'port': 8080, 'name': 'web3'}]}, 'apiVersion': 'v1', 'metadata': {'name': 'svc-test'}}
(Pdb) resp = dyn_client.apply(service, body=data, namespace="test")

 PDB set_trace (IO-capturing turned off) 
*** ValueError: Namespace is required for v1.Service

(Pdb) data['metadata']['namespace']="test"
(Pdb) data
{'kind': 'Service', 'spec': {'ports': [{'targetPort': 8080, 'protocol': 'TCP', 'port': 8080, 'name': 'web3'}]}, 'apiVersion': 'v1', 'metadata': {'namespace': 'test', 'name': 'svc-test'}}
(Pdb) resp = dyn_client.apply(service, body=data)
(Pdb) resp
ResourceInstance[Service]:
  apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: '2019-05-23T11:56:08Z'
    name: svc-test
    namespace: test
    resourceVersion: '3133190'
    selfLink: /api/v1/namespaces/test/services/svc-test
    uid: c066a908-7d51-11e9-a348-5254002c416c
  spec:
    clusterIP: 172.30.186.221
    ports:
    - name: web3
      port: 8080
      protocol: TCP
      targetPort: 8080
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions