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

chore: add debug logging to endpointslice watch #359

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/pepr/operator/controllers/network/generators/kubeAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { V1NetworkPolicyPeer } from "@kubernetes/client-node";
import { K8s, Log, R, kind } from "pepr";
import { K8s, kind, Log, R } from "pepr";

import { RemoteGenerated } from "../../../crd";
import { anywhere } from "./anywhere";
Expand Down Expand Up @@ -36,17 +36,33 @@ export function kubeAPI() {
* @param slice The EndpointSlice for the API server
*/
export async function updateAPIServerCIDRFromEndpointSlice(slice: kind.EndpointSlice) {
const svc = await K8s(kind.Service).InNamespace("default").Get("kubernetes");
await updateAPIServerCIDR(slice, svc);
try {
Log.debug(
"Processing watch for endpointslices, getting k8s service for updating API server CIDR",
);
const svc = await K8s(kind.Service).InNamespace("default").Get("kubernetes");
await updateAPIServerCIDR(slice, svc);
} catch (err) {
const msg = "Failed to update network policies from endpoint slice watch";
Log.error({ err }, msg);
}
}

/**
* When the kubernetes Service is created or updated, update the API server CIDR
* @param svc The Service for the API server
*/
export async function updateAPIServerCIDRFromService(svc: kind.Service) {
const slice = await K8s(kind.EndpointSlice).InNamespace("default").Get("kubernetes");
await updateAPIServerCIDR(slice, svc);
try {
Log.debug(
"Processing watch for api service, getting endpoint slices for updating API server CIDR",
);
const slice = await K8s(kind.EndpointSlice).InNamespace("default").Get("kubernetes");
await updateAPIServerCIDR(slice, svc);
} catch (err) {
const msg = "Failed to update network policies from api service watch";
Log.error({ err }, msg);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pepr/operator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ When(a.EndpointSlice)
.IsCreatedOrUpdated()
.InNamespace("default")
.WithName("kubernetes")
.Watch(updateAPIServerCIDRFromEndpointSlice);
.Reconcile(updateAPIServerCIDRFromEndpointSlice);

// Watch for changes to the API server Service and update the API server CIDR
When(a.Service)
Expand Down