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

fix: add generated target for all node IPs #1119

Merged
merged 12 commits into from
Dec 20, 2024
Merged

fix: add generated target for all node IPs #1119

merged 12 commits into from
Dec 20, 2024

Conversation

catsby
Copy link
Contributor

@catsby catsby commented Dec 12, 2024

Description

Adds a new generator / target called KubeNodes that contains the internal IP addresses of nodes in the cluster.

NOTE: I have no idea (yet) wher the docs/reference/ file changes came from. They appear to be missing on main.

Related Issue

Relates to #970 . Steps to Validate include steps to verify 970 gets fixed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Steps to Validate

Setup and verify behavior of the target

Create a k3d cluster named uds (we use names later for adding nodes):

k3d cluster create uds

Deploy slim-dev:

uds run slim-dev

Create and deploy monitoring layer:

uds run -f ./tasks/create.yaml single-layer-callable --set LAYER=monitoring

uds run -f ./tasks/deploy.yaml single-layer-callable --set LAYER=monitoring

Create and deploy metrics-server layer:

uds run -f ./tasks/create.yaml single-layer-callable --set LAYER=metrics-server

uds run -f ./tasks/deploy.yaml single-layer-callable --set LAYER=metrics-server

Inspect the network policy for scraping of kube nodes:

kubectl describe networkpolicy allow-prometheus-stack-egress-metrics-scraping-of-kube-nodes -n monitoring

The spec: part is the relevant part, and should contain the IPs of the nodes:

Spec:
  PodSelector:     app.kubernetes.io/name=prometheus
  Not affecting ingress traffic
  Allowing egress traffic:
    To Port: <any> (traffic allowed to all ports)
    To:
      IPBlock:
        CIDR: 172.28.0.2/32
        Except:
  Policy Types: Egress

Add a node:

k3d node create extra1 --cluster uds --wait --memory 500M

Verify the internal IP of the new node:

kubectl get nodes -o custom-columns="NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=='InternalIP')].address"

Re-get the netpol to verify the new ip is in the spec: block:

kubectl describe networkpolicy allow-prometheus-stack-egress-metrics-scraping-of-kube-nodes -n monitorin

Should now be something like this:

Spec:
  PodSelector:     app.kubernetes.io/name=prometheus
  Not affecting ingress traffic
  Allowing egress traffic:
    To Port: <any> (traffic allowed to all ports)
    To:
      IPBlock:
        CIDR: 172.28.0.2/32
        Except:
    To:
      IPBlock:
        CIDR: 172.28.0.4/32
        Except:
  Policy Types: Egress

Verify Prometheus can read things

Connect directly to prometheus:

kubectl port-forward -n monitoring svc/kube-prometheus-stack-prometheus 9090:9090

Visit http://localhost:9090/

Execute this expression to see all node/cpu data:

node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate

To see just info from the extra1 node:

node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{node=~"^k3d-extra.*"}

Add a new node:

k3d node create extra2 --cluster uds --wait --memory 500M

Verify the netpol updates:

kubectl describe networkpolicy allow-prometheus-stack-egress-metrics-scraping-of-kube-nodes -n monitorin

Re-execute the Prometheus query from above. It make take a few minutes for extra2 to show up though. Not sure why.

Delete a node and verify the spec updates again:

kubectl delete node k3d-extra1-0 && k3d node delete k3d-extra1-0

Re-reading the netpol should should the removal of that IP

Checklist before merging

@catsby catsby requested a review from a team as a code owner December 12, 2024 22:13
@catsby catsby changed the title fix: Add generated target for all node IPs fix: add generated target for all node IPs Dec 12, 2024
@catsby catsby mentioned this pull request Dec 13, 2024
5 tasks
mjnagel added a commit that referenced this pull request Dec 13, 2024
## Description

The generated docs were moved, but it seems the script to generate them
was not updated to reflect the new location. This PR fixes that.

## Related Issue

Relates to #1119 because at the moment it has docs that shouldn't be
generated in it.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)
- [ ] 
## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [x] [Contributor
Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)
followed

Signed-off-by: catsby <[email protected]>
Co-authored-by: Micah Nagel <[email protected]>
- Update src/pepr/operator/controllers/network/generators/kubeNodes.ts
- chipping away at tests
- wrap fetchKubernetesNodes in a retry
- refactor updateKubeNodes and such to reduce duplication

Signed-off-by: catsby <[email protected]>
@catsby
Copy link
Contributor Author

catsby commented Dec 18, 2024

Rebased with main, and I think I've addressed all the feedback

Copy link
Contributor

@mjnagel mjnagel 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 follow-on comments here, the code logic looks good at this point though (comments are on comments/docs). I'll deploy and validate this resolves the prometheus error, wanted to post these comments first though.

src/pepr/uds-operator-config/values.yaml Show resolved Hide resolved
src/pepr/operator/index.ts Outdated Show resolved Hide resolved
src/pepr/operator/index.ts Outdated Show resolved Hide resolved
mjnagel
mjnagel previously approved these changes Dec 19, 2024
@mjnagel mjnagel enabled auto-merge (squash) December 20, 2024 14:20
@mjnagel mjnagel merged commit 033338b into main Dec 20, 2024
25 checks passed
@mjnagel mjnagel deleted the 970-all-nodes branch December 20, 2024 14:49
mjnagel pushed a commit that referenced this pull request Dec 20, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.33.1](v0.33.0...v0.33.1)
(2024-12-20)


### Bug Fixes

* add generated target for all node IPs
([#1119](#1119))
([033338b](033338b))


### Miscellaneous

* add action to check readiness on renovate PRs before running CI
([#1144](#1144))
([83d81c6](83d81c6))
* **deps:** update codeql action to v3.28.0
([#1146](#1146))
([fe9bccf](fe9bccf))
* **deps:** update k8s-sidecar to v1.28.4
([#1132](#1132))
([b4f15ff](b4f15ff))
* **deps:** update loki
([#1134](#1134))
([56d0e39](56d0e39))
* **deps:** update prometheus-stack (prometheus 3.0.1, operator 0.79.2)
([#949](#949))
([5a35fc6](5a35fc6))
* **deps:** update support-deps
([#1131](#1131))
([4853969](4853969))
* **deps:** update support-deps
([#1138](#1138))
([2764d03](2764d03))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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