Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE]: For verification of VolumeAttachment cleanup when a node is force deleted or recycled #41

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ COPY --from=builder /app/civo-csi /app/civo-csi

RUN chmod +x /app/civo-csi

RUN apk add --update --no-cache findmnt blkid e2fsprogs e2fsprogs-extra
RUN apk add --update --no-cache findmnt blkid e2fsprogs e2fsprogs-extra expect

# Run the civo-csi binary
ENTRYPOINT ["/app/civo-csi"]
7 changes: 7 additions & 0 deletions deploy/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ spec:
mountPath: /registration
- name: civo-csi-plugin
image: gcr.io/consummate-yew-302509/csi:latest
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- unbuffer /app/civo-csi pre-stop > /proc/1/fd/1
env:
- name: CIVO_API_KEY
valueFrom:
Expand Down
73 changes: 48 additions & 25 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/civo/civo-csi/pkg/driver"
"github.com/civo/civo-csi/pkg/driver/hook"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand All @@ -18,30 +20,17 @@ var (
versionInfo = flag.Bool("version", false, "Print the driver version")
)

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

flag.Parse()
if *versionInfo {
log.Info().Str("version", driver.Version).Msg("CSI driver")
return
}

apiURL := strings.TrimSpace(os.Getenv("CIVO_API_URL"))
apiKey := strings.TrimSpace(os.Getenv("CIVO_API_KEY"))
region := strings.TrimSpace(os.Getenv("CIVO_REGION"))
ns := strings.TrimSpace(os.Getenv("CIVO_NAMESPACE"))
clusterID := strings.TrimSpace(os.Getenv("CIVO_CLUSTER_ID"))

d, err := driver.NewDriver(apiURL, apiKey, region, ns, clusterID)
if err != nil {
log.Fatal().Err(err)
}

log.Info().Interface("d", d).Msg("Created a new driver")
var (
apiURL = strings.TrimSpace(os.Getenv("CIVO_API_URL"))
apiKey = strings.TrimSpace(os.Getenv("CIVO_API_KEY"))
region = strings.TrimSpace(os.Getenv("CIVO_REGION"))
ns = strings.TrimSpace(os.Getenv("CIVO_NAMESPACE"))
clusterID = strings.TrimSpace(os.Getenv("CIVO_CLUSTER_ID"))
node = strings.TrimSpace(os.Getenv("KUBE_NODE_NAME"))
)

ctx, cancel := context.WithCancel(context.Background())
func run(ctx context.Context) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

c := make(chan os.Signal, 1)
Expand All @@ -53,9 +42,43 @@ func main() {
cancel()
}()

flag.Parse()
if *versionInfo {
log.Info().Str("version", driver.Version).Msg("CSI driver")
return nil
}

if len(os.Args) > 1 {
hook, err := hook.NewHook(
hook.WithNodeName(node),
)
if err != nil {
return err
}
switch cmd := os.Args[1]; cmd {
case "pre-stop":
log.Info().Msg("Running the pre-stop hook for driver")
return hook.PreStop(ctx)
default:
return fmt.Errorf("not supported command: %q", cmd)
}
}

d, err := driver.NewDriver(apiURL, apiKey, region, ns, clusterID)
if err != nil {
return err
}
log.Info().Interface("d", d).Msg("Created a new driver")

log.Info().Msg("Running the driver")
return d.Run(ctx)
}

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

if err := d.Run(ctx); err != nil {
log.Fatal().Err(err)
if err := run(context.Background()); err != nil {
log.Fatal().Err(err).Msg("Application error occured")
}
}
Loading