Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from scality/feature/COSI-11-deploy-cosi-resou…
Browse files Browse the repository at this point in the history
…rces-in-CI

COSI-11 deploy cosi resources in ci
  • Loading branch information
anurag4DSB authored Nov 8, 2024
2 parents 792beac + 737a340 commit 46dfc80
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 185 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/setup_cosi_resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -e

# Define log file for debugging
LOG_FILE=".github/e2e_tests/artifacts/logs/kind_cluster_logs/cosi_deployment/setup_debug.log"
mkdir -p "$(dirname "$LOG_FILE")" # Ensure the log directory exists

# Error handling function
error_handler() {
echo "An error occurred during the COSI setup. Check the log file for details." | tee -a "$LOG_FILE"
echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE"
exit 1
}

# Trap errors and call the error handler
trap 'error_handler' ERR

# Log command execution to the log file for debugging
log_and_run() {
echo "Running: $*" | tee -a "$LOG_FILE"
"$@" | tee -a "$LOG_FILE"
}

# Step 1: Install COSI CRDs
log_and_run echo "Installing COSI CRDs..."
log_and_run kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-api
log_and_run kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-controller

# Step 2: Verify COSI Controller Pod Status
log_and_run echo "Verifying COSI Controller Pod status..."
log_and_run kubectl wait --namespace default --for=condition=ready pod -l app.kubernetes.io/name=container-object-storage-interface-controller --timeout=10s
log_and_run kubectl get pods --namespace default

# Step 3: Build COSI driver Docker image
log_and_run echo "Building COSI driver image..."
log_and_run docker build -t ghcr.io/scality/cosi:latest .

# Step 4: Load COSI driver image into KIND cluster
log_and_run echo "Loading COSI driver image into KIND cluster..."
log_and_run kind load docker-image ghcr.io/scality/cosi:latest --name object-storage-cluster

# Step 5: Run COSI driver
log_and_run echo "Applying COSI driver manifests..."
log_and_run kubectl apply -k .

# Step 6: Verify COSI driver Pod Status
log_and_run echo "Verifying COSI driver Pod status..."
log_and_run kubectl wait --namespace scality-object-storage --for=condition=ready pod --selector=app.kubernetes.io/name=scality-cosi-driver --timeout=20s
log_and_run kubectl get pods -n scality-object-storage

log_and_run echo "COSI setup completed successfully."
7 changes: 7 additions & 0 deletions .github/workflows/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jobs:
with:
detached: true


- name: Setup COSI Controller, CRDs and Driver
run: |
pwd
chmod +x .github/scripts/setup_cosi_resources.sh
.github/scripts/setup_cosi_resources.sh
- name: Capture Kubernetes Logs in artifacts directory
run: |
chmod +x .github/scripts/capture_k8s_logs.sh
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
APP_NAME = scality-cosi-driver
BIN_DIR = ./bin

# 'go env' vars aren't always available in make environments, so get defaults for needed ones
GOARCH ?= $(shell go env GOARCH)
IMAGE_NAME ?= ghcr.io/scality/cosi:latest

.PHONY: all build test clean

all: test build

build:
@echo "Building $(APP_NAME)..."
go build -o $(BIN_DIR)/$(APP_NAME) ./cmd/$(APP_NAME)
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o $(BIN_DIR)/$(APP_NAME) ./cmd/$(APP_NAME)

test:
@echo "Running Ginkgo tests..."
Expand All @@ -17,3 +21,7 @@ test:
clean:
@echo "Cleaning up..."
rm -rf $(BIN_DIR)

container:
@echo "Building container image..."
docker build -t $(IMAGE_NAME) .
59 changes: 1 addition & 58 deletions kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: scality-cosi-driver

commonAnnotations:
cosi.storage.k8s.io/authors: "Kubernetes Authors"
cosi.storage.k8s.io/license: "Apache V2"
cosi.storage.k8s.io/support: "https://github.com/kubernetes-sigs/container-object-storage-api"

commonLabels:
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/component: driver-scality
app.kubernetes.io/version: main
app.kubernetes.io/name: cosi-driver-scality

configMapGenerator:
- name: cosi-driver-scality-config
env: resources/cosi-driver-scality.properties
generatorOptions:
disableNameSuffixHash: true
labels:
generated-by: "kustomize"

resources:
- resources/ns.yaml
- resources/sa.yaml
- resources/rbac.yaml
- resources/deployment.yaml

