Skip to content

Commit

Permalink
Merge branch 'main' into feat/security-groups/add-feature-for-list-of…
Browse files Browse the repository at this point in the history
…-ipranges
  • Loading branch information
gvdhart authored Dec 16, 2024
2 parents 47a169d + 0933d20 commit 40fd76d
Show file tree
Hide file tree
Showing 33 changed files with 1,184 additions and 2,284 deletions.
74 changes: 74 additions & 0 deletions .github/scripts/cleanup_k8s_crds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

set -e

# Function to patch resources to remove finalizers
remove_finalizers() {
local resource_type=$1
local resource_name=$2

echo "Removing finalizers from $resource_type/$resource_name (if any)..."
kubectl patch "$resource_type" "$resource_name" --type='merge' -p '{"metadata":{"finalizers":[]}}' || echo "No finalizers to patch or resource does not exist."
}

# Function to delete all resources of a given CRD type
delete_resources() {
local resource_type=$1

echo "Deleting all resources of type $resource_type..."
kubectl delete "$resource_type" --all --ignore-not-found || echo "No resources of type $resource_type found."
}

# Function to delete a CRD
delete_crd() {
local crd_name=$1

echo "Deleting CRD $crd_name..."
kubectl delete crd "$crd_name" --ignore-not-found || echo "CRD $crd_name not found."
}

# Main cleanup logic
cleanup_crd() {
local crd_name=$1
local resource_name=$2

echo "Starting cleanup for CRD $crd_name and resource $resource_name..."

# Remove finalizers from the resource (if exists)
if [ -n "$resource_name" ]; then
remove_finalizers "$crd_name" "$resource_name"
fi

# Delete all resources associated with the CRD
delete_resources "$crd_name"

# Delete the CRD itself
delete_crd "$crd_name"

echo "Cleanup for $crd_name complete."
}

# List of CRDs to clean up (add more as needed)
CRD_LIST=(
"oscclusters.infrastructure.cluster.x-k8s.io"
# Add more CRDs here if needed
)

# List of specific resources to patch/remove finalizers (CRD/resource name pairs)
RESOURCE_LIST=(
"oscclusters.infrastructure.cluster.x-k8s.io/cluster-api-test"
# Add more resources here if needed in the format "crd/resource_name"
)

# Perform cleanup for each resource in the RESOURCE_LIST
for resource_entry in "${RESOURCE_LIST[@]}"; do
IFS="/" read -r crd resource <<< "$resource_entry"
cleanup_crd "$crd" "$resource"
done

# Perform cleanup for all CRDs in the CRD_LIST (general cleanup)
for crd in "${CRD_LIST[@]}"; do
cleanup_crd "$crd" ""
done

echo "Kubernetes CRD cleanup complete."
13 changes: 8 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
paths:
- "**.go"
- "**.yaml"
- "**.mod"
- "**.sum"
- "!capm.yaml"
- "!osc-secret.yaml"
- "!example/**.yaml"
Expand Down Expand Up @@ -37,10 +39,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version-file: './go.mod'
- name: check-gofmt
run: make checkfmt
shell: bash
Expand All @@ -54,6 +57,6 @@ jobs:
run: pip install yamllint
- name: check with yamlint
run: yamllint -c .github/linters/yaml-lint.yaml . --format github
- name: Lint
run: make vet
- name: Run make build
run: make build
shell: bash
76 changes: 54 additions & 22 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,61 @@ on:
- "!hack/json-format/Makefile"
- "!hack/json-format/Cargo.*"
- "!hack/json-format/tests/*.rs"

