Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
bin/
tmp/
hammerspace-cs-driver
hammerspace-csi-driver
csi-plugin

deploy-test/
vendor/
*.swp
*.test
*.tests
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: go-vet
- id: go-imports
- id: go-mod-tidy
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM registry.access.redhat.com/ubi8/ubi:8.4
ADD ubi/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
ADD ubi/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo
ADD ubi/RPM-GPG-KEY-centosofficial /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
RUN dnf --disableplugin=subscription-manager -y install python2-pip libcom_err-devel \
RUN dnf --disableplugin=subscription-manager -y --nobest install python2-pip libcom_err-devel \
ca-certificates-2021.2.50-80.0.el8_4.noarch \
e2fsprogs-1.45.6-2.el8.x86_64 \
#-1.45.6-1.el8.x86_64 \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ build-dev:

build:
@echo "==> Building Docker Image Latest"
@docker build -t "hammerspaceinc/csi-plugin-ubi:latest" . -f Dockerfile --no-cache
@docker build -t "hammerspaceinc/csi-plugin:latest" . -f Dockerfile --no-cache

build-release:
@echo "==> Building Docker Image ${VERSION} ${GITHASH}"
@docker build --build-arg version=${VERSION} -t "hammerspaceinc/csi-plugin-ubi:${VERSION}" . -f Dockerfile
@docker build --build-arg version=${VERSION} -t "hammerspaceinc/csi-plugin:${VERSION}" . -f Dockerfile

build-alpine:
@echo "==> Building Alpine Docker Image Latest"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ $ yum install nfs-utils

The plugin container(s) must run as privileged containers

## Development Dependencies

```bash
$ pip2 install pre-commit
```

