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

[wip] platform: add Hetzner #533

Closed
wants to merge 6 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion cmd/kola/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
kolaOffering string
defaultTargetBoard = sdk.DefaultBoard()
kolaArchitectures = []string{"amd64"}
kolaPlatforms = []string{"aws", "azure", "brightbox", "do", "esx", "external", "gce", "openstack", "equinixmetal", "qemu", "qemu-unpriv", "scaleway"}
kolaPlatforms = []string{"aws", "azure", "brightbox", "do", "esx", "external", "gce", "hetzner", "openstack", "equinixmetal", "qemu", "qemu-unpriv", "scaleway"}
kolaDistros = []string{"cl", "fcos", "rhcos"}
kolaChannels = []string{"alpha", "beta", "stable", "edge", "lts"}
kolaOfferings = []string{"basic", "pro"}
Expand Down Expand Up @@ -244,6 +244,12 @@ func init() {
sv(&kola.ScalewayOptions.SecretKey, "scaleway-secret-key", "", "Scaleway credentials secret key")
sv(&kola.ScalewayOptions.Image, "scaleway-image", "", "Scaleway image ID")
sv(&kola.ScalewayOptions.InstanceType, "scaleway-instance-type", "DEV1-S", "Scaleway instance type")

// Hetzner specific options
sv(&kola.HetznerOptions.Token, "hetzner-token", "", "Hetzner token for client authentication")
sv(&kola.HetznerOptions.Location, "hetzner-location", "fsn1-dc8", "Hetzner location name")
sv(&kola.HetznerOptions.Image, "hetzner-image", "", "Hetzner image ID")
sv(&kola.HetznerOptions.InstanceType, "hetzner-instance-type", "cx11", "Hetzner instance type")
}

// Sync up the command line options if there is dependency
Expand All @@ -264,6 +270,7 @@ func syncOptions() error {
kola.EquinixMetalOptions.GSOptions = &kola.GCEOptions
kola.BrightboxOptions.Board = board
kola.ScalewayOptions.Board = board
kola.HetznerOptions.Board = board

validateOption := func(name, item string, valid []string) error {
for _, v := range valid {
Expand Down
12 changes: 12 additions & 0 deletions cmd/ore/hetzner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0

package main

import (
"github.com/flatcar/mantle/cmd/ore/hetzner"
)

func init() {
root.AddCommand(hetzner.Hetzner)
}
36 changes: 36 additions & 0 deletions cmd/ore/hetzner/gc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0

package hetzner

import (
"context"
"fmt"
"time"

"github.com/spf13/cobra"
)

var (
cmdGC = &cobra.Command{
Use: "gc",
Short: "GC resources in Hetzner",
Long: `Delete instances and images created over the given duration ago`,
RunE: runGC,
}

gcDuration time.Duration
)

func init() {
Hetzner.AddCommand(cmdGC)
cmdGC.Flags().DurationVar(&gcDuration, "duration", 5*time.Hour, "how old resources must be before they're considered garbage")
}

func runGC(cmd *cobra.Command, args []string) error {
if err := API.GC(context.Background(), gcDuration); err != nil {
return fmt.Errorf("running garbage collection: %w", err)
}

return nil
}
42 changes: 42 additions & 0 deletions cmd/ore/hetzner/hetzner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0
package hetzner

import (
"fmt"
"os"

"github.com/coreos/pkg/capnslog"
"github.com/flatcar/mantle/cli"
"github.com/flatcar/mantle/platform/api/hetzner"
"github.com/spf13/cobra"
)

var (
plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "ore/hetzner")

Hetzner = &cobra.Command{
Use: "hetzner [command]",
Short: "hetzner image utilities",
}

API *hetzner.API
options hetzner.Options
)

func init() {
cli.WrapPreRun(Hetzner, preflightCheck)
Hetzner.PersistentFlags().StringVar(&options.Token, "hetzner-token", "", "Hetzner token for client authentication")
Hetzner.PersistentFlags().StringVar(&options.Location, "hetzner-location", "", "Hetzner location name")
}

func preflightCheck(cmd *cobra.Command, args []string) error {
api, err := hetzner.New(&options)
if err != nil {
fmt.Fprintf(os.Stderr, "could not create Hetzner API client: %v\n", err)
os.Exit(1)
}

API = api
return nil
}
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/flatcar/mantle

go 1.20
go 1.21

toolchain go1.22.3

require (
cloud.google.com/go/storage v1.30.1
Expand All @@ -26,6 +28,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gophercloud/gophercloud v0.25.0
github.com/gophercloud/utils v0.0.0-20220704184730-55bdbbaec4ba
github.com/hetznercloud/hcloud-go/v2 v2.9.0
github.com/kballard/go-shellquote v0.0.0-20150810074751-d8ec1a69a250
github.com/kylelemons/godebug v0.0.0-20150519154555-21cb3784d9bd
github.com/packethost/packngo v0.21.0
Expand All @@ -43,11 +46,11 @@ require (
go.etcd.io/etcd/client/pkg/v3 v3.5.2
go.etcd.io/etcd/server/v3 v3.5.2
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.21.0
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.14.0
golang.org/x/sys v0.18.0
golang.org/x/text v0.14.0
golang.org/x/crypto v0.23.0
golang.org/x/net v0.25.0
golang.org/x/oauth2 v0.16.0
golang.org/x/sys v0.20.0
golang.org/x/text v0.15.0
google.golang.org/api v0.126.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -66,7 +69,7 @@ require (
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 // indirect
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clarketm/json v1.17.1 // indirect
Expand Down Expand Up @@ -95,23 +98,22 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.29 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/api/v3 v3.5.2 // indirect
Expand All @@ -127,7 +129,7 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
Loading