jobs:
docker:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Docker Lint
run: bash -c "make dockerlint"
- name: Build and Push Docker image
run: |
make docker-buildx
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}
DOCKER_BUILDKIT: 1
- name: Trivy-Scan
run: bash -c "make trivy-scan"
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}
- name: Trivy-Ignore-Check
run: bash -c "make trivy-ignore-check"
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}
- name: Upload Scan if errors
if: ${{ always() && github.event_name != 'pull_request' }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: './.trivyscan/report.sarif'
- uses: actions/checkout@v3

# Cache Trivy Database
- name: Cache Trivy DB
uses: actions/cache@v2
with:
path: ~/.cache/trivy/db # This is where Trivy DB will be cached locally
key: ${{ runner.os }}-trivy-db # Unique cache key based on OS
restore-keys: |
${{ runner.os }}-trivy-db # Fallback key if the exact cache key isn't available
# Download Trivy DB only if cache is missing or outdated
- name: Download Trivy DB
run: |
docker run --rm \
-v $HOME/.cache/trivy/db:/root/.cache/trivy/db \
aquasec/trivy:latest image --download-db-only
# Docker Lint
- name: Docker Lint
run: bash -c "make dockerlint"

# Build and Push Docker Image
- name: Build and Push Docker Image
run: |
make docker-buildx
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}
DOCKER_BUILDKIT: 1

# Trivy Scan
- name: Trivy Scan
run: bash -c "make trivy-scan"
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}
# Mount cached Trivy DB to avoid redundant downloads
with:
args: |
-v $HOME/.cache/trivy/db:/root/.cache/trivy/db
# Trivy Ignore Check
- name: Trivy Ignore Check
run: bash -c "make trivy-ignore-check"
env:
IMG: cluster-api-outscale-controller:${{ github.sha }}