## Installation
Kubernetes specific deployment instructions are located at [here](https://github.com/hammer-space/csi-plugin/blob/master/deploy/kubernetes/README.md)

Expand Down Expand Up @@ -90,6 +96,7 @@ Currently, only the ``topology.csi.hammerspace.com/is-data-portal`` key is suppo
* Docker
* Golang 1.12+
* nfs-utils
* pre-commit

### Building
##### Build a new docker image from local source:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.5
v1.2.4
251 changes: 131 additions & 120 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,136 +16,147 @@ limitations under the License.
package main

import (
"github.com/hammer-space/csi-plugin/pkg/common"
"net"
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"syscall"

log "github.com/sirupsen/logrus"
"github.com/hammer-space/csi-plugin/pkg/driver"
"context"
"net"
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"syscall"

"github.com/hammer-space/csi-plugin/pkg/common"

"github.com/hammer-space/csi-plugin/pkg/driver"
log "github.com/sirupsen/logrus"
)

var ()

func init() {
// Setup logging
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Setup logging
log.SetFormatter(&log.JSONFormatter{
PrettyPrint: true,
DisableTimestamp: false,
TimestampFormat: "2006-01-02 15:04:05",
})
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
log.SetReportCaller(false)
log.WithContext(ctx)
}

func validateEnvironmentVars() {
endpoint := os.Getenv("CSI_ENDPOINT")
if len(endpoint) == 0 {
log.Error("CSI_ENDPOINT must be defined and must be a path")
os.Exit(1)
}
if strings.Contains(endpoint, ":") {
log.Error("CSI_ENDPOINT must be a unix path")
os.Exit(1)
}

hsEndpoint := os.Getenv("HS_ENDPOINT")
if len(hsEndpoint) == 0 {
log.Error("HS_ENDPOINT must be defined")
os.Exit(1)
}

endpointUrl, err := url.Parse(hsEndpoint)
if err != nil || endpointUrl.Scheme != "https" || endpointUrl.Host == "" {
log.Error("HS_ENDPOINT must be a valid HTTPS URL")
os.Exit(1)
}

username := os.Getenv("HS_USERNAME")
if len(username) == 0 {
log.Error("HS_USERNAME must be defined")
os.Exit(1)
}
password := os.Getenv("HS_PASSWORD")
if len(password) == 0 {
log.Error("HS_PASSWORD must be defined")
os.Exit(1)
}
if os.Getenv("HS_TLS_VERIFY") != "" {
_, err = strconv.ParseBool(os.Getenv("HS_TLS_VERIFY"))
if err != nil {
log.Error("HS_TLS_VERIFY must be a bool")
os.Exit(1)
}
}
if os.Getenv("CSI_MAJOR_VERSION") != "0" || os.Getenv("CSI_MAJOR_VERSION") != "1" {
if err != nil {
log.Error("CSI_MAJOR_VERSION must be set to \"0\" or \"1\"")
os.Exit(1)
}
}
common.DataPortalMountPrefix = os.Getenv("HS_DATA_PORTAL_MOUNT_PREFIX")
endpoint := os.Getenv("CSI_ENDPOINT")
if len(endpoint) == 0 {
log.Error("CSI_ENDPOINT must be defined and must be a path")
os.Exit(1)
}
if strings.Contains(endpoint, ":") {
log.Error("CSI_ENDPOINT must be a unix path")
os.Exit(1)
}

hsEndpoint := os.Getenv("HS_ENDPOINT")
if len(hsEndpoint) == 0 {
log.Error("HS_ENDPOINT must be defined")
os.Exit(1)
}

endpointUrl, err := url.Parse(hsEndpoint)
if err != nil || endpointUrl.Scheme != "https" || endpointUrl.Host == "" {
log.Error("HS_ENDPOINT must be a valid HTTPS URL")
os.Exit(1)
}

username := os.Getenv("HS_USERNAME")
if len(username) == 0 {
log.Error("HS_USERNAME must be defined")
os.Exit(1)
}

password := os.Getenv("HS_PASSWORD")
if len(password) == 0 {
log.Error("HS_PASSWORD must be defined")
os.Exit(1)
}

if os.Getenv("HS_TLS_VERIFY") != "" {
_, err = strconv.ParseBool(os.Getenv("HS_TLS_VERIFY"))
if err != nil {
log.Error("HS_TLS_VERIFY must be a bool")
os.Exit(1)
}
}

if os.Getenv("CSI_MAJOR_VERSION") != "0" || os.Getenv("CSI_MAJOR_VERSION") != "1" {
if err != nil {
log.Error("CSI_MAJOR_VERSION must be set to \"0\" or \"1\"")
os.Exit(1)
}
}

common.DataPortalMountPrefix = os.Getenv("HS_DATA_PORTAL_MOUNT_PREFIX")
}

type Server interface {
Start(net.Listener) error
Stop()
Start(net.Listener) error
Stop()
}

func main() {

validateEnvironmentVars()

var server Server

CSI_version := os.Getenv("CSI_MAJOR_VERSION")

endpoint := os.Getenv("CSI_ENDPOINT")
csiDriver := driver.NewCSIDriver(
os.Getenv("HS_ENDPOINT"),
os.Getenv("HS_USERNAME"),
os.Getenv("HS_PASSWORD"),
os.Getenv("HS_TLS_VERIFY"),
)

if CSI_version == "0" {
server = driver.NewCSIDriver_v0Support(csiDriver)
common.CsiVersion = "0"
} else {
server = csiDriver
}

// Listen
os.Remove(endpoint)
l, err := net.Listen("unix", endpoint)
if err != nil {
log.Errorf("Error: Unable to listen on %s socket: %v\n",
endpoint,
err)
os.Exit(1)
}
defer os.Remove(endpoint)

// Start server
if err := server.Start(l); err != nil {
log.Errorf("Error: Unable to start CSI server: %v\n",
err)
os.Exit(1)
}
log.Info("hammerspace driver started")

// Wait for signal
sigc := make(chan os.Signal, 1)
sigs := []os.Signal{
syscall.SIGTERM,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
}
signal.Notify(sigc, sigs...)

<-sigc
server.Stop()
log.Info("hammerspace driver stopped")
validateEnvironmentVars()

var server Server

CSI_version := os.Getenv("CSI_MAJOR_VERSION")

endpoint := os.Getenv("CSI_ENDPOINT")
csiDriver := driver.NewCSIDriver(
os.Getenv("HS_ENDPOINT"),
os.Getenv("HS_USERNAME"),
os.Getenv("HS_PASSWORD"),
os.Getenv("HS_TLS_VERIFY"),
)

if CSI_version == "0" {
server = driver.NewCSIDriver_v0Support(csiDriver)
common.CsiVersion = "0"
} else {
server = csiDriver
}

// Listen
os.Remove(endpoint)
l, err := net.Listen("unix", endpoint)
if err != nil {
log.Errorf("Error: Unable to listen on %s socket: %v\n",
endpoint,
err)
os.Exit(1)
}
defer os.Remove(endpoint)

// Start server
if err := server.Start(l); err != nil {
log.Errorf("Error: Unable to start CSI server: %v\n",
err)
os.Exit(1)
}
log.Info("hammerspace driver started")

// Wait for signal
sigc := make(chan os.Signal, 1)
sigs := []os.Signal{
syscall.SIGTERM,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
}
signal.Notify(sigc, sigs...)

<-sigc
server.Stop()
log.Info("hammerspace driver stopped")
}
Loading