Skip to content

Conversation

awprice
Copy link
Contributor

@awprice awprice commented Jun 5, 2018

Exposing the underlying kubernetes client will provide the flexibility of
allowing the user to perform more advanced actions that the SDK does not
provide out of the box. Often, more advanced actions are located in
subresources of the resource, like Pods().Evict and Pods().GetLogs. The SDK
does not provide access to these, and restricts the user to create, get,
update, delete and list.

Some examples:

kubeClient := k8sclient.GetKubeClient()

// Evict pod
kubeClient.CoreV1().Pods("default").Evict(&v1beta1.Eviction{})

// Get pod logs
kubeClient.CoreV1().Pods("default").GetLogs("example", &v1.PodLogOptions{})

Resolves #190

@andersjanmyr
Copy link
Contributor

andersjanmyr commented Jun 5, 2018

👍 I have done this in my fork of the project too. This is definitely something that is needed while the project is maturing.

@hasbro17
Copy link
Contributor

hasbro17 commented Jun 5, 2018

@awprice LGTM. Can you please update the CHANGELOG as well. Just add The SDK exposes the Kubernetes clientset via k8sclient.GetKubeClient() #295.

@awprice
Copy link
Contributor Author

awprice commented Jun 5, 2018

@hasbro17 Awesome. I've just updated the changelog to include that line.
@andersjanmyr Yep, definitely agree that it's needed whilst the project is maturing.

@hasbro17
Copy link
Contributor

hasbro17 commented Jun 5, 2018

@awprice Were you able to manually test this out, i.e successfully use the client returned by k8sclient.GetKubeClient() to create/update resources.
We're still working on adding e2e tests so we'll need to test this manually for now.

Exposing the underlying kubernetes client will provide the flexibility of
allowing the user to perform more advanced actions that the SDK does not
provide out of the box. Often, more advanced actions are located in
subresources of the resource, like Pods().Evict and Pods().GetLogs. The SDK
does not provide access to these, and restricts the user to create, get,
update, delete and list.

Some examples:

```go
kubeClient := k8sclient.GetKubeClient()

// Evict pod
kubeClient.CoreV1().Pods("default").Evict(&v1beta1.Eviction{})

// Get pod logs
kubeClient.CoreV1().Pods("default").GetLogs("example", &v1.PodLogOptions{})
```

Resolves operator-framework#190
@awprice
Copy link
Contributor Author

awprice commented Jun 6, 2018

@hasbro17 Apologies, I've updated the commit to fix an issue where the kubeClient is nil.

I've tested the change with the following actions:

  • Creating pods
  • Updating pods
  • Deleting pods

More advanced actions:

  • Using the Discovery API to determine if eviction is supported on the API server
  • Evicting pods

@hasbro17 hasbro17 merged commit 2cedbe0 into operator-framework:master Jun 6, 2018
m1kola pushed a commit to m1kola/operator-sdk that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants