Skip to content

Commit

Permalink
CRUSOE-15363: Allow the usage of Crusoe Shared Disks with CSI
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Liaw committed Nov 23, 2024
1 parent 43ecf35 commit 0632409
Show file tree
Hide file tree
Showing 34 changed files with 2,092 additions and 1,813 deletions.
8 changes: 6 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ include:
- project: 'crusoeenergy/tools'
file: '/templates/go.gitlab-ci.yml'

default:
tags:
- gitlab-runner-gcp

variables:
CI_IMAGE: registry.gitlab.com/crusoeenergy/tools/go-ci-1.22
CI_IMAGE: registry.gitlab.com/crusoeenergy/tools/go-ci-1.23

test_and_lint:
rules:
Expand Down Expand Up @@ -39,4 +43,4 @@ code_intelligence:

pages:
rules:
- when: never
- when: never
16 changes: 4 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ linters-settings:
# default is false: such cases aren't reported by default.
check-blank: true
govet:
check-shadowing: true
enable-all: true
gci:
sections:
- standard
Expand All @@ -26,9 +26,6 @@ linters-settings:
- commentedOutCode
whitespace:
multi-if: true # Enforces newlines (or comments) after every multi-line if statement
gosec:
global:
audit: enabled # Run extra checks that might be "nosy"
gomoddirectives:
replace-allow-list:
- github.com/crusoecloud/client-go
Expand All @@ -37,32 +34,28 @@ linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- copyloopvar
- cyclop
- dogsled
- dupl
- durationcheck
- err113
- errcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoinits
- gochecknoglobals
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -73,6 +66,7 @@ linters:
- lll
- makezero
- misspell
- mnd
- nakedret
- nestif
- nilerr
Expand Down Expand Up @@ -114,5 +108,3 @@ run:

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.50.1 # use a fixed version for consistent results
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
# STEP 1: build crusoe-csi-driver binary #
##########################################

FROM golang:1.22.9 AS builder
FROM golang:1.23.3 AS builder

ARG CRUSOE_CSI_DRIVER_NAME
ENV CRUSOE_CSI_DRIVER_NAME=$CRUSOE_CSI_DRIVER_NAME
ARG CRUSOE_CSI_DRIVER_VERSION
ENV CRUSOE_CSI_DRIVER_VERSION=$CRUSOE_CSI_DRIVER_VERSION

WORKDIR /build

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN make cross

################################################################
# STEP 2: build a small image and run crusoe-csi-driver binary #
################################################################
FROM alpine
FROM alpine:3.20.3

# Need to get these updates for k8s mount-utils library to work properly
RUN apk update && \
apk add --no-cache e2fsprogs && \
apk add --no-cache blkid && \
apk add --no-cache e2fsprogs-extra~=1.47.0 && \
apk add --no-cache blkid~=2.40.1 && \
apk add --no-cache xfsprogs-extra~=6.8.0 && \
rm -rf /var/cache/apk/*

COPY --from=builder /build/dist/crusoe-csi-driver /usr/local/go/bin/crusoe-csi-driver
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BUILDDIR := ${PREFIX}/dist
# Set any default go build tags
BUILDTAGS :=

GOLANGCI_VERSION = v1.55.2
GOLANGCI_VERSION = v1.62.0
GO_ACC_VERSION = latest
GOTESTSUM_VERSION = latest
GOCOVER_VERSION = latest
Expand Down
70 changes: 57 additions & 13 deletions cmd/crusoe-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,68 @@ package main
import (
"fmt"
"os"

"github.com/spf13/cobra"
"strings"

"github.com/crusoecloud/crusoe-csi-driver/internal"
"github.com/crusoecloud/crusoe-csi-driver/internal/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/thediveo/enumflag/v2"
)

// Start executing the Crusoe CSI driver.
func main() {
rootCmd := &cobra.Command{
Use: "crusoe-csi-driver",
Short: "Crusoe Container Storage Interface (CSI) driver",
Args: cobra.NoArgs,
RunE: internal.RunDriver,
//nolint:gochecknoglobals // Global command instance
var rootCmd = &cobra.Command{
Use: "crusoe-csi-driver",
Short: "Crusoe Container Storage Interface (CSI) driver",
RunE: internal.RunMain,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
config.AddFlags(rootCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
}

func setFlags() {
var err error
viper.AutomaticEnv()

// Use underscores in env var names
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)

rootCmd.Flags().String(internal.CrusoeAPIEndpointFlag, internal.CrusoeAPIEndpointDefault, "help for api endpoint")
rootCmd.Flags().String(internal.CrusoeAccessKeyFlag, "", "help for access key")
rootCmd.Flags().String(internal.CrusoeSecretKeyFlag, "", "help for secret key")
rootCmd.Flags().String(internal.CrusoeProjectIDFlag, "", "help for project id")
rootCmd.Flags().Var(
enumflag.New(&internal.SelectedCSIDriverType,
internal.CSIDriverTypeFlag,
internal.CSIDriverTypeNames,
true),
internal.CSIDriverTypeFlag,
"help for driver type")
rootCmd.Flags().Var(
enumflag.NewSlice(&internal.Services,
internal.ServicesFlag,
internal.ServiceTypeNames,
true),
internal.ServicesFlag,
"help for services")
rootCmd.Flags().String(internal.NodeNameFlag, "", "help for kubernetes node name")
rootCmd.Flags().String(internal.SocketAddressFlag, internal.SocketAddressDefault, "help for socket address")

err = viper.BindPFlags(rootCmd.Flags())
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func main() {
setFlags()
Execute()
}
48 changes: 34 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,75 @@
module github.com/crusoecloud/crusoe-csi-driver

go 1.22.0
go 1.23

require (
github.com/antihax/optional v1.0.0
github.com/container-storage-interface/spec v1.9.0
github.com/container-storage-interface/spec v1.10.0
github.com/crusoecloud/client-go v0.1.59
github.com/google/uuid v1.6.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/thediveo/enumflag/v2 v2.0.5
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.34.2
k8s.io/apimachinery v0.31.2
k8s.io/client-go v0.31.2
k8s.io/klog/v2 v2.130.1
k8s.io/mount-utils v0.31.2
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
)

require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/runc v1.2.1 // indirect
github.com/opencontainers/runc v1.1.13 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.30.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/protobuf v1.35.1 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.2 // indirect
Expand Down
Loading

0 comments on commit 0632409

Please sign in to comment.