Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/containerne…
Browse files Browse the repository at this point in the history
…tworking/plugins-1.5.1

Signed-off-by: Mohamed Belgaied Hassine <[email protected]>
  • Loading branch information
belgaied2 authored Nov 21, 2024
2 parents 6979e8b + 975f52f commit 2eb1111
Show file tree
Hide file tree
Showing 23 changed files with 935 additions and 861 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ on:
- "v*.*.*"

env:
TAG: ${{ github.ref_name }}
REGISTRY: ghcr.io
ORG: ${{ github.repository_owner }}
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
Expand All @@ -21,20 +20,38 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setupGo
uses: actions/setup-go@v5
with:
go-version: '=1.22.3'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
run: make docker-build-all TAG=${{ env.TAG }} ORG=${{ env.ORG }}
- name: Push docker image
run: make docker-push-all TAG=${{ env.TAG }} PROD_REGISTRY=${{ env.REGISTRY }} ORG=${{ env.ORG }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
release:
runs-on: ubuntu-latest
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ linters-settings:
statements: 60
lll:
line-length: 150
gomnd:
mnd:
ignored-numbers:
- "5"
- "4"
Expand Down
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Build the manager binary
FROM golang:1.22 as builder
ARG TARGETOS
ARG TARGETARCH
FROM --platform=$BUILDPLATFORM registry.suse.com/bci/golang:1.22 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -23,13 +21,13 @@ COPY util util/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
ARG TARGETOS
ARG TARGETARCH
ARG LDFLAGS
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
FROM registry.suse.com/bci/bci-micro:15.6
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,10 @@ docker-build-%:
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./ --build-arg ldflags="$(LDFLAGS)" . -t $(IMG)-$(ARCH):$(TAG)
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./ --build-arg ldflags="$(LDFLAGS)" . -t $(IMG)-$(ARCH):$(TAG)
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"

# docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}-$(ARCH):$(TAG)
Expand Down Expand Up @@ -290,7 +288,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.0
CONTROLLER_TOOLS_VERSION ?= v0.17.0
CONTROLLER_TOOLS_VERSION ?= v0.16.5
ENVTEST_VERSION ?= v0.0.0-20240531134648-6636df17d67b

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,32 @@ You can now create your first workload cluster by running the following:
```

### Create a workload cluster
Now, you can test out the provider by generating some YAML and applying it to the above `kind` cluster. Such YAML samples can be found in `./samples` directory. We will be interested here in the `RKE2` examples under `./samples/rke2`. Please be aware that the file [example.yaml](./samples/rke2/example.yaml) is a template with placeholders: it cannot be applied directly to the cluster. You need to generate a valid YAML file first. In order to do that, you need to set the following environment variables:
Now, you can test out the provider by generating some YAML and applying it to the above `kind` cluster. Such YAML templates can be found in `./templates` directory. We will be interested here in the `RKE2` examples under `./templates`. Please be aware that the file [cluster-template-rke2-dhcp.yaml](./templates/cluster-template-rke2-dhcp.yaml) is a template with placeholders: it cannot be applied directly to the cluster. You need to generate a valid YAML file first. In order to do that, you need to set the following environment variables:

```bash
export CLUSTER_NAME=test-rk # Name of the cluster that will be created.
export HARVESTER_ENDPOINT=x.x.x.x # Harvester Clusters IP Adr.
export NAMESPACE=example-rk # Namespace where the cluster will be created.
export KUBERNETES_VERSION=v1.26.6 # Kubernetes Version
export SSH_KEYPAIR=<public-key-name> # should exist in Harvester prior to applying manifest
export VM_IMAGE_NAME=default/jammy-server-cloudimg-amd64.img # Should have the format <NAMESPACE>/<NAME> for an image that exists on Harvester
export SSH_KEYPAIR=<public-key-name> # should exist in Harvester prior to applying manifest. Should have the format <TARGET_HARVESTER_NAMESPACE>/<NAME>
export VM_IMAGE_NAME=default/jammy-server-cloudimg-amd64.img # Should have the format <TARGET_HARVESTER_NAMESPACE>/<NAME> for an image that exists on Harvester
export CONTROL_PLANE_MACHINE_COUNT=3
export WORKER_MACHINE_COUNT=2
export VM_DISK_SIZE=40Gi # Put here the desired disk size
export RANCHER_TURTLES_LABEL='' # This is used if you are using Rancher CAPI Extension (Turtles) to import the cluster automatically.
export VM_NETWORK=default/untagged # change here according to your Harvester available VM Networks. Should have the format <TARGET_HARVESTER_NAMESPACE>/<NAME>
export HARVESTER_KUBECONFIG_B64=XXXYYY #Full Harvester's kubeconfig encoded in Base64. You can use: cat kubeconfig.yaml | base64
export CLOUD_CONFIG_KUBECONFIG_B64=ZZZZAAA # Kubeconfig generated for the Cloud Provider: https://docs.harvesterhci.io/v1.3/rancher/cloud-provider#deploying-to-the-rke2-custom-cluster-experimental
export IP_POOL_NAME=default # for the non-DHCP template, specify the IP pool for the Harvester load balancer. The IP pool must exist in Harvester prior to applying manifest
export TARGET_HARVESTER_NAMESPACE=default # the namespace on the Harvester cluster where the VMs, load balancers etc. should be created
```

NOTE: The `CLOUD_CONFIG_KUBECONFIG_B64` variable content should be the result of the script available [here](https://docs.harvesterhci.io/v1.3/rancher/cloud-provider#deploying-to-the-rke2-custom-cluster-experimental) -- meaning, the generated kubeconfig -- encoded in BASE64.

Now, we can generate the YAML using the following command:

```bash
clusterctl generate cluster --from https://github.com/rancher-sandbox/cluster-api-provider-harvester/blob/v0.1.2/templates/cluster-template-rke2.yaml -n ${CLUSTER_NAMESPACE} ${CLUSTER_NAME} > harvester-rke2-clusterctl.yaml
clusterctl generate yaml --from https://github.com/rancher-sandbox/cluster-api-provider-harvester/blob/main/templates/cluster-template-rke2.yaml > harvester-rke2-clusterctl.yaml
```

After examining the resulting YAML file, you can apply it to the management cluster:
Expand Down Expand Up @@ -149,4 +157,4 @@ Cluster/test-rk True
└─Workers
└─MachineDeployment/test-rk-workers True 7h46m
└─2 Machines... True 7h46m See test-rk-workers-jwjdg-sz7qk, test-rk-workers-jwjdg-vxgbx
```
```
20 changes: 17 additions & 3 deletions api/v1alpha1/harvestercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const (
LoadBalancerNoBackendMachineReason = "There are no machines matching the load balancer configuration"
// LoadBalancerHealthcheckFailedReason documents the reason why the load balancer is not ready.
LoadBalancerHealthcheckFailedReason = "The healthcheck for the load balancer failed"
// CustomIPPoolCreatedCondition documents if a custom IP Pool was created in Harvester.
CustomIPPoolCreatedCondition clusterv1.ConditionType = "CustomIPPoolCreated"
// CustomPoolCreationInHarvesterFailedReason documents the reason why a custom pool was unable to be created.
CustomPoolCreationInHarvesterFailedReason = "The custom Pool creation in Harvester failed"
// CustomIPPoolCreatedSuccessfullyReason documents the reason why Custom IP Pool was created.
CustomIPPoolCreatedSuccessfullyReason = "Custom IP Pool was successfully created"
)

const (
Expand Down Expand Up @@ -82,7 +88,6 @@ type LoadBalancerConfig struct {

// IpPoolRef is a reference to an existing IpPool object in Harvester's cluster.
// This field is mutually exclusive with "ipPool".
//TODO: To be implemented
IpPoolRef string `json:"ipPoolRef,omitempty"`

// IpPool defines a new IpPool that will be added to Harvester.
Expand Down Expand Up @@ -115,6 +120,14 @@ type IpPool struct {
// Gateway is the IP Address that should be used by the Gateway on the Subnet. It should be a valid address inside the subnet.
// e.g. 172.17.1.1.
Gateway string `json:"gateway"`

// RangeStart is the first IP Address that should be used by the IP Pool.
// + optional
RangeStart string `json:"rangeStart,omitempty"`

// RangeEnd is the last IP Address that should be used by the IP Pool.
// + optional
RangeEnd string `json:"rangeEnd,omitempty"`
}

// Listener is a description of a new Listener to be created on the Load Balancer.
Expand All @@ -135,8 +148,9 @@ type Listener struct {

// HarvesterClusterStatus defines the observed state of HarvesterCluster.
type HarvesterClusterStatus struct {
// Reddy describes if the Harvester Cluster can be considered ready for machine creation.
Ready bool `json:"ready"`
// Ready describes if the Harvester Cluster can be considered ready for machine creation.
// +optional
Ready bool `json:"ready,omitempty"`

// FailureReason is the short name for the reason why a failure might be happening that makes the cluster not ready.
// +optional
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 2eb1111

Please sign in to comment.