-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement very common tools to work with Proxmox CSI disks. Like: * migrate - helps to move block devices from one Proxmox node to another. * rename - helps to change name of pvc. Signed-off-by: Serge Logvinov <[email protected]>
- Loading branch information
1 parent
ffad744
commit d97bc32
Showing
15 changed files
with
1,168 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
project_name: pvecsi-mutate | ||
|
||
before: | ||
hooks: | ||
- go mod download | ||
- make release-update | ||
|
||
dist: bin | ||
builds: | ||
- dir: cmd/pvecsi-mutate | ||
binary: pvecsi-mutate-{{ .Os }}-{{ .Arch }} | ||
no_unique_dist_dir: true | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
|
||
checksum: | ||
name_template: "checksums.txt" | ||
|
||
snapshot: | ||
name_template: edge | ||
|
||
dockers: | ||
- use: buildx | ||
image_templates: | ||
- ghcr.io/sergelogvinov/pvecsi-mutate:{{ .Version }}-amd64 | ||
goos: linux | ||
goarch: amd64 | ||
build_flag_templates: | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
- "--target=pvecsi-mutate-goreleaser" | ||
- "--platform=linux/amd64" | ||
- use: buildx | ||
image_templates: | ||
- ghcr.io/sergelogvinov/pvecsi-mutate:{{ .Version }}-arm64 | ||
goos: linux | ||
goarch: arm64 | ||
build_flag_templates: | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
- "--target=pvecsi-mutate-goreleaser" | ||
- "--platform=linux/arm64" | ||
docker_manifests: | ||
- name_template: ghcr.io/sergelogvinov/{{ .ProjectName }}:{{ .Version }} | ||
image_templates: | ||
- ghcr.io/sergelogvinov/{{ .ProjectName }}:{{ .Version }}-amd64 | ||
- ghcr.io/sergelogvinov/{{ .ProjectName }}:{{ .Version }}-arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Proxmox PV Migrate utility | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
cobra "github.com/spf13/cobra" | ||
|
||
clilog "github.com/sergelogvinov/proxmox-csi-plugin/pkg/log" | ||
) | ||
|
||
var ( | ||
command = "pvecsi-mutate" | ||
version = "v0.0.0" | ||
commit = "none" | ||
|
||
cloudconfig string | ||
kubeconfig string | ||
|
||
flagLogLevel = "log-level" | ||
|
||
flagProxmoxConfig = "config" | ||
flagKubeConfig = "kubeconfig" | ||
|
||
logger *log.Entry | ||
) | ||
|
||
func main() { | ||
if exitCode := run(); exitCode != 0 { | ||
os.Exit(exitCode) | ||
} | ||
} | ||
|
||
func run() int { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
l := log.New() | ||
l.SetOutput(os.Stdout) | ||
l.SetLevel(log.InfoLevel) | ||
|
||
logger = l.WithContext(ctx) | ||
|
||
cmd := cobra.Command{ | ||
Use: command, | ||
Version: fmt.Sprintf("%s (commit: %s)", version, commit), | ||
Short: "A command-line utility to manipulate PersistentVolume/PersistentVolumeClaim on Proxmox VE", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
f := cmd.Flags() | ||
loglvl, _ := f.GetString(flagLogLevel) //nolint: errcheck | ||
|
||
clilog.Configure(logger, loglvl) | ||
|
||
return nil | ||
}, | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
} | ||
|
||
cmd.PersistentFlags().String(flagLogLevel, clilog.LevelInfo, | ||
fmt.Sprintf("log level, must be one of: %s", strings.Join(clilog.Levels, ", "))) | ||
|
||
cmd.PersistentFlags().StringVar(&cloudconfig, flagProxmoxConfig, "", "proxmox cluster config file") | ||
cmd.PersistentFlags().StringVar(&kubeconfig, flagKubeConfig, "", "kubernetes config file") | ||
|
||
cmd.AddCommand(buildMigrateCmd()) | ||
cmd.AddCommand(buildRenameCmd()) | ||
|
||
err := cmd.ExecuteContext(ctx) | ||
if err != nil { | ||
errorString := err.Error() | ||
if strings.Contains(errorString, "arg(s)") || strings.Contains(errorString, "flag") || strings.Contains(errorString, "command") { | ||
fmt.Fprintf(os.Stderr, "Error: %s\n\n", errorString) | ||
fmt.Fprintln(os.Stderr, cmd.UsageString()) | ||
} else { | ||
logger.Errorf("Error: %s\n", errorString) | ||
} | ||
|
||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
Oops, something went wrong.