Skip to content

Commit f700cd7

Browse files
authored
Merge branch 'platform9:main' into forkmain
2 parents 0428628 + 8ebc1f0 commit f700cd7

6 files changed

Lines changed: 47 additions & 12 deletions

File tree

CLAUDE.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
Cluster API Provider BYOH (BringYourOwnHost) is a Kubernetes infrastructure provider that lets operators declare, provision, and manage Kubernetes clusters on already-provisioned Linux hosts. It decouples node provisioning from host provisioning by running an agent daemon on each BYO host that registers with a management cluster.
88

9+
This repo (`platform9/cluster-api-provider-bringyourownhost`) is Platform9's fork of the upstream `vmware-tanzu/cluster-api-provider-bringyourownhost`. The root Go module keeps the upstream import path (`github.com/vmware-tanzu/cluster-api-provider-bringyourownhost`) for compatibility with existing imports; new Platform9-authored code (`cmd/byohctl`) uses its own module under the `github.com/platform9/...` path instead. Keep this distinction in mind when adding imports — don't assume the whole tree shares one module or one import prefix.
10+
911
## Build & Development Commands
1012

1113
```bash
1214
# Build
1315
make build # Build manager binary to bin/manager
1416
make host-agent-binaries # Build host agent binaries
17+
cd cmd/byohctl && make build # Build byohctl CLI (separate Go module, see Architecture)
1518

1619
# Run tests
17-
make test # All unit tests with coverage
20+
make test # All unit tests with coverage (includes cmd-test)
1821
make controller-test # Controller tests only
1922
make agent-test # Agent tests only
2023
make webhook-test # Webhook tests only
24+
make cmd-test # byohctl tests (cd cmd && go test ./...)
2125
make test-e2e # End-to-end tests (requires a cluster)
2226

2327
# Code quality
@@ -44,11 +48,12 @@ ginkgo -v -focus "description of test" ./controllers/infrastructure/
4448

4549
## Architecture
4650

47-
### Two-Binary Design
51+
### Three-Binary Design
4852

49-
The project produces two binaries:
53+
The project produces three binaries, two of which share the root Go module:
5054
- **Manager** (`main.go`) — runs in the management cluster; reconciles `ByoCluster`, `ByoMachine`, `ByoHost`, and related CRs.
5155
- **Host Agent** (`agent/main.go`) — runs as a daemon on each BYO host; registers the host with the management cluster and drives Kubernetes installation.
56+
- **byohctl** (`cmd/byohctl/`) — operator-facing CLI for onboarding, deauthorizing, and decommissioning a host (`cmd/byohctl/cmd/{onboard,deauthorise,decommission}.go`). Lives in its own Go module (`cmd/go.mod`) with its own `cmd/byohctl/Makefile`; built and tested independently of the root module — see `make cmd-test`.
5257

5358
### Custom Resources (`apis/infrastructure/v1beta1/`)
5459

@@ -103,4 +108,23 @@ Markers in type files (e.g. `// +kubebuilder:object:root=true`) drive controller
103108

104109
## Linting
105110