configurations:
- resources/kustomizeconfig.yaml

vars:
- name: IMAGE_ORG
objref:
name: cosi-driver-scality-config
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.OBJECTSTORAGE_PROVISIONER_IMAGE_ORG
- name: IMAGE_VERSION
objref:
name: cosi-driver-scality-config
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.OBJECTSTORAGE_PROVISIONER_IMAGE_VERSION
- name: SCALITY_IMAGE_ORG
objref:
name: cosi-driver-scality-config
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.SCALITY_DRIVER_IMAGE_ORG
- name: SCALITY_IMAGE_VERSION
objref:
name: cosi-driver-scality-config
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.SCALITY_DRIVER_IMAGE_VERSION
- kustomize/overlays
45 changes: 45 additions & 0 deletions kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: scality-cosi-driver
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: scality-cosi-driver
template:
metadata:
labels:
app.kubernetes.io/name: scality-cosi-driver
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/component: driver
app.kubernetes.io/version: main
app.kubernetes.io/managed-by: kustomize
spec:
serviceAccountName: scality-object-storage-provisioner
containers:
- name: scality-cosi-driver
image: ghcr.io/scality/cosi:latest
imagePullPolicy: IfNotPresent
args:
- "--driver-prefix=cosi"
- "--v=$(COSI_DRIVER_LOG_LEVEL)"
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: objectstorage-provisioner-sidecar
image: gcr.io/k8s-staging-sig-storage/objectstorage-sidecar:latest
imagePullPolicy: IfNotPresent
args:
- "--v=$(OBJECTSTORAGE_PROVISIONER_SIDECAR_LOG_LEVEL)"
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
volumes:
- name: socket
emptyDir: {}
10 changes: 10 additions & 0 deletions kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: scality-object-storage

resources:
- namespace.yaml
- serviceaccount.yaml
- rbac.yaml
- deployment.yaml
4 changes: 4 additions & 0 deletions kustomize/base/namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: scality-object-storage
28 changes: 28 additions & 0 deletions kustomize/base/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: scality-object-storage-provisioner-role
rules:
- apiGroups: ["objectstorage.k8s.io"]
resources: ["buckets", "bucketaccesses", "bucketclaims", "bucketaccessclasses", "buckets/status", "bucketaccesses/status", "bucketclaims/status", "bucketaccessclasses/status"]
verbs: ["get", "list", "watch", "update", "create", "delete"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "watch", "list", "delete", "update", "create"]
- apiGroups: [""]
resources: ["secrets", "events"]
verbs: ["get", "delete", "update", "create"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: scality-object-storage-provisioner-role-binding
subjects:
- kind: ServiceAccount
name: scality-object-storage-provisioner
namespace: default
roleRef:
kind: ClusterRole
name: scality-object-storage-provisioner-role
apiGroup: rbac.authorization.k8s.io
5 changes: 5 additions & 0 deletions kustomize/base/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: scality-object-storage-provisioner
namespace: default
37 changes: 37 additions & 0 deletions kustomize/overlays/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

configMapGenerator:
- name: scality-cosi-driver-properties
env: scality-cosi-driver.properties
generatorOptions:
disableNameSuffixHash: true
labels:
generated-by: "kustomize"

resources:
- ../base

commonLabels:
app.kubernetes.io/version: main
app.kubernetes.io/component: driver
app.kubernetes.io/name: scality-cosi-driver
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/managed-by: kustomize

vars:
- name: COSI_DRIVER_LOG_LEVEL
objref:
name: scality-cosi-driver-properties
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.COSI_DRIVER_LOG_LEVEL

- name: OBJECTSTORAGE_PROVISIONER_SIDECAR_LOG_LEVEL
objref:
name: scality-cosi-driver-properties
kind: ConfigMap
apiVersion: v1
fieldref:
fieldpath: data.OBJECTSTORAGE_PROVISIONER_SIDECAR_LOG_LEVEL
2 changes: 2 additions & 0 deletions kustomize/overlays/scality-cosi-driver.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COSI_DRIVER_LOG_LEVEL=5
OBJECTSTORAGE_PROVISIONER_SIDECAR_LOG_LEVEL=5
4 changes: 0 additions & 4 deletions resources/cosi-driver.properties

This file was deleted.

60 changes: 0 additions & 60 deletions resources/deployment.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions resources/kustomizeconfig.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions resources/ns.yaml

This file was deleted.

Loading

0 comments on commit 46dfc80

Please sign in to comment.