# Upload Trivy SARIF report if errors
- name: Upload Scan if Errors
if: ${{ always() && github.event_name != 'pull_request' }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: './.trivyscan/report.sarif'
7 changes: 7 additions & 0 deletions .github/workflows/unit-func-e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ jobs:
env:
KUBECONFIG: rke-cluster-for-cluster-api/rke/kube_config_cluster.yml
CAPO_NAMESPACE: cluster-api-provider-outscale-system
- name: Run Cleanup Script
run: |
chmod +x .github/scripts/cleanup_k8s_crds.sh
.github/scripts/cleanup_k8s_crds.sh
shell: bash
env:
KUBECONFIG: ${{ github.workspace }}/rke-cluster-for-cluster-api/rke/kube_config_cluster.yml
- name: Destroy cluster
uses: ./rke-cluster-for-cluster-api/github_actions/destroy_cluster/
if: ${{ always() }}
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CAPI_NAMESPACE ?= capi-kubeadm-bootstrap-system
CAPO_NAMESPACE ?= cluster-api-provider-outscale-system
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.30.3
GOFLAGS=-mod=readonly
export GOFLAGS
MINIMUM_KUBEBUILDERTOOL_VERSION=1.30.3
MINIMUM_ENVTEST_VERSION=1.30.3
E2E_CONF_FILE_SOURCE ?= ${PWD}/test/e2e/config/outscale-ci.yaml
Expand Down Expand Up @@ -137,7 +139,7 @@ vet: ## Run go vet against code.
format: gofmt gospace yamlspace yamlfmt

gofmt: ## Run gofmt
find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w
find . -name "*.go" | xargs gofmt -s -w

.PHONY: gospace
gospace: ## Run to remove trailling space
Expand All @@ -149,7 +151,7 @@ yamlspace: ## Run to remove trailling space

.PHONY: yamlfmt
yamlfmt: install-yamlfmt
find . -name "*.yaml" -not -path "./helm/*" -not -path "./.github/workflows/*" | grep -v "\/vendor\/" | xargs yamlfmt
find . -name "*.yaml" -not -path "./helm/*" -not -path "./.github/workflows/*" | xargs yamlfmt

.PHONY: checkfmt
checkfmt: ## check gofmt
Expand Down
31 changes: 15 additions & 16 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,21 @@ type OscVm struct {
}

type OscBastion struct {
Name string `json:"name,omitempty"`
ImageId string `json:"imageId,omitempty"`
ImageName string `json:"imageName,omitempty"`
KeypairName string `json:"keypairName,omitempty"`
VmType string `json:"vmType,omitempty"`
DeviceName string `json:"deviceName,omitempty"`
SubnetName string `json:"subnetName,omitempty"`
RootDisk OscRootDisk `json:"rootDisk,omitempty"`
PublicIpName string `json:"publicIpName,omitempty"`
SubregionName string `json:"subregionName,omitempty"`
PrivateIps []OscPrivateIpElement `json:"privateIps,omitempty"`
SecurityGroupNames []OscSecurityGroupElement `json:"securityGroupNames,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Enable bool `json:"enable,omitempty"`
PublicIpNameAfterBastion bool `json:"publicIpNameAfterBastion,omitempty"`
Name string `json:"name,omitempty"`
ImageId string `json:"imageId,omitempty"`
ImageName string `json:"imageName,omitempty"`
KeypairName string `json:"keypairName,omitempty"`
VmType string `json:"vmType,omitempty"`
DeviceName string `json:"deviceName,omitempty"`
SubnetName string `json:"subnetName,omitempty"`
RootDisk OscRootDisk `json:"rootDisk,omitempty"`
PublicIpName string `json:"publicIpName,omitempty"`
SubregionName string `json:"subregionName,omitempty"`
PrivateIps []OscPrivateIpElement `json:"privateIps,omitempty"`
SecurityGroupNames []OscSecurityGroupElement `json:"securityGroupNames,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Enable bool `json:"enable,omitempty"`
}

type OscRootDisk struct {
Expand Down
20 changes: 10 additions & 10 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,6 @@ func (s *ClusterScope) SetExtraSecurityGroupRule(extraSecurityGroupRule bool) {
s.OscCluster.Spec.Network.ExtraSecurityGroupRule = extraSecurityGroupRule
}

// GetPublicIpNameAfterBastion return publicIpNameAfterBastion
func (s *ClusterScope) GetPublicIpNameAfterBastion() bool {
return s.OscCluster.Spec.Network.Bastion.PublicIpNameAfterBastion
}

// SetPublicIpNameAfterBastion set the publicIpNameAfterBastion
func (s *ClusterScope) SetPublicIpNameAfterBastion(publicIpNameAfterBastion bool) {
s.OscCluster.Spec.Network.Bastion.PublicIpNameAfterBastion = publicIpNameAfterBastion
}

// GetNetwork return the network of the cluster
func (s *ClusterScope) GetNetwork() *infrastructurev1beta1.OscNetwork {
return &s.OscCluster.Spec.Network
Expand Down Expand Up @@ -336,6 +326,11 @@ func (s *ClusterScope) GetControlPlaneEndpointPort() int32 {
return s.OscCluster.Spec.ControlPlaneEndpoint.Port
}

// GetReady get ready status
func (s *ClusterScope) GetReady() bool {
return s.OscCluster.Status.Ready
}

// SetNotReady set not ready status
func (s *ClusterScope) SetNotReady() {
s.OscCluster.Status.Ready = false
Expand Down Expand Up @@ -386,6 +381,11 @@ func (s *ClusterScope) SetVmState(v infrastructurev1beta1.VmState) {
s.OscCluster.Status.VmState = &v
}

// SetVmState set vmstate
func (s *ClusterScope) GetVmState() *infrastructurev1beta1.VmState {
return s.OscCluster.Status.VmState
}

// PatchObject keep the cluster configuration and status
func (s *ClusterScope) PatchObject() error {
setConditions := []clusterv1.ConditionType{
Expand Down
5 changes: 5 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ func (m *MachineScope) SetProviderID(subregionName string, vmId string) {
m.OscMachine.Spec.ProviderID = pointer.StringPtr(pid)
}

// SetVmID set the instanceID
func (m *MachineScope) SetVmID(vmId string) {
m.OscMachine.Spec.Node.Vm.ResourceId = vmId
}

// GetVmState return the vmState
func (m *MachineScope) GetVmState() *infrastructurev1beta1.VmState {
return m.OscMachine.Status.VmState
Expand Down
30 changes: 15 additions & 15 deletions cloud/services/compute/mock_compute/vm_mock.go

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

Loading

0 comments on commit 40fd76d

Please sign in to comment.