106-
Config is in `.golangci.yml` (timeout 10 min). Key enabled linters include `gosec`, `staticcheck`, `errcheck`, `gocyclo`, and `depguard`. Run `make lint` before submitting; CI enforces this.
111+
Config is in `.golangci.yml` (v2 schema, timeout 10 min). Key enabled linters include `gosec`, `staticcheck`, `errcheck`, `gocyclo`, and `depguard`. Run `make lint` before submitting; CI enforces this via `golangci-lint-action@v9` pinned to v2.12.2 (`.github/workflows/lint.yml`).
112+
113+
Gotcha: the `golangci-lint` target in the Makefile only installs the binary if `bin/golangci-lint` doesn't already exist, and pins an older v1.64.8 install script — if you have a stale v1 binary in `bin/`, `make lint` will run against the v2-schema config and fail or disagree with CI. Delete `bin/golangci-lint` and re-run `make lint` if results look wrong.
114+
115+
## Licensing
116+
117+
Most existing files carry a VMware copyright header, e.g.:
118+
```go
119+
// Copyright 2021 VMware, Inc. All Rights Reserved.
120+
// SPDX-License-Identifier: Apache-2.0
121+
```
122+
123+
- Never remove or replace an existing copyright header, including VMware's.
124+
- When editing a file going forward, add a Platform9 copyright line above the `SPDX-License-Identifier` line (don't replace the existing one) using the current year:
125+
```go
126+
// Copyright 2021 VMware, Inc. All Rights Reserved.
127+
// Copyright 2026 Platform9, Inc. All Rights Reserved.
128+
// SPDX-License-Identifier: Apache-2.0
129+
```
130+
- New files that have no prior header get a Platform9-only header.

agent/reconciler/host_reconciler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ func (r *HostReconciler) removeAnnotations(ctx context.Context, byoHost *infrast
376376
byoHost.Spec.BootstrapSecret = nil
377377

378378
// Remove UninstallationSecret reference (secret deletion is handled manager-side)
379-
byoHost.Spec.UninstallationSecret = nil
379+
//
380+
// FIXME: Currently we cleanup uninstallation secret from the management plane controller.
381+
// This means we have split-ownership of cleanup between the agent and the management plane controller.
382+
// We should ensure agent's boundary for cleanup remains within the host itself and it should not be modifying the ByoHost CR at all. The management of the ByoHost CR is the management plane's responsibility, until the host decides to "deboard". And even then it may only ask the management plane to initiate the cleanup of the CR, but not do so itself.
383+
// byoHost.Spec.UninstallationSecret = nil
380384

381385
// Remove cluster-name label
382386
delete(byoHost.Labels, clusterv1.ClusterNameLabel)

agent/reconciler/reconciler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ runCmd:
590590
Expect(updatedByoHost.Annotations).NotTo(HaveKey(infrastructurev1beta1.EndPointIPAnnotation))
591591
Expect(updatedByoHost.Annotations).NotTo(HaveKey(infrastructurev1beta1.K8sVersionAnnotation))
592592
Expect(updatedByoHost.Annotations).NotTo(HaveKey(infrastructurev1beta1.BundleLookupBaseRegistryAnnotation))
593-
Expect(updatedByoHost.Spec.UninstallationSecret).To(BeNil(),
593+
Expect(updatedByoHost.Spec.UninstallationSecret).ToNot(BeNil(),
594594
"UninstallationSecret reference should be cleared after successful cleanup")
595595

596596
k8sNodeBootstrapSucceeded := conditions.Get(updatedByoHost, infrastructurev1beta1.K8sNodeBootstrapSucceeded)
@@ -786,7 +786,7 @@ runCmd:
786786
updatedByoHost := &infrastructurev1beta1.ByoHost{}
787787
err := k8sClient.Get(ctx, byoHostLookupKey, updatedByoHost)
788788
Expect(err).ToNot(HaveOccurred())
789-
Expect(updatedByoHost.Spec.UninstallationSecret).To(BeNil())
789+
Expect(updatedByoHost.Spec.UninstallationSecret).ToNot(BeNil())
790790
})
791791

792792
It("should skip uninstallation if skip-installation flag is set", func() {

apis/infrastructure/v1beta1/byohost_webhook.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ func (v *ByoHostValidator) handleCreateUpdate(req *admission.Request) admission.
8383
// An agent's username encodes the host it owns as the third colon-separated segment
8484
// (format: byoh:host:<hostname>). Reject requests where the encoded host does not
8585
// match the target ByoHost — an agent must not create or update another agent's host.
86-
if len(substrs) >= 3 && !strings.Contains(byoHost.Name, substrs[2]) {
87-
return admission.Denied(fmt.Sprintf("%s cannot create/update resource %s", userName, byoHost.Name))
88-
}
86+
87+
// FIXME: We only support token based kubeconfig for now. cert based flow needs a redesign. Disable it for now to allow host onboarding for the time being.
88+
// NOTE: When you're fixing this, see the tests that were skipped as part of the commit that disabled this check.
89+
//
90+
// if len(substrs) >= 3 && !strings.Contains(byoHost.Name, substrs[2]) {
91+
// return admission.Denied(fmt.Sprintf("%s cannot create/update resource %s", userName, byoHost.Name))
92+
// }
8993

9094
return admission.Allowed("")
9195
}

apis/infrastructure/v1beta1/byohost_webhook_internal_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var _ = Describe("ByohostWebhook/Unit", func() {
6666
Expect(err).ShouldNot(HaveOccurred())
6767
})
6868
It("Should reject create request from invalid user", func() {
69+
Skip("feature not implemented yet")
6970
admissionRequest := admissionv1.AdmissionRequest{
7071
Operation: admissionv1.Create,
7172
UserInfo: v1.UserInfo{Username: unauthorizedUser},
@@ -79,6 +80,7 @@ var _ = Describe("ByohostWebhook/Unit", func() {
7980
Expect(string(resp.AdmissionResponse.Result.Reason)).To(Equal(fmt.Sprintf("%s is not a valid agent username", unauthorizedUser)))
8081
})
8182
It("Should reject request from another agent user in the group", func() {
83+
Skip("feature not implemented yet")
8284
admissionRequest := admissionv1.AdmissionRequest{
8385
Operation: admissionv1.Create,
8486
UserInfo: v1.UserInfo{Username: byohHostTwoUser},
@@ -179,6 +181,7 @@ var _ = Describe("ByohostWebhook/Unit", func() {
179181
})
180182

181183
It("Should reject request from another agent user in the group", func() {
184+
Skip("feature not implemented yet")
182185
admissionRequest := admissionv1.AdmissionRequest{
183186
Operation: admissionv1.Update,
184187
UserInfo: v1.UserInfo{Username: byohHostTwoUser},
@@ -307,7 +310,7 @@ func TestByoHostValidator_handleCreateUpdate(t *testing.T) {
307310
{
308311
name: "agent encoding a different host is denied",
309312
userName: byohHostTwoUser,
310-
wantAllow: false,
313+
wantAllow: true, // FIXME: This test should fail when we fix the check.
311314
wantMsg: "byoh:host:host2 cannot create/update resource host1",
312315
},
313316
{

cmd/byohctl/service/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
DefaultFilePerms = 0644
1414

1515
// ByohAgentDebPackageURL is the URL to download the agent package
16-
ByohAgentDebPackageURL = "quay.io/platform9/byoh-agent-deb:0.1.366"
16+
ByohAgentDebPackageURL = "quay.io/platform9/byoh-agent-deb:0.1.423"
1717
// ByohAgentDebPackageFilename is the filename of the agent package
1818
ByohAgentDebPackageFilename = "pf9-byohost-agent.deb"
1919
// ByohAgentServiceName is the name of the agent service

0 commit comments

Comments
 (0)