Skip to content

Commit

Permalink
feat: support global config patches which can be applied to all machines
Browse files Browse the repository at this point in the history
The provider now has `--config-patch` cmd line argument which can
configure it to create config patches for each created machine.

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Nov 12, 2024
1 parent deb6fcc commit 18bd814
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 109 deletions.
27 changes: 26 additions & 1 deletion cmd/omni-infra-provider-kubevirt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import (
"os"
"os/signal"
"slices"
"strings"
"syscall"

"github.com/siderolabs/omni/client/pkg/client"
"github.com/siderolabs/omni/client/pkg/infra"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/yaml.v3"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -90,7 +92,28 @@ var rootCmd = &cobra.Command{
return fmt.Errorf("data-volume-mode flags should be one of %s", volumeOpts)
}

provisioner := provider.NewProvisioner(k8sClient, cfg.namespace, cfg.dataVolumeMode)
patches := make([]provider.ConfigPatch, 0, len(cfg.configPatches))

for _, patch := range cfg.configPatches {
data := []byte(patch)

if strings.HasPrefix(patch, "@") {
data, err = os.ReadFile(strings.TrimPrefix(patch, "@"))
if err != nil {
return err
}
}

var p provider.ConfigPatch

if err = yaml.Unmarshal(data, &p); err != nil {
return err
}

patches = append(patches, p)
}

provisioner := provider.NewProvisioner(k8sClient, cfg.namespace, cfg.dataVolumeMode, patches)

ip, err := infra.NewProvider(meta.ProviderID, provisioner, infra.ProviderConfig{
Name: cfg.providerName,
Expand Down Expand Up @@ -126,6 +149,7 @@ var cfg struct {
kubeconfigFile string
namespace string
dataVolumeMode string
configPatches []string
insecureSkipVerify bool
}

Expand All @@ -152,5 +176,6 @@ func init() {
rootCmd.Flags().StringVar(&cfg.kubeconfigFile, "kubeconfig-file", "~/.kube/config", "Kubeconfig file to use to connect to the cluster where KubeVirt is running")
rootCmd.Flags().StringVar(&cfg.namespace, "namespace", "default", "Kubernetes namespace to use for the resources created by the provider")
rootCmd.Flags().StringVar(&cfg.dataVolumeMode, "data-volume-mode", "", "DataVolume PVC type to use (Block|Filesystem)")
rootCmd.Flags().StringArrayVar(&cfg.configPatches, "config-patch", nil, "Applies config patches for all machines created by the infra provider")
rootCmd.Flags().BoolVar(&cfg.insecureSkipVerify, "insecure-skip-verify", false, "ignores untrusted certs on Omni side")
}
64 changes: 32 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ go 1.23.0
replace gopkg.in/yaml.v3 => github.com/unix4ever/yaml v0.0.0-20220527175918-f17b0f05cf2c

require (
github.com/cosi-project/runtime v0.6.4
github.com/cosi-project/runtime v0.7.1
github.com/google/uuid v1.6.0
github.com/planetscale/vtprotobuf v0.6.1-0.20240917153116-6f2963f01587
github.com/siderolabs/go-pointer v1.0.0
github.com/siderolabs/omni/client v0.0.0-20241018142957-c754cdc0d76b
github.com/siderolabs/omni/client v0.0.0-20241112155921-05ab993d3da6
github.com/spf13/cobra v1.8.1
go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.34.2
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
google.golang.org/protobuf v1.35.1
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.31.2
k8s.io/apimachinery v0.31.2
k8s.io/client-go v0.31.2
kubevirt.io/api v1.3.1
kubevirt.io/containerized-data-importer-api v1.60.3
sigs.k8s.io/controller-runtime v0.19.0
)

require (
github.com/ProtonMail/go-crypto v1.1.0-alpha.5.0.20240827111422-b5837fa4476e // indirect
github.com/ProtonMail/go-crypto v1.1.0-beta.0-proton // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/ProtonMail/gopenpgp/v2 v2.7.5 // indirect
github.com/adrg/xdg v0.5.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/adrg/xdg v0.5.3 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/containerd/go-cni v1.1.10 // indirect
github.com/containernetworking/cni v1.2.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -50,7 +51,7 @@ require (
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand All @@ -59,9 +60,9 @@ require (
github.com/josharian/native v1.1.0 // indirect
github.com/jsimonetti/rtnetlink/v2 v2.0.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mdlayher/ethtool v0.1.0 // indirect
github.com/mdlayher/ethtool v0.2.0 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
Expand All @@ -73,41 +74,40 @@ require (
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/siderolabs/crypto v0.4.4 // indirect
github.com/siderolabs/gen v0.5.0 // indirect
github.com/siderolabs/crypto v0.5.0 // indirect
github.com/siderolabs/gen v0.7.0 // indirect
github.com/siderolabs/go-api-signature v0.3.6 // indirect
github.com/siderolabs/go-blockdevice v0.4.7 // indirect
github.com/siderolabs/go-blockdevice/v2 v2.0.2 // indirect
github.com/siderolabs/go-blockdevice v0.4.8 // indirect
github.com/siderolabs/go-blockdevice/v2 v2.0.3 // indirect
github.com/siderolabs/image-factory v0.5.0 // indirect
github.com/siderolabs/net v0.4.0 // indirect
github.com/siderolabs/proto-codec v0.1.1 // indirect
github.com/siderolabs/protoenc v0.2.1 // indirect
github.com/siderolabs/talos/pkg/machinery v1.8.0 // indirect
github.com/siderolabs/talos/pkg/machinery v1.8.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240709000822-3c01b740850f // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 18bd814

Please sign in to comment.