这是indexloc提供的服务,不要输入任何密码
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: 5 additions & 0 deletions plugins/network/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ require (
require (
github.com/alexellis/go-execute/v2 v2.2.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/melbahja/goph v1.4.0 // indirect
github.com/onsi/gomega v1.36.2 // indirect
github.com/otiai10/copy v1.14.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect
github.com/ryanuber/columnize v2.1.2+incompatible // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/dokku/dokku/plugins/common => ../common
Expand Down
2 changes: 1 addition & 1 deletion plugins/scheduler-k3s/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBCOMMANDS = subcommands/annotations:set subcommands/autoscaling-auth:set subcommands/autoscaling-auth:report subcommands/cluster-add subcommands/cluster-list subcommands/cluster-remove subcommands/ensure-charts subcommands/initialize subcommands/labels:set subcommands/report subcommands/set subcommands/show-kubeconfig subcommands/uninstall
SUBCOMMANDS = subcommands/annotations:set subcommands/autoscaling-auth:set subcommands/autoscaling-auth:report subcommands/cluster-add subcommands/cluster-list subcommands/cluster-remove subcommands/ensure-charts subcommands/initialize subcommands/labels:set subcommands/report subcommands/set subcommands/show-kubeconfig subcommands/add-pvc subcommands/remove-pvc subcommands/mount subcommands/unmount subcommands/uninstall
TRIGGERS = triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report triggers/scheduler-app-status triggers/scheduler-deploy triggers/scheduler-enter triggers/scheduler-logs triggers/scheduler-proxy-config triggers/scheduler-proxy-logs triggers/scheduler-post-delete triggers/scheduler-run triggers/scheduler-run-list triggers/scheduler-stop
BUILD = commands subcommands triggers
PLUGIN_NAME = scheduler-k3s
Expand Down
25 changes: 25 additions & 0 deletions plugins/scheduler-k3s/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ func getAnnotations(appName string, processType string) (ProcessAnnotations, err
}
annotations.TraefikMiddlewareAnnotations = traefikMiddlewareAnnotations

// TODO: check if this needed???
pvcAnnotations, err := getAnnotation(appName, processType, "pvc")
if err != nil {
return annotations, err
}
annotations.PvcAnnotations = pvcAnnotations

return annotations, nil
}

Expand Down Expand Up @@ -1136,9 +1143,27 @@ func getLabels(appName string, processType string) (ProcessLabels, error) {
}
labels.TraefikMiddlewareLabels = traefikMiddlewareLabels

// TODO: check if this needed ???
pvcLabels, err := getLabel(appName, processType, "pvc")
if err != nil {
return labels, err
}
labels.PvcLabels = pvcLabels

return labels, nil
}

func getVolumes(appName string, processType string) ([]ProcessVolume, error) {
volumes := []ProcessVolume{}
propValue := common.PropertyGet("scheduler-k3s", appName, fmt.Sprintf("volumes.%s", processType))
err := yaml.Unmarshal([]byte(propValue), &volumes)
if err != nil {
return volumes, err
}

return volumes, nil
}

// getGlobalLabel retrieves global labels for a given app
func getGlobalLabel(appName string) (ProcessLabels, error) {
return getLabels(appName, GlobalProcessType)
Expand Down
13 changes: 13 additions & 0 deletions plugins/scheduler-k3s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,16 @@ func streamLogsFromRequest(ctx context.Context, request rest.ResponseWrapper, ou
}
}
}

// PvcInput contains all the information needed to get/delete a Kubernetes PVC
type PvcInput struct {
// Name is the Kubernetes PVC name
Name string
// Namespace is the Kubernetes namespace
Namespace string
}

