diff --git a/.github/workflows/test-agent.yml b/.github/workflows/test-agent.yml index 8f93f99ef..5f9cccea7 100644 --- a/.github/workflows/test-agent.yml +++ b/.github/workflows/test-agent.yml @@ -34,5 +34,8 @@ jobs: - name: Install ginkgo run: sudo apt-get install golang-ginkgo-dev + - name: make sure it has permission to clean up directory + run: sudo chmod -R 755 /etc + - name: test agent run: make agent-test diff --git a/Makefile b/Makefile index 84afc8f49..4713bba0f 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ prepare-byoh-docker-host-image: docker build test/e2e -f test/e2e/BYOHDockerFile -t ${BYOH_BASE_IMG} test-e2e: docker-build prepare-byoh-docker-host-image $(GINKGO) cluster-templates ## Run the end-to-end tests - $(GINKGO) -v -trace -tags=e2e -focus="$(GINKGO_FOCUS)" $(_SKIP_ARGS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) $(GINKGO_ARGS) test/e2e -- \ + CONTROL_PLANE_ENDPOINT_IP=172.18.10.151 $(GINKGO) -v -trace -tags=e2e -focus="$(GINKGO_FOCUS)" $(_SKIP_ARGS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) $(GINKGO_ARGS) test/e2e -- \ -e2e.artifacts-folder="$(ARTIFACTS)" \ -e2e.config="$(E2E_CONF_FILE)" \ -e2e.skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP) -e2e.use-existing-cluster=$(USE_EXISTING_CLUSTER) \ diff --git a/PROJECT b/PROJECT index e69ff77e8..a217fbfcf 100644 --- a/PROJECT +++ b/PROJECT @@ -3,7 +3,7 @@ layout: - go.kubebuilder.io/v3 multigroup: true projectName: byoh -repo: github.com/vmware-tanzu/cluster-api-provider-byoh +repo: github.com/vmware-tanzu/cluster-api-provider-bringyourownhost resources: - api: crdVersion: v1 @@ -11,7 +11,7 @@ resources: domain: cluster.x-k8s.io group: infrastructure kind: ByoMachine - path: github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1 + path: github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1 version: v1beta1 - api: crdVersion: v1 @@ -19,7 +19,7 @@ resources: domain: cluster.x-k8s.io group: infrastructure kind: ByoHost - path: github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1 + path: github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1 version: v1beta1 webhooks: validation: true @@ -30,7 +30,7 @@ resources: domain: cluster.x-k8s.io group: infrastructure kind: ByoCluster - path: github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1 + path: github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1 version: v1beta1 - api: crdVersion: v1 @@ -38,6 +38,6 @@ resources: domain: cluster.x-k8s.io group: infrastructure kind: ByoMachineTemplate - path: github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1 + path: github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1 version: v1beta1 version: "3" diff --git a/README.md b/README.md index 282eb5edf..e2dc303e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kubernetes Cluster API Provider BYOH(Bring your own host) -[![lint](https://github.com/vmware-tanzu/cluster-api-provider-byoh/actions/workflows/lint.yml/badge.svg)](https://github.com/vmware-tanzu/cluster-api-provider-byoh/actions/workflows/lint.yml) -[![test](https://github.com/vmware-tanzu/cluster-api-provider-byoh/actions/workflows/main.yml/badge.svg)](https://github.com/vmware-tanzu/cluster-api-provider-byoh/actions/workflows/main.yml) +[![lint](https://github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/actions/workflows/lint.yml/badge.svg)](https://github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/actions/workflows/lint.yml) +[![test](https://github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/actions/workflows/main.yml/badge.svg)](https://github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/actions/workflows/main.yml) ------ @@ -56,4 +56,4 @@ More about development and contributing practices can be found in [`CONTRIBUTING [cluster_api]: https://github.com/kubernetes-sigs/cluster-api -[issue]: https://github.com/vmware-tanzu/cluster-api-provider-byoh/issues +[issue]: https://github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/issues diff --git a/agent/cloudinit/cloudinit.go b/agent/cloudinit/cloudinit.go index 5d382441a..5e6647b13 100644 --- a/agent/cloudinit/cloudinit.go +++ b/agent/cloudinit/cloudinit.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/pkg/errors" - "github.com/vmware-tanzu/cluster-api-provider-byoh/common" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/common" "sigs.k8s.io/yaml" ) diff --git a/agent/cloudinit/cloudinit_integration_test.go b/agent/cloudinit/cloudinit_integration_test.go index 23a27fb20..6fbec265a 100644 --- a/agent/cloudinit/cloudinit_integration_test.go +++ b/agent/cloudinit/cloudinit_integration_test.go @@ -14,9 +14,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/registration" - "github.com/vmware-tanzu/cluster-api-provider-byoh/common" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/registration" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/common" ) var ( diff --git a/agent/cloudinit/cloudinit_test.go b/agent/cloudinit/cloudinit_test.go index a60570d30..b39d5a997 100644 --- a/agent/cloudinit/cloudinit_test.go +++ b/agent/cloudinit/cloudinit_test.go @@ -13,8 +13,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit/cloudinitfakes" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit/cloudinitfakes" ) var _ = Describe("Cloudinit", func() { diff --git a/agent/cloudinit/cloudinitfakes/fake_icmd_runner.go b/agent/cloudinit/cloudinitfakes/fake_icmd_runner.go index 4cd667254..8942db888 100644 --- a/agent/cloudinit/cloudinitfakes/fake_icmd_runner.go +++ b/agent/cloudinit/cloudinitfakes/fake_icmd_runner.go @@ -4,7 +4,7 @@ package cloudinitfakes import ( "sync" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" ) type FakeICmdRunner struct { diff --git a/agent/cloudinit/cloudinitfakes/fake_ifile_writer.go b/agent/cloudinit/cloudinitfakes/fake_ifile_writer.go index 51be982e9..6c678b3b5 100644 --- a/agent/cloudinit/cloudinitfakes/fake_ifile_writer.go +++ b/agent/cloudinit/cloudinitfakes/fake_ifile_writer.go @@ -4,7 +4,7 @@ package cloudinitfakes import ( "sync" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" ) type FakeIFileWriter struct { diff --git a/agent/cloudinit/cloudinitfakes/fake_itemplate_parser.go b/agent/cloudinit/cloudinitfakes/fake_itemplate_parser.go index ee5f9fcd3..d2141e688 100644 --- a/agent/cloudinit/cloudinitfakes/fake_itemplate_parser.go +++ b/agent/cloudinit/cloudinitfakes/fake_itemplate_parser.go @@ -4,7 +4,7 @@ package cloudinitfakes import ( "sync" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" ) type FakeITemplateParser struct { diff --git a/agent/host_agent_suite_test.go b/agent/host_agent_suite_test.go index 29fb4dec7..624935bc0 100644 --- a/agent/host_agent_suite_test.go +++ b/agent/host_agent_suite_test.go @@ -14,7 +14,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" @@ -68,7 +68,7 @@ var _ = BeforeSuite(func() { k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) writeKubeConfig() - pathToHostAgentBinary, err = gexec.Build("github.com/vmware-tanzu/cluster-api-provider-byoh/agent") + pathToHostAgentBinary, err = gexec.Build("github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent") Expect(err).NotTo(HaveOccurred()) }) diff --git a/agent/host_agent_test.go b/agent/host_agent_test.go index 2094f75d4..d594c2748 100644 --- a/agent/host_agent_test.go +++ b/agent/host_agent_test.go @@ -17,8 +17,8 @@ import ( . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" - "github.com/vmware-tanzu/cluster-api-provider-byoh/test/builder" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" ) diff --git a/agent/installer/bundle_builder/Dockerfile b/agent/installer/bundle_builder/Dockerfile index 5d3139d07..0934aeb0c 100644 --- a/agent/installer/bundle_builder/Dockerfile +++ b/agent/installer/bundle_builder/Dockerfile @@ -26,7 +26,7 @@ WORKDIR /bundle-builder COPY *.sh ./ RUN chmod a+x *.sh #Default config -COPY config/ubuntu/20_04/k8s/ /config/ +COPY config/ubuntu/20_04/k8s/1_22 /config/ RUN mkdir /ingredients && mkdir /bundle ENV PATH="/bundle-builder:${PATH}" diff --git a/agent/installer/bundle_builder/build-bundle.sh b/agent/installer/bundle_builder/build-bundle.sh index 289cbd204..d2e52bdbc 100755 --- a/agent/installer/bundle_builder/build-bundle.sh +++ b/agent/installer/bundle_builder/build-bundle.sh @@ -28,13 +28,14 @@ echo Configuration $CONFIG_PATH ls -l $CONFIG_PATH echo Add configuration under well-known name -tar -cvf conf.tar -C $CONFIG_PATH . +(cd $CONFIG_PATH && tar -cvf conf.tar *) +cp $CONFIG_PATH/conf.tar . echo Running kbld mkdir .imgpkg kbld --imgpkg-lock-output .imgpkg/images.yml echo Creating bundle tar -tar -cvf /bundle/bundle.tar . +tar -cvf /bundle/bundle.tar * echo Done diff --git a/agent/installer/bundle_builder/ingredients/deb/download.sh b/agent/installer/bundle_builder/ingredients/deb/download.sh index 4f31295b4..9aa91c8aa 100644 --- a/agent/installer/bundle_builder/ingredients/deb/download.sh +++ b/agent/installer/bundle_builder/ingredients/deb/download.sh @@ -10,7 +10,7 @@ sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl echo Download containerd -curl -OJ https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/cri-containerd-cni-${CONTAINERD_VERSION}-linux-amd64.tar.gz +curl -LOJR https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/cri-containerd-cni-${CONTAINERD_VERSION}-linux-amd64.tar.gz echo Download the Google Cloud public signing key curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg @@ -21,3 +21,5 @@ echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https:/ echo Update apt package index, install kubelet, kubeadm and kubectl sudo apt-get update sudo apt-get download {kubelet,kubeadm,kubectl}:$ARCH=$KUBERNETES_VERSION +sudo apt-get download kubernetes-cni:$ARCH=0.8.7-00 +sudo apt-get download cri-tools:$ARCH=1.19.0-00 diff --git a/agent/installer/bundle_downloader.go b/agent/installer/bundle_downloader.go index 74268d53d..1a4691a97 100644 --- a/agent/installer/bundle_downloader.go +++ b/agent/installer/bundle_downloader.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/cppforlife/go-cli-ui/ui" + "github.com/go-logr/logr" "github.com/k14s/imgpkg/pkg/imgpkg/cmd" ) @@ -22,6 +23,7 @@ var ( type bundleDownloader struct { repoAddr string downloadPath string + logger logr.Logger } // Download is a method that downloads the bundle from repoAddr to downloadPath. @@ -31,11 +33,13 @@ type bundleDownloader struct { // If a cache for the bundle exists, nothing is downloaded. func (bd *bundleDownloader) Download( normalizedOsVersion, - k8sVersion string) error { + k8sVersion string, + tag string) error { return bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + tag, bd.downloadByImgpkg) } @@ -43,6 +47,7 @@ func (bd *bundleDownloader) Download( func (bd *bundleDownloader) DownloadFromRepo( normalizedOsVersion, k8sVersion string, + tag string, downloadByTool func(string, string) error) error { err := ensureDirExist(bd.downloadPath) @@ -50,13 +55,16 @@ func (bd *bundleDownloader) DownloadFromRepo( return err } - bundleDirPath := bd.GetBundleDirPath(k8sVersion) + bundleDirPath := bd.GetBundleDirPath(k8sVersion, tag) // cache hit if checkDirExist(bundleDirPath) { + bd.logger.Info("Cache hit", "path", bundleDirPath) return nil } + bd.logger.Info("Cache miss", "path", bundleDirPath) + dir, err := os.MkdirTemp(bd.downloadPath, "tempBundle") // It is fine if the dir path does not exist. defer os.RemoveAll(dir) @@ -64,7 +72,7 @@ func (bd *bundleDownloader) DownloadFromRepo( return err } - bundleAddr := bd.getBundleAddr(normalizedOsVersion, k8sVersion) + bundleAddr := bd.getBundleAddr(normalizedOsVersion, k8sVersion, tag) err = convertError(downloadByTool(bundleAddr, dir)) if err != nil { return err @@ -77,6 +85,8 @@ func (bd *bundleDownloader) downloadByImgpkg( bundleAddr, bundleDirPath string) error { + bd.logger.Info("Downloading bundle", "from", bundleAddr) + var confUI = ui.NewConfUI(ui.NewNoopLogger()) defer confUI.Flush() @@ -106,8 +116,11 @@ func convertError(err error) error { } // GetBundleDirPath returns the path to directory containing the required bundle. -func (bd *bundleDownloader) GetBundleDirPath(k8sVersion string) string { - return filepath.Join(bd.downloadPath, k8sVersion) +func (bd *bundleDownloader) GetBundleDirPath(k8sVersion, tag string) string { + // Not storing tag as a subdir of k8s because we can't atomically move + // the temp bundle dir to a non-existing dir. + // Using "-" instead of ":" because Windows doesn't like the latter + return fmt.Sprintf("%s-%s", filepath.Join(bd.downloadPath, k8sVersion), tag) } // GetBundleName returns the name of the bundle in normalized format. @@ -116,8 +129,8 @@ func GetBundleName(normalizedOsVersion, k8sVersion string) string { } // getBundleAddr returns the exact address to the bundle in the repo. -func (bd *bundleDownloader) getBundleAddr(normalizedOsVersion, k8sVersion string) string { - return fmt.Sprintf("%s/%s", bd.repoAddr, GetBundleName(normalizedOsVersion, k8sVersion)) +func (bd *bundleDownloader) getBundleAddr(normalizedOsVersion, k8sVersion, tag string) string { + return fmt.Sprintf("%s/%s:%s", bd.repoAddr, GetBundleName(normalizedOsVersion, k8sVersion), tag) } // checkDirExist checks if a dirrectory exists. diff --git a/agent/installer/bundle_downloader_test.go b/agent/installer/bundle_downloader_test.go index daf2d14a2..d2de6eaab 100644 --- a/agent/installer/bundle_downloader_test.go +++ b/agent/installer/bundle_downloader_test.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + "github.com/go-logr/logr" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -34,6 +35,8 @@ var _ = Describe("Byohost Installer Tests", func() { k8sVersion string ) + const testTag = "test-tag" + BeforeEach(func() { normalizedOsVersion = "Ubuntu_20.04.3_x64" k8sVersion = "1.22" @@ -43,7 +46,7 @@ var _ = Describe("Byohost Installer Tests", func() { if err != nil { log.Fatal(err) } - bd = &bundleDownloader{repoAddr, downloadPath} + bd = &bundleDownloader{repoAddr, downloadPath, logr.Discard()} mi = &mockImgpkg{} }) AfterEach(func() { @@ -53,12 +56,12 @@ var _ = Describe("Byohost Installer Tests", func() { } }) Context("When given correct arguments", func() { - It("Should download bundle", func() { // Test download on cache missing err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).ShouldNot((HaveOccurred())) @@ -66,6 +69,7 @@ var _ = Describe("Byohost Installer Tests", func() { err = bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).ShouldNot((HaveOccurred())) Expect(mi.callCount).Should(Equal(1)) @@ -75,6 +79,7 @@ var _ = Describe("Byohost Installer Tests", func() { err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).ShouldNot((HaveOccurred())) }) @@ -85,6 +90,7 @@ var _ = Describe("Byohost Installer Tests", func() { err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).Should((HaveOccurred())) Expect(err.Error()).Should(Equal(ErrBundleDownload.Error())) @@ -94,6 +100,7 @@ var _ = Describe("Byohost Installer Tests", func() { err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).Should((HaveOccurred())) Expect(err.Error()).Should(Equal(ErrBundleDownload.Error())) @@ -103,6 +110,7 @@ var _ = Describe("Byohost Installer Tests", func() { err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).Should((HaveOccurred())) Expect(err.Error()).Should(Equal(ErrBundleDownload.Error())) @@ -112,6 +120,7 @@ var _ = Describe("Byohost Installer Tests", func() { err := bd.DownloadFromRepo( normalizedOsVersion, k8sVersion, + testTag, mi.Get) Expect(err).Should((HaveOccurred())) Expect(err.Error()).Should(Equal(ErrBundleExtract.Error())) diff --git a/agent/installer/cli.go b/agent/installer/cli.go index 0a281f835..67999a4cb 100644 --- a/agent/installer/cli.go +++ b/agent/installer/cli.go @@ -6,20 +6,22 @@ package installer import ( "flag" "fmt" - "k8s.io/klog" + "github.com/go-logr/logr" "k8s.io/klog/klogr" ) var ( - listFlag = flag.Bool("list", false, "List all supported OS and Kubernetes versions") - listBundlesFlag = flag.Bool("listBundles", false, "List the BYOH Bundle names for all supported OS and Kubernetes versions") + listSupportedFlag = flag.Bool("list-supported", false, "List all supported OS and Kubernetes versions") + listBundlesFlag = flag.Bool("list-bundles", false, "List the BYOH Bundle names for all supported OS and Kubernetes versions") detectOSFlag = flag.Bool("detect", false, "Detects the current operating system") installFlag = flag.Bool("install", false, "Install a BYOH Bundle") uninstallFlag = flag.Bool("uninstall", false, "Unnstall a BYOH Bundle") - bundleRepoFlag = flag.String("bundleRepo", "https://projects.registry.vmware.com", "BYOH Bundle Repository. If not set, will look for bundles locally") + bundleRepoFlag = flag.String("bundle-repo", "projects.registry.vmware.com", "BYOH Bundle Repository") + cachePathFlag = flag.String("cache-path", ".", "Path to the local bundle cache") k8sFlag = flag.String("k8s", "1.22.1", "Kubernetes version") - osFlag = flag.String("os", "", "OS. If used with install/uninstall, skip os detection") - previewOSChangesFlag = flag.Bool("previewOSChanges", false, "Preview the install and uninstall changes for the specified OS") + osFlag = flag.String("os", "", "OS. If used with install/uninstall, override os detection") + tagFlag = flag.String("tag", "", "BYOH Bundle tag") + previewOSChangesFlag = flag.Bool("preview-os-changes", false, "Preview the install and uninstall changes for the specified OS") ) const ( @@ -27,35 +29,49 @@ const ( doUninstall = false ) +var ( + klogger logr.Logger +) + func Main() { + klogger = klogr.New() + flag.Parse() - if *listFlag { - list() + if *listSupportedFlag { + listSupported() + return } if *listBundlesFlag { listBundles() + return } if *detectOSFlag { detectOS() + return } if *installFlag { runInstaller(doInstall) + return } if *uninstallFlag { runInstaller(doUninstall) + return } if *previewOSChangesFlag { previewOSChanges() + return } + + fmt.Println("No flag set. See --help") } -func list() { +func listSupported() { for _, os := range ListSupportedOS() { for _, k8s := range ListSupportedK8s(os) { fmt.Printf("%s %s\n", os, k8s) @@ -75,7 +91,7 @@ func detectOS() { osd := osDetector{} os, err := osd.Detect() if err != nil { - fmt.Printf("Error detecting OS %s", err) + klogger.Error(err, "Error detecting OS") return } @@ -83,49 +99,37 @@ func detectOS() { } func runInstaller(install bool) { - klog.InitFlags(nil) - klogger := klogr.New() - - if *bundleRepoFlag == "" { - bd := bundleDownloader{"", "."} - fmt.Printf("Bundle repo not specified. Provide bundle contents in %s\n", bd.GetBundleDirPath(*k8sFlag)) - } - var i *installer var err error if *osFlag != "" { // Override current OS detection - i, err = newUnchecked(*osFlag, *bundleRepoFlag, ".", klogger, &logPrinter{klogger}) + i, err = newUnchecked(*osFlag, *bundleRepoFlag, *cachePathFlag, klogger, &logPrinter{klogger}) if err != nil { - fmt.Println(err) + klogger.Error(err, "unable to create installer") return } } else { - i, err = New("norepo", ".", klogger) + i, err = New(*bundleRepoFlag, *cachePathFlag, klogger) if err != nil { - fmt.Println(err) + klogger.Error(err, "unable to create installer") return } - - // Override preview mode - i.downloadPath = "." - i.repoAddr = *bundleRepoFlag } if install { - err = i.Install(*k8sFlag) + err = i.Install(*k8sFlag, *tagFlag) } else { - err = i.Uninstall(*k8sFlag) + err = i.Uninstall(*k8sFlag, *tagFlag) } if err != nil { - fmt.Println(err) + klogger.Error(err, "error installing/uninstalling") } } func previewOSChanges() { installChanges, uninstallChanges, err := PreviewChanges(*osFlag, *k8sFlag) if err != nil { - fmt.Printf("Error previewing changes for os '%s' k8s '%s' %s", *osFlag, *k8sFlag, err) + klogger.Error(err, "error previewing changes for os", "os", osFlag, "k8s", *k8sFlag) return } diff --git a/agent/installer/cli/main.go b/agent/installer/cli/main.go index 4611ec373..e2f986149 100644 --- a/agent/installer/cli/main.go +++ b/agent/installer/cli/main.go @@ -4,7 +4,7 @@ package main import ( - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/installer" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/installer" ) func main() { diff --git a/agent/installer/installer.go b/agent/installer/installer.go index 353212bb8..a7b93cfa9 100644 --- a/agent/installer/installer.go +++ b/agent/installer/installer.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/go-logr/logr" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/installer/internal/algo" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/installer/internal/algo" ) type Error string @@ -49,28 +49,29 @@ func getSupportedRegistry(bd *bundleDownloader, ob algo.OutputBuilder) registry for _, t := range supportedOsK8s { a := &algo.BaseK8sInstaller{ K8sStepProvider: t.algo, - BundlePath: bd.getBundlePathDirOrPreview(t.k8s), /* empty means preview mode */ - OutputBuilder: ob} + /*BundlePath: will be set when tag is known */ + OutputBuilder: ob} reg.Add(t.os, t.k8s, a) } return reg } -func (bd *bundleDownloader) getBundlePathDirOrPreview(k8s string) string { +func (bd *bundleDownloader) getBundlePathDirOrPreview(k8s, tag string) string { if bd == nil || bd.downloadPath == "" { return "" } - return bd.GetBundleDirPath(k8s) + return bd.GetBundleDirPath(k8s, tag) } -func (bd *bundleDownloader) DownloadOrPreview(os, k8s string) error { +func (bd *bundleDownloader) DownloadOrPreview(os, k8s, tag string) error { if bd == nil || bd.downloadPath == "" { + bd.logger.Info("Running in preview mode, skip bundle download") return nil } - return bd.Download(os, k8s) + return bd.Download(os, k8s, tag) } // New returns an installer that downloads bundles for the current OS from OCI repository with @@ -91,10 +92,6 @@ func New(bundleRepo, downloadPath string, logger logr.Logger) (*installer, error return nil, ErrDetectOs } - // Run in preview mode until we can run the e2e test - downloadPath = "" - bundleRepo = "" - return newUnchecked(os, bundleRepo, downloadPath, logger, &logPrinter{logger}) } @@ -102,7 +99,7 @@ func New(bundleRepo, downloadPath string, logger logr.Logger) (*installer, error // If they are empty, returned installer will runs in preview mode, i.e. // executes everything except the actual commands. func newUnchecked(currentOs, bundleRepo, downloadPath string, logger logr.Logger, outputBuilder algo.OutputBuilder) (*installer, error) { - bd := bundleDownloader{repoAddr: bundleRepo, downloadPath: downloadPath} + bd := bundleDownloader{repoAddr: bundleRepo, downloadPath: downloadPath, logger: logger} reg := getSupportedRegistry(&bd, outputBuilder) if len(reg.ListK8s(currentOs)) == 0 { @@ -117,8 +114,8 @@ func newUnchecked(currentOs, bundleRepo, downloadPath string, logger logr.Logger } // Install installs the specified k8s version on the current OS -func (i *installer) Install(k8sVer string) error { - algoInst, err := i.getAlgoInstallerWithBundle(k8sVer) +func (i *installer) Install(k8sVer, tag string) error { + algoInst, err := i.getAlgoInstallerWithBundle(k8sVer, tag) if err != nil { return err } @@ -131,8 +128,8 @@ func (i *installer) Install(k8sVer string) error { } // Uninstal uninstalls the specified k8s version on the current OS -func (i *installer) Uninstall(k8sVer string) error { - algoInst, err := i.getAlgoInstallerWithBundle(k8sVer) +func (i *installer) Uninstall(k8sVer, tag string) error { + algoInst, err := i.getAlgoInstallerWithBundle(k8sVer, tag) if err != nil { return err } @@ -145,20 +142,24 @@ func (i *installer) Uninstall(k8sVer string) error { } // getAlgoInstallerWithBundle returns an algo.Installer instance and downloads its bundle -func (i *installer) getAlgoInstallerWithBundle(k8sVer string) (osk8sInstaller, error) { +func (i *installer) getAlgoInstallerWithBundle(k8sVer, tag string) (osk8sInstaller, error) { // This OS supports at least 1 k8s version. See New. algoInst := i.algoRegistry.GetInstaller(i.detectedOs, k8sVer) if algoInst == nil { return nil, ErrOsK8sNotSupported } + // copy installer from registry and set BundlePath including tag + // empty means preview mode + algoInstCopy := *algoInst.(*algo.BaseK8sInstaller) + algoInstCopy.BundlePath = i.bundleDownloader.getBundlePathDirOrPreview(k8sVer, tag) - bdErr := i.bundleDownloader.DownloadOrPreview(i.detectedOs, k8sVer) + bdErr := i.bundleDownloader.DownloadOrPreview(i.detectedOs, k8sVer, tag) if bdErr != nil { return nil, bdErr } - return algoInst, nil + return &algoInstCopy, nil } // ListSupportedOS() returns the list of all supported OS-es. Can be invoked on a non-supported OS. @@ -187,10 +188,12 @@ func PreviewChanges(os, k8sVer string) (install, uninstall string, err error) { stepPreviewer := stringPrinter{msgFmt: "# %s"} reg := getSupportedRegistry(&bundleDownloader{}, &stepPreviewer) installer := reg.GetInstaller(os, k8sVer) + if installer == nil { err = ErrOsK8sNotSupported return } + err = installer.(algo.Installer).Install() if err != nil { return diff --git a/agent/installer/installer_test.go b/agent/installer/installer_test.go index a5e07ae6c..50b78d549 100644 --- a/agent/installer/installer_test.go +++ b/agent/installer/installer_test.go @@ -7,10 +7,12 @@ import ( "github.com/go-logr/logr" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/installer/internal/algo" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/installer/internal/algo" ) var _ = Describe("Byohost Installer Tests", func() { + const testTag = "test-tag" + Context("When installer is created for unsupported OS", func() { It("Should return error", func() { _, err := New("repo", "downloadPath", logr.Discard()) @@ -34,10 +36,10 @@ var _ = Describe("Byohost Installer Tests", func() { for _, os := range ListSupportedOS() { i := NewPreviewInstaller(os, nil) - err := i.Install("unsupported-k8s") + err := i.Install("unsupported-k8s", testTag) Expect(err).Should((HaveOccurred())) - err = i.Uninstall("unsupported-k8s") + err = i.Uninstall("unsupported-k8s", testTag) Expect(err).Should((HaveOccurred())) } }) @@ -49,7 +51,7 @@ var _ = Describe("Byohost Installer Tests", func() { { ob := algo.OutputBuilderCounter{} i := NewPreviewInstaller(os, &ob) - err := i.Install(k8s) + err := i.Install(k8s, testTag) Expect(err).ShouldNot((HaveOccurred())) Expect(ob.LogCalledCnt).Should(Equal(24)) } @@ -57,7 +59,7 @@ var _ = Describe("Byohost Installer Tests", func() { { ob := algo.OutputBuilderCounter{} i := NewPreviewInstaller(os, &ob) - err := i.Uninstall(k8s) + err := i.Uninstall(k8s, testTag) Expect(err).ShouldNot((HaveOccurred())) Expect(ob.LogCalledCnt).Should(Equal(24)) } diff --git a/agent/installer/internal/algo/apt_step.go b/agent/installer/internal/algo/apt_step.go index 79a389fc8..e155d0e2f 100755 --- a/agent/installer/internal/algo/apt_step.go +++ b/agent/installer/internal/algo/apt_step.go @@ -19,16 +19,20 @@ func NewAptStepOptional(k *BaseK8sInstaller, aptPkg string) Step { } func NewAptStepEx(k *BaseK8sInstaller, aptPkg string, optional bool) Step { - pkgName := strings.Split(aptPkg, ".")[0] + pkgName := strings.Split(aptPkg, ".")[0] // leave only pkg name, strip .deb pkgAbsolutePath := filepath.Join(k.BundlePath, aptPkg) - pkgCheck := "" + + condCmd := "%s" if optional { - pkgCheck = fmt.Sprintf("test -e %s && ", pkgAbsolutePath) + condCmd = fmt.Sprintf("if [ -f %s ]; then %%s; fi", pkgAbsolutePath) } + doCmd := fmt.Sprintf("dpkg --install '%s'", pkgAbsolutePath) + undoCmd :=fmt.Sprintf("dpkg --purge %s", pkgName) + return &ShellStep{ BaseK8sInstaller: k, Desc: pkgName, - DoCmd: fmt.Sprintf("%sapt install -y '%s'", pkgCheck, pkgAbsolutePath), - UndoCmd: fmt.Sprintf("%sapt remove -y %s", pkgCheck, pkgName)} + DoCmd: fmt.Sprintf(condCmd, doCmd), + UndoCmd: fmt.Sprintf(condCmd, undoCmd)} } diff --git a/agent/installer/internal/algo/ubuntu20_4K8s1_22.go b/agent/installer/internal/algo/ubuntu20_4K8s1_22.go index f292f82c9..2206c7cb0 100755 --- a/agent/installer/internal/algo/ubuntu20_4K8s1_22.go +++ b/agent/installer/internal/algo/ubuntu20_4K8s1_22.go @@ -45,7 +45,7 @@ func (u *Ubuntu20_4K8s1_22) unattendedUpdStep(bki *BaseK8sInstaller) Step { } func (u *Ubuntu20_4K8s1_22) osWideCfgUpdateStep(bki *BaseK8sInstaller) Step { - confAbsolutePath := filepath.Join(u.BundlePath, "conf.tar") + confAbsolutePath := filepath.Join(bki.BundlePath, "conf.tar") doCmd := fmt.Sprintf( "tar -C / -xvf '%s' && sysctl --system", @@ -85,7 +85,7 @@ func (u *Ubuntu20_4K8s1_22) kubeletStep(bki *BaseK8sInstaller) Step { } func (u *Ubuntu20_4K8s1_22) containerdStep(bki *BaseK8sInstaller) Step { - containerdAbsPath := filepath.Join(u.BundlePath, "containerd.tar") + containerdAbsPath := filepath.Join(bki.BundlePath, "containerd.tar") cmdRmDirs := "rm -rf /opt/cni/ && rm -rf /opt/containerd/ && " cmdListTar := fmt.Sprintf("tar tf '%s'", containerdAbsPath) diff --git a/agent/main.go b/agent/main.go index 00840a4b9..1ac31e694 100644 --- a/agent/main.go +++ b/agent/main.go @@ -10,10 +10,10 @@ import ( "os" "strings" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/reconciler" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/registration" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/reconciler" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/registration" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" @@ -72,9 +72,9 @@ func (l *labelFlags) Set(value string) error { } var ( - namespace string - scheme *runtime.Scheme - labels = make(labelFlags) + namespace string + scheme *runtime.Scheme + labels = make(labelFlags) metricsbindaddress string ) @@ -83,7 +83,7 @@ var ( func main() { flag.StringVar(&namespace, "namespace", "default", "Namespace in the management cluster where you would like to register this host") flag.Var(&labels, "label", "labels to attach to the ByoHost CR in the form labelname=labelVal for e.g. '--label site=apac --label cores=2'") - flag.StringVar(&metricsbindaddress,"metricsbindaddress",":8080","metricsbindaddress is the TCP address that the controller should bind to for serving prometheus metrics.It can be set to \"0\" to disable the metrics serving") + flag.StringVar(&metricsbindaddress, "metricsbindaddress", ":8080", "metricsbindaddress is the TCP address that the controller should bind to for serving prometheus metrics.It can be set to \"0\" to disable the metrics serving") klog.InitFlags(nil) flag.Parse() scheme = runtime.NewScheme() diff --git a/agent/reconciler/host_reconciler.go b/agent/reconciler/host_reconciler.go index b9e441d43..03799dcfb 100644 --- a/agent/reconciler/host_reconciler.go +++ b/agent/reconciler/host_reconciler.go @@ -5,11 +5,13 @@ package reconciler import ( "context" + "fmt" "os" "github.com/pkg/errors" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/registration" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/registration" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/common" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" @@ -22,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "github.com/kube-vip/kube-vip/pkg/vip" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" ) type HostReconciler struct { @@ -107,9 +109,11 @@ func (r *HostReconciler) reconcileNormal(ctx context.Context, byoHost *infrastru return ctrl.Result{}, err } - err = r.kubeadmDirCleanup(ctx) + err = r.cleank8sdirectories(ctx) if err != nil { - logger.Error(err, "error cleaning up kubeadm directory, please delete it manually for reconcile to proceed.") + logger.Error(err, "error cleaning up k8s directories, please delete it manually for reconcile to proceed.") + r.Recorder.Event(byoHost, corev1.EventTypeWarning, "CleanK8sDirectoriesFailed", "clean k8s directories failed") + conditions.MarkFalse(byoHost, infrastructurev1beta1.K8sNodeBootstrapSucceeded, infrastructurev1beta1.CleanK8sDirectoriesFailedReason, clusterv1.ConditionSeverityError, "") return ctrl.Result{}, err } @@ -151,12 +155,28 @@ func (r *HostReconciler) SetupWithManager(ctx context.Context, mgr manager.Manag Complete(r) } -// cleanup kubeadm dir to remove any stale config on the host -func (r *HostReconciler) kubeadmDirCleanup(ctx context.Context) error { +// cleanup /run/kubeadm, /etc/cni/net.d dirs to remove any stale config on the host +func (r *HostReconciler) cleank8sdirectories(ctx context.Context) error { logger := ctrl.LoggerFrom(ctx) - logger.Info("cleaning up kubeadm directory") - const kubeadmDir = "/run/kubeadm" - return os.RemoveAll(kubeadmDir) + + dirs := []string{ + "/run/kubeadm/*", + "/etc/cni/net.d/*", + } + + errList := []error{} + for _, dir := range dirs { + logger.Info(fmt.Sprintf("cleaning up directory %s", dir)) + if err := common.RemoveGlob(dir); err != nil { + logger.Error(err, fmt.Sprintf("failed to clean up directory %s", dir)) + errList = append(errList, err) + } + } + + if len(errList) > 0 { + return errors.New("not all k8s directories are cleaned up") + } + return nil } func (r *HostReconciler) hostCleanUp(ctx context.Context, byoHost *infrastructurev1beta1.ByoHost) error { diff --git a/agent/reconciler/reconciler_suite_test.go b/agent/reconciler/reconciler_suite_test.go index 1a80d73f5..3d5fbfc4a 100644 --- a/agent/reconciler/reconciler_suite_test.go +++ b/agent/reconciler/reconciler_suite_test.go @@ -10,8 +10,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit/cloudinitfakes" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit/cloudinitfakes" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" diff --git a/agent/reconciler/reconciler_test.go b/agent/reconciler/reconciler_test.go index b7f7c4e17..4c47834b3 100644 --- a/agent/reconciler/reconciler_test.go +++ b/agent/reconciler/reconciler_test.go @@ -10,10 +10,10 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/cloudinit/cloudinitfakes" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" - "github.com/vmware-tanzu/cluster-api-provider-byoh/test/builder" - eventutils "github.com/vmware-tanzu/cluster-api-provider-byoh/test/utils/events" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit/cloudinitfakes" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" + eventutils "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/utils/events" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" diff --git a/agent/registration/host_registrar.go b/agent/registration/host_registrar.go index c20ab41ef..a424c5214 100644 --- a/agent/registration/host_registrar.go +++ b/agent/registration/host_registrar.go @@ -8,7 +8,7 @@ import ( "net" "github.com/jackpal/gateway" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" diff --git a/apis/infrastructure/v1beta1/condition_consts.go b/apis/infrastructure/v1beta1/condition_consts.go index 02bf0c4f6..3e075c7bf 100644 --- a/apis/infrastructure/v1beta1/condition_consts.go +++ b/apis/infrastructure/v1beta1/condition_consts.go @@ -26,6 +26,11 @@ const ( // This secret is available on byohost.Spec.BootstrapSecret field BootstrapDataSecretUnavailableReason = "BootstrapDataSecretUnavailable" + // CleanK8sDirectoriesFailedReason indicates that clean k8s directories failed for some reason, please + // delete it manually for reconcile to proceed. + // The cleaned directories are /run/kubeadm and /etc/cni/net.d + CleanK8sDirectoriesFailedReason = "CleanK8sDirectoriesFailed" + // CloudInitExecutionFailedReason indicates that cloudinit failed to parse and execute the directives // that are part of the cloud-config file CloudInitExecutionFailedReason = "CloudInitExecutionFailed" diff --git a/common/utils.go b/common/utils.go index d0e834c4a..9f1e029d7 100644 --- a/common/utils.go +++ b/common/utils.go @@ -8,6 +8,8 @@ import ( "compress/gzip" "io" "math/rand" + "os" + "path/filepath" "time" "github.com/pkg/errors" @@ -63,3 +65,17 @@ func GunzipData(data []byte) ([]byte, error) { return resB.Bytes(), nil } + +func RemoveGlob(path string) error { + contents, err := filepath.Glob(path) + if err != nil { + return err + } + for _, item := range contents { + err = os.RemoveAll(item) + if err != nil { + return err + } + } + return nil +} diff --git a/controllers/infrastructure/byocluster_controller.go b/controllers/infrastructure/byocluster_controller.go index bfd111a9f..2a6bfced7 100644 --- a/controllers/infrastructure/byocluster_controller.go +++ b/controllers/infrastructure/byocluster_controller.go @@ -19,7 +19,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" "github.com/pkg/errors" - infrav1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrav1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" clusterutilv1 "sigs.k8s.io/cluster-api/util" diff --git a/controllers/infrastructure/byohost_controller.go b/controllers/infrastructure/byohost_controller.go index 5ccfa9312..63dda70b6 100644 --- a/controllers/infrastructure/byohost_controller.go +++ b/controllers/infrastructure/byohost_controller.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" ) // ByoHostReconciler reconciles a ByoHost object diff --git a/controllers/infrastructure/byomachine_controller.go b/controllers/infrastructure/byomachine_controller.go index 2727a231d..439aed036 100644 --- a/controllers/infrastructure/byomachine_controller.go +++ b/controllers/infrastructure/byomachine_controller.go @@ -30,7 +30,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" "github.com/go-logr/logr" - infrav1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrav1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/controllers/infrastructure/byomachine_controller_test.go b/controllers/infrastructure/byomachine_controller_test.go index c5db7df79..08ab494a4 100644 --- a/controllers/infrastructure/byomachine_controller_test.go +++ b/controllers/infrastructure/byomachine_controller_test.go @@ -10,9 +10,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" - "github.com/vmware-tanzu/cluster-api-provider-byoh/test/builder" - eventutils "github.com/vmware-tanzu/cluster-api-provider-byoh/test/utils/events" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" + eventutils "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/utils/events" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" diff --git a/controllers/infrastructure/byomachine_scope.go b/controllers/infrastructure/byomachine_scope.go index a298f214a..4785295a1 100644 --- a/controllers/infrastructure/byomachine_scope.go +++ b/controllers/infrastructure/byomachine_scope.go @@ -5,7 +5,7 @@ package controllers import ( "github.com/pkg/errors" - infrav1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrav1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/patch" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/controllers/infrastructure/byomachinetemplate_controller.go b/controllers/infrastructure/byomachinetemplate_controller.go index f18488a1f..fee430b14 100644 --- a/controllers/infrastructure/byomachinetemplate_controller.go +++ b/controllers/infrastructure/byomachinetemplate_controller.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" ) // ByoMachineTemplateReconciler reconciles a ByoMachineTemplate object diff --git a/controllers/infrastructure/suite_test.go b/controllers/infrastructure/suite_test.go index 350918363..430b6e86c 100644 --- a/controllers/infrastructure/suite_test.go +++ b/controllers/infrastructure/suite_test.go @@ -21,8 +21,8 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" - "github.com/vmware-tanzu/cluster-api-provider-byoh/test/builder" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" //+kubebuilder:scaffold:imports diff --git a/docs/local_dev.md b/docs/local_dev.md index 19de8cb3c..09747ea51 100644 --- a/docs/local_dev.md +++ b/docs/local_dev.md @@ -134,7 +134,7 @@ export NAMESPACE="default" export KUBERNETES_VERSION="v1.22.0" export CONTROL_PLANE_MACHINE_COUNT=1 export WORKER_MACHINE_COUNT=1 -export CONTROL_PLANE_ENDPOINT= +export CONTROL_PLANE_ENDPOINT_IP= ``` From ```cluster-api-provider-bringyourownhost``` folder diff --git a/go.mod b/go.mod index 191a805f1..c5b5692e5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/vmware-tanzu/cluster-api-provider-byoh +module github.com/vmware-tanzu/cluster-api-provider-bringyourownhost go 1.16 diff --git a/main.go b/main.go index 87a1d4c98..56a89415c 100644 --- a/main.go +++ b/main.go @@ -21,9 +21,9 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" - byohcontrollers "github.com/vmware-tanzu/cluster-api-provider-byoh/controllers/infrastructure" + byohcontrollers "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/controllers/infrastructure" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" //+kubebuilder:scaffold:imports clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/remote" diff --git a/test/builder/builders.go b/test/builder/builders.go index d843f2fc3..e2600a3d1 100644 --- a/test/builder/builders.go +++ b/test/builder/builders.go @@ -4,7 +4,7 @@ package builder import ( - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" diff --git a/test/e2e/byohost_reuse_test.go b/test/e2e/byohost_reuse_test.go index 9a52f621e..4d4ac3e25 100644 --- a/test/e2e/byohost_reuse_test.go +++ b/test/e2e/byohost_reuse_test.go @@ -13,7 +13,7 @@ import ( "github.com/docker/docker/client" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" k8stypes "k8s.io/apimachinery/pkg/types" "k8s.io/utils/pointer" diff --git a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template-byoh.yaml b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template-byoh.yaml index ba67e3004..dc709c1c2 100644 --- a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template-byoh.yaml +++ b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template-byoh.yaml @@ -82,7 +82,7 @@ spec: - name: vip_leaderelection value: "true" - name: vip_address - value: ${CONTROL_PLANE_ENDPOINT} + value: ${CONTROL_PLANE_ENDPOINT_IP} - name: vip_interface value: {{ .DefaultNetworkInterfaceName }} - name: vip_leaseduration diff --git a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template.yaml b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template.yaml index 6bb324e53..c99bca321 100644 --- a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template.yaml +++ b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-template.yaml @@ -119,7 +119,7 @@ spec: - name: vip_leaderelection value: "true" - name: vip_address - value: 172.18.10.10 + value: ${CONTROL_PLANE_ENDPOINT_IP} - name: vip_interface value: {{ .DefaultNetworkInterfaceName }} - name: vip_leaseduration @@ -184,7 +184,7 @@ metadata: name: ${CLUSTER_NAME} spec: controlPlaneEndpoint: - host: 172.18.10.10 + host: ${CONTROL_PLANE_ENDPOINT_IP} port: 6443 --- apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 diff --git a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-with-kcp.yaml b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-with-kcp.yaml index 65413e8d3..225499f43 100644 --- a/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-with-kcp.yaml +++ b/test/e2e/data/infrastructure-provider-byoh/v1beta1/cluster-with-kcp.yaml @@ -28,7 +28,7 @@ metadata: name: ${CLUSTER_NAME} spec: controlPlaneEndpoint: - host: 172.18.10.10 + host: ${CONTROL_PLANE_ENDPOINT_IP} port: 6443 --- apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 @@ -77,7 +77,7 @@ spec: - name: vip_leaderelection value: "true" - name: vip_address - value: 172.18.10.10 + value: ${CONTROL_PLANE_ENDPOINT_IP} - name: vip_interface value: {{ .DefaultNetworkInterfaceName }} - name: vip_leaseduration diff --git a/test/e2e/e2e_docker_helper.go b/test/e2e/e2e_docker_helper.go index c28bca048..42659ab93 100644 --- a/test/e2e/e2e_docker_helper.go +++ b/test/e2e/e2e_docker_helper.go @@ -154,7 +154,7 @@ func setupByoDockerHost(ctx context.Context, clusterConName, byoHostName, namesp Expect(dockerClient.ContainerStart(ctx, byohost.ID, types.ContainerStartOptions{})).NotTo(HaveOccurred()) - pathToHostAgentBinary, err := gexec.Build("github.com/vmware-tanzu/cluster-api-provider-byoh/agent") + pathToHostAgentBinary, err := gexec.Build("github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent") Expect(err).NotTo(HaveOccurred()) config := cpConfig{ diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 3e12113af..fdc60c024 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -14,7 +14,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - infraproviderv1 "github.com/vmware-tanzu/cluster-api-provider-byoh/apis/infrastructure/v1beta1" + infraproviderv1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"