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

[WIP] Adding fixes for pf9 changes #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .
docker build --network host -t ${IMG} .

docker-push: ## Push docker image with the manager.
docker push ${IMG}
Expand Down Expand Up @@ -220,7 +220,7 @@ host-agent-binaries: ## Builds the binaries for the host-agent

host-agent-binary: $(RELEASE_DIR)
docker run \
--rm \
--rm --network host \
-e CGO_ENABLED=0 \
-e GOOS=$(GOOS) \
-e GOARCH=$(GOARCH) \
Expand Down
6 changes: 3 additions & 3 deletions agent/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type Files struct {
}

// Execute performs the following operations on the bootstrap script
// - parse the script to get the cloudinit data
// - execute the write_files directive
// - execute the run_cmd directive
// - parse the script to get the cloudinit data
// - execute the write_files directive
// - execute the run_cmd directive
func (se ScriptExecutor) Execute(bootstrapScript string) error {
cloudInitData := bootstrapConfig{}
if err := yaml.Unmarshal([]byte(bootstrapScript), &cloudInitData); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import (
// labelFlags is a flag that holds a map of label key values.
// One or more key value pairs can be passed using the same flag
// The following example sets labelFlags with two items:
// -label "key1=value1" -label "key2=value2"
//
// -label "key1=value1" -label "key2=value2"
type labelFlags map[string]string

// String implements flag.Value interface
Expand All @@ -51,7 +52,7 @@ func (l *labelFlags) String() string {
}

// Set implements flag.Value interface
//nolint: gomnd
// nolint: gomnd
func (l *labelFlags) Set(value string) error {
// account for comma-separated key-value pairs in a single invocation
if len(strings.Split(value, ",")) > 1 {
Expand Down
2 changes: 1 addition & 1 deletion apis/infrastructure/v1beta1/byohost_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ByoHostValidator struct {
// To allow byoh manager service account to patch ByoHost CR
const managerServiceAccount = "system:serviceaccount:byoh-system:byoh-controller-manager"

//nolint: gocritic
// nolint: gocritic
// Handle handles all the requests for ByoHost resource
func (v *ByoHostValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
var response admission.Response
Expand Down
4 changes: 2 additions & 2 deletions apis/infrastructure/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

// Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
//+kubebuilder:object:generate=true
//+groupName=infrastructure.cluster.x-k8s.io
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1beta1

import (
Expand Down
5 changes: 4 additions & 1 deletion controllers/infrastructure/k8sinstallerconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ func (r *K8sInstallerConfigReconciler) storeInstallationData(ctx context.Context
logger := scope.Logger
logger.Info("creating installation secret")

// Currently the secret name is set to byomachine name, but both kubeadm control plan
// & byoh try to create secret with same name. Changing secret name
secretName := "byoinstall-" + scope.Config.Name
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: scope.Config.Name,
Name: secretName,
Namespace: scope.Config.Namespace,
Labels: map[string]string{
clusterv1.ClusterNameLabel: scope.Cluster.Name,
Expand Down
218 changes: 218 additions & 0 deletions docs/sample/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
name: byoh-cluster-md-0
namespace: byoh
spec:
template:
spec: {}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
labels:
cni: byoh-cluster-crs-0
crs: "true"
name: byoh-cluster
namespace: byoh
spec:
clusterNetwork:
pods:
cidrBlocks:
- 192.168.0.0/16
serviceDomain: cluster.local
services:
cidrBlocks:
- 10.128.0.0/12
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: byoh-cluster-control-plane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoCluster
name: byoh-cluster
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: byoh-cluster-md-0
namespace: byoh
spec:
clusterName: byoh-cluster
replicas: 1
selector:
matchLabels: null
template:
metadata:
labels:
nodepool: pool1
spec:
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
name: byoh-cluster-md-0
clusterName: byoh-cluster
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoMachineTemplate
name: byoh-cluster-md-0
version: v1.26.6
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
labels:
nodepool: pool0
name: byoh-cluster-control-plane
namespace: byoh
spec:
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
certSANs:
- localhost
- 127.0.0.1
- 0.0.0.0
- host.docker.internal
controllerManager:
extraArgs:
enable-hostpath-provisioner: "true"
files:
- content: |
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
name: kube-vip
namespace: kube-system
spec:
containers:
- args:
- manager
env:
- name: cp_enable
value: "true"
- name: vip_arp
value: "true"
- name: vip_leaderelection
value: "true"
- name: vip_address
value: 10.149.106.217
- name: vip_interface
value: {{ .DefaultNetworkInterfaceName }}
- name: vip_leaseduration
value: "15"
- name: vip_renewdeadline
value: "10"
- name: vip_retryperiod
value: "2"
image: ghcr.io/kube-vip/kube-vip:v0.5.0
imagePullPolicy: IfNotPresent
name: kube-vip
resources: {}
securityContext:
capabilities:
add:
- NET_ADMIN
- NET_RAW
volumeMounts:
- mountPath: /etc/kubernetes/admin.conf
name: kubeconfig
hostNetwork: true
hostAliases:
- hostnames:
- kubernetes
ip: 127.0.0.1
volumes:
- hostPath:
path: /etc/kubernetes/admin.conf
type: FileOrCreate
name: kubeconfig
status: {}
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
initConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
ignorePreflightErrors:
- Swap
- DirAvailable--etc-kubernetes-manifests
- FileAvailable--etc-kubernetes-kubelet.conf
joinConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
ignorePreflightErrors:
- Swap
- DirAvailable--etc-kubernetes-manifests
- FileAvailable--etc-kubernetes-kubelet.conf
machineTemplate:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoMachineTemplate
name: byoh-cluster-control-plane
namespace: byoh
replicas: 1
version: v1.26.6
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoCluster
metadata:
name: byoh-cluster
namespace: byoh
spec:
bundleLookupBaseRegistry: projects.registry.vmware.com/cluster_api_provider_bringyourownhost
controlPlaneEndpoint:
host: 10.149.106.217
port: 6443
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoMachineTemplate
metadata:
name: byoh-cluster-control-plane
namespace: byoh
spec:
template:
spec:
installerRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: K8sInstallerConfigTemplate
name: byoh-cluster-control-plane
namespace: byoh
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: ByoMachineTemplate
metadata:
name: byoh-cluster-md-0
namespace: byoh
spec:
template:
spec:
installerRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: K8sInstallerConfigTemplate
name: byoh-cluster-md-0
namespace: byoh
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: K8sInstallerConfigTemplate
metadata:
name: byoh-cluster-control-plane
namespace: byoh
spec:
template:
spec:
bundleRepo: projects.registry.vmware.com/cluster_api_provider_bringyourownhost
bundleType: k8s
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: K8sInstallerConfigTemplate
metadata:
name: byoh-cluster-md-0
namespace: byoh
spec:
template:
spec:
bundleRepo: projects.registry.vmware.com/cluster_api_provider_bringyourownhost
bundleType: k8s
31 changes: 31 additions & 0 deletions docs/sample/generate-bootstrap-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/bash

NAMESPACE=byoh
SERVICE_ACCOUNT=default
CLUSTER_NAME=$(kubectl config view --minify -o jsonpath='{.clusters[0].name}')
CLUSTER_SERVER=https://10.149.106.220:443
SECRET_NAME=$(kubectl get secret -n $NAMESPACE -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='$SERVICE_ACCOUNT')].metadata.name}")
CA_DATA=$(kubectl get secret $SECRET_NAME -n $NAMESPACE -o jsonpath='{.data.ca\.crt}')
TOKEN=$(kubectl get secret $SECRET_NAME -n $NAMESPACE -o jsonpath='{.data.token}' | base64 --decode)

cat <<EOF > bootstrap-kubeconfig.yaml
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: ${CA_DATA}
server: ${CLUSTER_SERVER}
name: ${CLUSTER_NAME}
contexts:
- context:
cluster: ${CLUSTER_NAME}
namespace: ${NAMESPACE}
user: ${SERVICE_ACCOUNT}
name: ${SERVICE_ACCOUNT}-${NAMESPACE}
current-context: ${SERVICE_ACCOUNT}-${NAMESPACE}
users:
- name: ${SERVICE_ACCOUNT}
user:
token: ${TOKEN}
EOF

13 changes: 13 additions & 0 deletions docs/sample/kamaji_clusterrolebindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: byo-cluster-patch-clusterrolebinding
subjects:
- kind: ServiceAccount
name: capi-kamaji-controller-manager
namespace: kamaji-system
roleRef:
kind: ClusterRole
name: byo-cluster-patch-clusterrole
apiGroup: rbac.authorization.k8s.io

9 changes: 9 additions & 0 deletions docs/sample/kamaji_clusterroles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: byo-cluster-patch-clusterrole
rules:
- apiGroups: ["infrastructure.cluster.x-k8s.io"]
resources: ["byoclusters", "byoclusters/status"]
verbs: ["patch"]

24 changes: 24 additions & 0 deletions docs/sample/rbac_csr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: byoh
name: certificate-manager
rules:
- apiGroups: ["certificates.k8s.io"]
resources: ["certificatesigningrequests"]
verbs: ["create", "get", "list", "watch", "approve", "issue"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: bind-certificate-manager
namespace: byoh
subjects:
- kind: ServiceAccount
name: default
namespace: byoh
roleRef:
kind: Role
name: certificate-manager
apiGroup: rbac.authorization.k8s.io

Loading