Skip to content

Commit 06712fe

Browse files
rsmittytalos-bot
authored andcommitted
feat: support talosVersion in talosconfig CRD
This PR pulls in a newer version of the talos config machinery, as well as allows users to specify a "talosVersion" as part of the talosConfig struct. This enables backward compatibility for generating multiple machine config types. Signed-off-by: Spencer Smith <[email protected]>
1 parent 96ffeed commit 06712fe

File tree

7 files changed

+68
-21
lines changed

7 files changed

+68
-21
lines changed

api/v1alpha2/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha3/talosconfig_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const (
2626

2727
// TalosConfigSpec defines the desired state of TalosConfig
2828
type TalosConfigSpec struct {
29-
GenerateType string `json:"generateType"` //none,init,controlplane,worker mutually exclusive w/ data
29+
TalosVersion string `json:"talosVersion,omitempty"` //talos version formatted like v0.8. used for backwards compatibility
30+
GenerateType string `json:"generateType"` //none,init,controlplane,worker mutually exclusive w/ data
3031
Data string `json:"data,omitempty"`
3132
ConfigPatches []ConfigPatches `json:"configPatches,omitempty"`
3233
// Important: Run "make" to regenerate code after modifying this file

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ spec:
110110
type: string
111111
generateType:
112112
type: string
113+
talosVersion:
114+
type: string
113115
required:
114116
- generateType
115117
type: object

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigtemplates.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ spec:
104104
type: string
105105
generateType:
106106
type: string
107+
talosVersion:
108+
type: string
107109
required:
108110
- generateType
109111
type: object

controllers/talosconfig_controller.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
jsonpatch "github.com/evanphx/json-patch"
2828
"github.com/go-logr/logr"
2929
bootstrapv1alpha3 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
30+
"github.com/talos-systems/talos/pkg/machinery/config"
3031
"github.com/talos-systems/talos/pkg/machinery/config/configpatcher"
3132
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
3233
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/generate"
@@ -56,6 +57,10 @@ const (
5657
controllerName = "cabpt-controller"
5758
)
5859

60+
var (
61+
defaultVersionContract = config.TalosVersion0_8
62+
)
63+
5964
// TalosConfigReconciler reconciles a TalosConfig object
6065
type TalosConfigReconciler struct {
6166
client.Client
@@ -383,7 +388,20 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
383388

384389
genOptions := []generate.GenOption{generate.WithDNSDomain(clusterDNS)}
385390

386-
secretBundle, err := generate.NewSecretsBundle()
391+
// default version contract to v0.8 unless user specifies something different.
392+
versionContract := defaultVersionContract
393+
394+
if scope.Config.Spec.TalosVersion != "" {
395+
var err error
396+
versionContract, err = config.ParseContractFromVersion(scope.Config.Spec.TalosVersion)
397+
if err != nil {
398+
return retBundle, fmt.Errorf("invalid talos-version: %w", err)
399+
}
400+
}
401+
402+
genOptions = append(genOptions, generate.WithVersionContract(versionContract))
403+
404+
secretBundle, err := generate.NewSecretsBundle(generate.NewClock(), genOptions...)
387405
if err != nil {
388406
return retBundle, err
389407
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ require (
1010
github.com/onsi/ginkgo v1.12.1
1111
github.com/onsi/gomega v1.10.1
1212
github.com/spf13/pflag v1.0.5
13-
github.com/talos-systems/crypto v0.2.0
14-
github.com/talos-systems/talos/pkg/machinery v0.0.0-20201203014938-ed31056d91d0
13+
github.com/talos-systems/crypto v0.2.1-0.20210202170911-39584f1b6e54
14+
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210216142802-8d7a36cc0cc2
1515
gopkg.in/yaml.v2 v2.3.0
1616
k8s.io/api v0.17.9
1717
k8s.io/apiextensions-apiserver v0.17.9

0 commit comments

Comments
 (0)