Skip to content

Commit

Permalink
fix pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
eljohnson92 committed Jul 13, 2024
1 parent 851c7e2 commit 259515a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
20 changes: 11 additions & 9 deletions cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"embed"
_ "embed"
"fmt"
"github.com/google/uuid"
"io"
"io/fs"
"path/filepath"
"text/template"
"time"

"github.com/google/uuid"

capiYaml "capi-bootstrap/yaml"

"github.com/k3s-io/cluster-api-k3s/pkg/k3s"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -119,31 +121,31 @@ func GenerateCloudInit(values capiYaml.Substitutions, manifestFS fs.FS, manifest

func generateCertManagerManifest(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/cert-manager.yaml"
return constructFile(filePath, "files/cert-manager.yaml", files, values)
return constructFile(filePath, filepath.Join("files", "cert-manager.yaml"), files, values)
}

func generateCapiOperator(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/capi-operator.yaml"
return constructFile(filePath, "files/capi-operator.yaml", files, values)
return constructFile(filePath, filepath.Join("files", "capi-operator.yaml"), files, values)
}

func generateLinodeCCM(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/linode-ccm.yaml"
localPath := "files/linode/linode-ccm.yaml"
localPath := filepath.Join("files", "linode", "linode-ccm.yaml")
if values.Linode.VPC {
localPath = "files/linode/linode-ccm-vpc.yaml"
localPath = filepath.Join("files", "linode", "linode-ccm-vpc.yaml")
}
return constructFile(filePath, localPath, files, values)
}

func generateK3sProvider(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/capi-k3s.yaml"
return constructFile(filePath, "files/k3s/capi-k3s.yaml", files, values)
return constructFile(filePath, filepath.Join("files", "k3s", "capi-k3s.yaml"), files, values)
}

func generateCapiLinode(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/capi-linode.yaml"
return constructFile(filePath, "files/linode/capi-linode.yaml", files, values)
return constructFile(filePath, filepath.Join("files", "linode", "capi-linode.yaml"), files, values)
}

func generateK3sConfig(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
Expand All @@ -161,7 +163,7 @@ func generateK3sConfig(values capiYaml.Substitutions) (*capiYaml.InitFile, error

func generateCapiPivotMachine(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/var/lib/rancher/k3s/server/manifests/capi-pivot-machine.yaml"
return constructFile(filePath, "files/capi-pivot-machine.yaml", files, values)
return constructFile(filePath, filepath.Join("files", "capi-pivot-machine.yaml"), files, values)
}

func GenerateCapiManifests(manifestFS fs.FS, manifestFile string) (*capiYaml.ParsedManifest, error) {
Expand All @@ -182,7 +184,7 @@ func GenerateCapiManifests(manifestFS fs.FS, manifestFile string) (*capiYaml.Par

func generateInitScript(values capiYaml.Substitutions) (*capiYaml.InitFile, error) {
filePath := "/tmp/init-cluster.sh"
return constructFile(filePath, "files/init-cluster.sh", files, values)
return constructFile(filePath, filepath.Join("files", "init-cluster.sh"), files, values)
}

func templateManifest(filesystem fs.FS, localPath string, templateValues capiYaml.Substitutions) ([]byte, error) {
Expand Down
3 changes: 2 additions & 1 deletion cloudinit/files/init-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ k3s kubectl create secret generic {{{ .ClusterName }}}-token --type=cluster.x-k8
until k3s kubectl get secret {{{ .ClusterName }}}-ca {{{ .ClusterName }}}-cca {{{ .ClusterName }}}-kubeconfig {{{ .ClusterName }}}-token; do sleep 5; done
k3s kubectl label secret {{{ .ClusterName }}}-kubeconfig {{{ .ClusterName }}}-ca {{{ .ClusterName }}}-cca {{{ .ClusterName }}}-token "cluster.x-k8s.io/cluster-name"="{{{ .ClusterName }}}"
until k3s kubectl get kthreescontrolplane {{{ .ClusterName }}}-control-plane; do sleep 10; done
until k3s kubectl get linode-cluster {{{ .ClusterName }}}; do sleep 10; done
rm /var/lib/rancher/k3s/server/manifests/capi-manifests.yaml
k3s kubectl patch machine {{{ .ClusterName }}}-bootstrap --type=json -p "[{\"op\": \"add\", \"path\": \"/metadata/ownerReferences\", \"value\" : [{\"apiVersion\":\"controlplane.cluster.x-k8s.io/v1beta1\",\"blockOwnerDeletion\":true,\"controller\":true,\"kind\":\"KThreesControlPlane\",\"name\":\"{{{ .ClusterName }}}-control-plane\",\"uid\":\"$(k3s kubectl get KThreesControlPlane {{{ .ClusterName }}}-control-plane -ojsonpath='{.metadata.uid}')\"}]}]"
sleep 15
k3s kubectl patch cluster {{{ .ClusterName }}} --type=json -p '[{"op": "replace", "path": "/spec/controlPlaneRef/name", "value": "{{{ .ClusterName }}}-control-plane"}]'
2 changes: 1 addition & 1 deletion cloudinit/files/linode/capi-linode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ metadata:
name: linode
namespace: capl-system
spec:
version: v0.3.0
version: v0.5.0
fetchConfig:
url: https://github.com/linode/cluster-api-provider-linode/releases/latest/infrastructure-components.yaml
configSecret:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/linode/linodego v1.37.0
github.com/spf13/cobra v1.8.0
golang.org/x/oauth2 v0.21.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/cluster-api v1.7.4
Expand Down Expand Up @@ -86,7 +87,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.2 // indirect
k8s.io/apiextensions-apiserver v0.29.3 // indirect
k8s.io/apimachinery v0.30.2 // indirect
Expand Down

0 comments on commit 259515a

Please sign in to comment.