func (k KubernetesClient) GetPvc(ctx context.Context, input PvcInput) (*corev1.PersistentVolumeClaim, error) {
// Retrieve the PVC
return k.Client.CoreV1().PersistentVolumeClaims(input.Namespace).Get(ctx, input.Name, metav1.GetOptions{})
}
6 changes: 5 additions & 1 deletion plugins/scheduler-k3s/src/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ Additional commands:`
scheduler-k3s:cluster-add [--insecure-allow-unknown-hosts] [--server-ip SERVER_IP] [--taint-scheduling] <ssh://user@host:port>, Adds a server node to a Dokku-managed cluster
scheduler-k3s:cluster-list [--format json|stdout], Lists all nodes in a Dokku-managed cluster
scheduler-k3s:cluster-remove [node-id], Removes client node to a Dokku-managed cluster
scheduler-k3s:ensure-charts, Ensures the k3s charts are installed
scheduler-k3s:ensure-charts, Ensures the k3s charts are installed
scheduler-k3s:initialize [--server-ip SERVER_IP] [--taint-scheduling], Initializes a cluster
scheduler-k3s:labels:set <app|--global> <property> (<value>) [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Set or clear a label for a given app/process-type/resource-type combination
scheduler-k3s:report [<app>] [<flag>], Displays a scheduler-k3s report for one or more apps
scheduler-k3s:set <app> <property> (<value>), Set or clear a scheduler-k3s property for an app
scheduler-k3s:show-kubeconfig, Displays the kubeconfig for remote usage
scheduler-k3s:add-pvc <name> <size> [--access-mode <mode>] [--namespace <namespace>] [--storage-class-name <class-name>], Adds a Persistent Volume Claim (PVC)
scheduler-k3s:remove-pvc <name> [--namespace <namespace>], Remove Persistent Volume Claim in Namespace
scheduler-k3s:mount <app> <pvc_name> </container/path> [--process-type PROCESS_TYPE] [--subpath SUBPATH] [--readonly] [--chown option], Mount a Volume to Container Path for an app. Default processtype: web
scheduler-k3s:unmount <app> <pvc_name> </container/path>, Unmount a Volume from an app
scheduler-k3s:uninstall, Uninstalls k3s from the Dokku server`
)

Expand Down
42 changes: 42 additions & 0 deletions plugins/scheduler-k3s/src/subcommands/subcommands.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"errors"
"fmt"
"os"
"slices"
"strings"

"github.com/dokku/dokku/plugins/common"
Expand Down Expand Up @@ -128,6 +130,46 @@ func main() {
args := flag.NewFlagSet("scheduler-k3s:show-kubeconfig", flag.ExitOnError)
args.Parse(os.Args[2:])
err = scheduler_k3s.CommandShowKubeconfig()
case "add-pvc":
args := flag.NewFlagSet("scheduler-k3s:add-pvc", flag.ExitOnError)
accessMode := args.String("access-mode", "ReadWriteOnce", "--access-mode: access mode default ReadWriteOnce")
namespace := args.String("namespace", "default", "--namespace: default")
storageClass := args.String("storage-class-name", "", "--storage-class-name: e.g. longhorn")
args.Parse(os.Args[2:])
// check accessMode
accessModes := []string{"ReadWriteOnce", "ReadWriteMany", "ReadOnlyMany"}
if !slices.Contains(accessModes, *accessMode) {
err = errors.New("Please specify PVC access mode as either ReadWriteOnce, ReadOnlyMany, ReadWriteMany")
break
}
pvcName := args.Arg(0)
storageSize := args.Arg(1)
err = scheduler_k3s.CommandAddPVC(pvcName, *namespace, *accessMode, storageSize, *storageClass)
case "remove-pvc":
args := flag.NewFlagSet("scheduler-k3s:remove-pvc", flag.ExitOnError)
namespace := args.String("namespace", "default", "--namespace: default")
args.Parse(os.Args[2:])
pvcName := args.Arg(0)
err = scheduler_k3s.CommandRemovePVC(pvcName, *namespace)
case "mount":
args := flag.NewFlagSet("scheduler-k3s:mount", flag.ExitOnError)
subPath := args.String("subpath", "", "--subpath: ")
readOnly := args.Bool("readonly", false, "--readonly: false")
processType := args.String("process-type", "web", "--process-type: web")
chown := args.String("chown", "", "--chown: UID:GID")
args.Parse(os.Args[2:])
appName := args.Arg(0)
pvcName := args.Arg(1)
mountPath := args.Arg(2)
err = scheduler_k3s.CommandMountPVC(appName, *processType, pvcName, mountPath, *subPath, *readOnly, *chown)
case "unmount":
args := flag.NewFlagSet("scheduler-k3s:unmount", flag.ExitOnError)
processType := args.String("process-type", "web", "--process-type: web")
args.Parse(os.Args[2:])
appName := args.Arg(0)
pvcName := args.Arg(1)
mountPath := args.Arg(2)
err = scheduler_k3s.CommandUnMountPVC(appName, *processType, pvcName, mountPath)
case "uninstall":
args := flag.NewFlagSet("scheduler-k3s:uninstall", flag.ExitOnError)
args.Parse(os.Args[2:])
Expand Down
Loading