Skip to content

Commit

Permalink
Replace client instantiation with a clearer config
Browse files Browse the repository at this point in the history
Changed the examples to showcase DynamicClient instantiation without the
parameter since `config.load_kube_config()` does not return anything.

Signed-off-by: Christoffer Kragh Pedersen <[email protected]>
  • Loading branch information
tonur committed Sep 16, 2024
1 parent 18fe668 commit 6f1ae85
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
10 changes: 6 additions & 4 deletions examples/dynamic-client/accept_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)


# fetching the node api
api = client.resources.get(api_version="v1", kind="Node")
api = dynamic_client.resources.get(api_version="v1", kind="Node")

# Creating a custom header
params = {'header_params': {'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}}
Expand Down
13 changes: 7 additions & 6 deletions examples/dynamic-client/cluster_scoped_custom_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the custom resource definition (CRD) api
crd_api = client.resources.get(
crd_api = dynamic_client.resources.get(
api_version="apiextensions.k8s.io/v1", kind="CustomResourceDefinition"
)

Expand Down Expand Up @@ -104,14 +105,14 @@ def main():
# Fetching the "ingressroutes" CRD api

try:
ingressroute_api = client.resources.get(
ingressroute_api = dynamic_client.resources.get(
api_version="apps.example.com/v1", kind="IngressRoute"
)
except ResourceNotFoundError:
# Need to wait a sec for the discovery layer to get updated
time.sleep(2)

ingressroute_api = client.resources.get(
ingressroute_api = dynamic_client.resources.get(
api_version="apps.example.com/v1", kind="IngressRoute"
)

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/configmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the configmap api
api = client.resources.get(api_version="v1", kind="ConfigMap")
api = dynamic_client.resources.get(api_version="v1", kind="ConfigMap")

configmap_name = "test-configmap"

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/deployment_rolling_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the deployment api
api = client.resources.get(api_version="apps/v1", kind="Deployment")
api = dynamic_client.resources.get(api_version="apps/v1", kind="Deployment")

name = "nginx-deployment"

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/namespaced_custom_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ def delete_namespace(namespace_api, name):

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the custom resource definition (CRD) api
crd_api = client.resources.get(
crd_api = dynamic_client.resources.get(
api_version="apiextensions.k8s.io/v1", kind="CustomResourceDefinition"
)

Expand Down
10 changes: 6 additions & 4 deletions examples/dynamic-client/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)

configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the node api
api = client.resources.get(api_version="v1", kind="Node")
api = dynamic_client.resources.get(api_version="v1", kind="Node")

# Listing cluster nodes

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/replication_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the replication controller api
api = client.resources.get(api_version="v1", kind="ReplicationController")
api = dynamic_client.resources.get(api_version="v1", kind="ReplicationController")

name = "frontend-replication-controller"

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/request_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the configmap api
api = client.resources.get(api_version="v1", kind="ConfigMap")
api = dynamic_client.resources.get(api_version="v1", kind="ConfigMap")

configmap_name = "request-timeout-test-configmap"

Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic-client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

def main():
# Creating a dynamic client
client = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
configuration = api_client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(client)

# fetching the service api
api = client.resources.get(api_version="v1", kind="Service")
api = dynamic_client.resources.get(api_version="v1", kind="Service")

name = "frontend-service"

Expand Down

0 comments on commit 6f1ae85

Please sign in to comment.