Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes back-end client #82

Merged
merged 2 commits into from
May 9, 2022

Conversation

chrisdoherty4
Copy link
Member

@chrisdoherty4 chrisdoherty4 commented Apr 15, 2022

Description

Builds on #95 (rebased after PR was created)

This feature builds on #81 and realizes the Hegel portion of the Kubernetes back-end proposal.

Having generalized the client used to acquire metadata, this PR implements a Kubernetes client that leverages an internal client caching mechanism so as to reduce load on the Kubernetes API Server.

Additionally, I put some effort into reworking the Hegel Dockerfile so it could leverage layer caching for Go module dependencies and added an image build command to the Makefile.

The Watch API for the client is unimplemented and scheduled for a follow up. This is so we can get off the ground for machine provisioning. The Watch API is used for subscription capabilities so doesn't feature in metadata retrieval.

How Has This Been Tested?

Built and ran the image with the Kubernetes back-end enabled talking to a KinD cluster containing the necessary CRDs and a Hardware resource.

How are existing users impacted? What migration steps/scripts do we need?

None. Users enable the Kubernetes back-end by setting the DATA_MODEL_VERSION=kubernetes plus some additional env vars.

Future work

  • Implement the Watch API for consistency with other back-ends.

@chrisdoherty4 chrisdoherty4 changed the title Add Kubernetes back-end client. Add Kubernetes back-end client Apr 15, 2022
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 3 times, most recently from 2377d79 to 93b3de6 Compare April 15, 2022 15:49
hardware/kubernetes.go Outdated Show resolved Hide resolved
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

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

A few questions, and some cleanup.

hardware/client.go Outdated Show resolved Hide resolved
hardware/kubernetes.go Outdated Show resolved Hide resolved
hardware/kubernetes.go Show resolved Hide resolved
hardware/kubernetes.go Outdated Show resolved Hide resolved
hardware/kubernetes_test.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 5 times, most recently from 2547eda to 4bc9339 Compare April 17, 2022 02:19
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from 3c042da to 3e0cd30 Compare April 18, 2022 13:42
@codecov
Copy link

codecov bot commented Apr 18, 2022

Codecov Report

Merging #82 (9fa3d0c) into main (50983c3) will decrease coverage by 7.64%.
The diff coverage is 42.44%.

❗ Current head 9fa3d0c differs from pull request most recent head f6fccce. Consider uploading reports for the commit f6fccce to get more accurate results

@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
- Coverage   50.00%   42.35%   -7.65%     
==========================================
  Files           3        6       +3     
  Lines         374      595     +221     
==========================================
+ Hits          187      252      +65     
- Misses        155      311     +156     
  Partials       32       32              
Impacted Files Coverage Δ
hardware/client.go 0.00% <0.00%> (ø)
grpc/server.go 56.96% <20.00%> (+10.75%) ⬆️
http/handlers.go 44.56% <36.36%> (-1.00%) ⬇️
hardware/kubernetes_client.go 46.15% <46.15%> (ø)
http/server.go 88.88% <88.88%> (ø)
hardware/export.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50983c3...f6fccce. Read the comment docs.

@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from 308bcf3 to 360938c Compare April 18, 2022 14:36
@chrisdoherty4 chrisdoherty4 marked this pull request as ready for review April 18, 2022 14:38
Copy link
Member

@displague displague left a comment

Choose a reason for hiding this comment

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

I took an initial look to get a sense of what's in flux and left a few questions.

.golangci.yml Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
hardware/kubernetes_client.go Outdated Show resolved Hide resolved
hardware/kubernetes_client_test.go Outdated Show resolved Hide resolved
hardware/kubernetes_client.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from bc16c9c to bb999a9 Compare April 18, 2022 19:21
@chrisdoherty4 chrisdoherty4 requested a review from displague April 18, 2022 19:22
@mmlb mmlb added the do-not-merge Signal to Mergify to block merging of the PR. label Apr 18, 2022
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 2 times, most recently from 291dfe6 to e2f8bad Compare April 19, 2022 16:10
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from e2f8bad to c8a1202 Compare April 21, 2022 11:43
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from 4069e86 to 0e7bcd7 Compare April 21, 2022 12:05
micahhausler
micahhausler previously approved these changes Apr 21, 2022
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

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

LGTM modulo minor nits, and pending merge of tinkerbell/tink#573

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
hardware/kubernetes_client.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 2 times, most recently from 236bb9c to d5ea9ab Compare April 27, 2022 18:49
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from d5ea9ab to 326c59a Compare April 29, 2022 11:44
go.mod Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 6 times, most recently from 1c5944d to 7679986 Compare May 6, 2022 19:30
@chrisdoherty4 chrisdoherty4 removed the do-not-merge Signal to Mergify to block merging of the PR. label May 6, 2022
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from 7679986 to 8ee9572 Compare May 6, 2022 19:32
The Kubernetes back-end client enables Hegel to talk to a Kubernetes API
Server to retrieve Hardware metadata from CRDs available in the Tink
project.

This realizes the Hegel portion of proposal 0026.

Signed-off-by: Chris Doherty <[email protected]>
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch 2 times, most recently from 5407406 to b6787b8 Compare May 6, 2022 19:45
hardware/kubernetes_client.go Outdated Show resolved Hide resolved
}

managerCtx, cancel := context.WithCancel(context.Background())
go func() {
Copy link
Member

Choose a reason for hiding this comment

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

hmmm...removing this goroutine from this function might be something to consider. The name suggests that it is a constructor and having a constructor start a goroutine seems a bit unusual, could be just me though.

refs: 1, 2

Copy link
Member Author

Choose a reason for hiding this comment

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

Generally I agree. The way the app is designed though makes this difficult to do. The NewClient() call is a factory function returning an interface so anything that needs to be done for a given implementation must be done during that call. Without re-designing this factory I don't think there's much I can do.

hardware/kubernetes_client.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/impl-kubernetes-client branch from b6787b8 to 26c8747 Compare May 7, 2022 15:05
Http handlers require a specific metadata format for querying using jq.
The metadata format of the Kubernetes object isn't equivilent so we
create an explicit mapping. This has the side effect of being much
clearer and intentional about the serialization of metadata.

Signed-off-by: Chris Doherty <[email protected]>
Copy link
Member

@jacobweinstock jacobweinstock left a comment

Choose a reason for hiding this comment

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

lgtm

@jacobweinstock jacobweinstock added the ready-to-merge Signal to Mergify to merge the PR. label May 9, 2022
@mergify mergify bot merged commit 7285eb8 into tinkerbell:main May 9, 2022
mergify bot added a commit that referenced this pull request May 9, 2022
Builds on #82 

The hardware clients has 3 implementations with a fourth, file based for testing, being written. This change introduces a simple source file split to reduce cognitive load.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants