Skip to content

Consolidate k8s APIs#2747

Merged
siggy merged 2 commits intomasterfrom
siggy/check-k8s-smpfy
Apr 25, 2019
Merged

Consolidate k8s APIs#2747
siggy merged 2 commits intomasterfrom
siggy/check-k8s-smpfy

Conversation

@siggy
Copy link
Member

@siggy siggy commented Apr 25, 2019

Numerous codepaths have emerged that create k8s configs, k8s clients,
and make k8s api requests.

This branch consolidates k8s client creation and APIs. The primary
change migrates most codepaths to call k8s.NewAPI to instantiate a
KubernetesAPI struct from pkg. KubernetesAPI implements the
kubernetes.Interface (clientset) interface, and also persists a
client-go rest.Config.

Specific list of changes:

  • removes manual GET requests from k8s.KubernetesAPI, in favor of
    clientsets
  • replaces most calls to k8s.GetConfig+kubernetes.NewForConfig with
    a single k8s.NewAPI
  • introduces a timeout param to k8s.NewAPI, currently only used by
    healthchecks
  • removes NewClientSet in controller/k8s/clientset.go in favor of
    k8s.NewAPI
  • removes httpClient and clientset from HealthChecker, use
    KubernetesAPI instead

Signed-off-by: Andrew Seigner [email protected]

@siggy siggy self-assigned this Apr 25, 2019
@siggy
Copy link
Member Author

siggy commented Apr 25, 2019

A bit more context, this branch fell out of work on #2337, where we need to introduce multi-stage support into linkerd check. Multi-stage linkerd check motivates validating the existence of discrete k8s resources, such as ClusterRoles and CRDs. The existing k8s APIs and patterns in the healthcheck code would have necessitated the introduction of additional manual GET requests, or, parallel functionality via clientsets. This PR simplifies healthcheck code by providing a uniform client-go API for validating various k8s resources.

@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 25, 2019

Copy link
Contributor

@klingerf klingerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐️ Awesome! This is such a great cleanup.

err = json.Unmarshal(bytes, &versionInfo)
return &versionInfo, err
func (kubeAPI *KubernetesAPI) GetVersionInfo() (*version.Info, error) {
return kubeAPI.Discovery().ServerVersion()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man the changes in this file are so 😻

pkg/k8s/api.go Outdated
// configured cluster
func NewAPI(configPath, kubeContext string) (*KubernetesAPI, error) {
// configured cluster.
func NewAPI(configPath, kubeContext string, timeout time.Duration) (*KubernetesAPI, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your change, but can I bug you to move this func to the top of this file, right below where the KubernetesAPI struct is defined? It feels weird to have the initializer func defined so far down in the file.

siggy added 2 commits April 25, 2019 10:54
Numerous codepaths have emerged that create k8s configs, k8s clients,
and make k8s api requests.

This branch consolidates k8s client creation and APIs. The primary
change migrates most codepaths to call `k8s.NewAPI` to instantiate a
`KubernetesAPI` struct from `pkg`. `KubernetesAPI` implements the
`kubernetes.Interface` (clientset) interface, and also persists a
`client-go` `rest.Config`.

Specific list of changes:
- removes manual GET requests from `k8s.KubernetesAPI`, in favor of
  clientsets
- replaces most calls to `k8s.GetConfig`+`kubernetes.NewForConfig` with
  a single `k8s.NewAPI`
- introduces a `timeout` param to `k8s.NewAPI`, currently only used by
  healthchecks
- removes `NewClientSet` in `controller/k8s/clientset.go` in favor of
  `k8s.NewAPI`
- removes `httpClient` and `clientset` from `HealthChecker`, use
  `KubernetesAPI` instead

Signed-off-by: Andrew Seigner <[email protected]>
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 25, 2019

@siggy siggy merged commit ec540a8 into master Apr 25, 2019
@siggy siggy deleted the siggy/check-k8s-smpfy branch April 25, 2019 18:31
siggy added a commit that referenced this pull request Apr 25, 2019
The `linkerd check --proxy` command checks for proxies in all
namespaces, if the `--namespace` flag is not set. PR #2747 modified the
behavior of `KubernetesAPI.NamespaceExists`. Previously it would succeed
if given an emptry string for a namespace. Now it fails with a
`resource name may not be empty` error (for k8s server `v1.10.11`), or a
not found error (for our fake test client).

Modify the data plane proxy namespace check to return success if the
namespace is not set.

Signed-off-by: Andrew Seigner <[email protected]>

fix lint

Signed-off-by: Andrew Seigner <[email protected]>
siggy added a commit that referenced this pull request Apr 25, 2019
The `linkerd check --proxy` command checks for proxies in all
namespaces, if the `--namespace` flag is not set. PR #2747 modified the
behavior of `KubernetesAPI.NamespaceExists`. Previously it would succeed
if given an emptry string for a namespace. Now it fails with a
`resource name may not be empty` error (for k8s server `v1.10.11`), or a
not found error (for our fake test client).

Modify the data plane proxy namespace check to return success if the
namespace is not set.

Signed-off-by: Andrew Seigner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants