Skip to content

Commit

Permalink
Merge branch 'hainstaller-algo-test-rollback' of github.com:georgieva…
Browse files Browse the repository at this point in the history
…VMW/cluster-api-provider-bringyourownhost into hainstaller-algo-test-rollback
  • Loading branch information
georgievaVMW committed Nov 3, 2021
2 parents f688f85 + 0b64574 commit 40b1e5c
Show file tree
Hide file tree
Showing 47 changed files with 227 additions and 145 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
10 changes: 5 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ 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
namespaced: true
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
namespaced: true
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
Expand All @@ -30,14 +30,14 @@ 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
namespaced: true
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"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

------

Expand Down Expand Up @@ -56,4 +56,4 @@ More about development and contributing practices can be found in [`CONTRIBUTING
<!-- References -->

[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
2 changes: 1 addition & 1 deletion agent/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions agent/cloudinit/cloudinit_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions agent/cloudinit/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion agent/cloudinit/cloudinitfakes/fake_icmd_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/cloudinit/cloudinitfakes/fake_ifile_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/cloudinit/cloudinitfakes/fake_itemplate_parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions agent/host_agent_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
})

Expand Down
4 changes: 2 additions & 2 deletions agent/host_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion agent/installer/bundle_builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
5 changes: 3 additions & 2 deletions agent/installer/bundle_builder/build-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion agent/installer/bundle_builder/ingredients/deb/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
27 changes: 20 additions & 7 deletions agent/installer/bundle_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.
Expand All @@ -31,40 +33,46 @@ 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)
}

// DownloadFromRepo downloads the required bundle with the given method.
func (bd *bundleDownloader) DownloadFromRepo(
normalizedOsVersion,
k8sVersion string,
tag string,
downloadByTool func(string, string) error) error {

err := ensureDirExist(bd.downloadPath)
if err != nil {
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)
if err != nil {
return err
}

bundleAddr := bd.getBundleAddr(normalizedOsVersion, k8sVersion)
bundleAddr := bd.getBundleAddr(normalizedOsVersion, k8sVersion, tag)
err = convertError(downloadByTool(bundleAddr, dir))
if err != nil {
return err
Expand All @@ -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()

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions agent/installer/bundle_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -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"
Expand All @@ -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() {
Expand All @@ -53,19 +56,20 @@ 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()))

// Test no download on cache hit
err = bd.DownloadFromRepo(
normalizedOsVersion,
k8sVersion,
testTag,
mi.Get)
Expect(err).ShouldNot((HaveOccurred()))
Expect(mi.callCount).Should(Equal(1))
Expand All @@ -75,6 +79,7 @@ var _ = Describe("Byohost Installer Tests", func() {
err := bd.DownloadFromRepo(
normalizedOsVersion,
k8sVersion,
testTag,
mi.Get)
Expect(err).ShouldNot((HaveOccurred()))
})
Expand All @@ -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()))
Expand All @@ -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()))
Expand All @@ -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()))
Expand All @@ -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()))
Expand Down
Loading

0 comments on commit 40b1e5c

Please sign in to comment.