Skip to content

Commit

Permalink
feat: support clusterapi v1beta1
Browse files Browse the repository at this point in the history
Fixes: #76

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Nov 2, 2021
1 parent 1662815 commit 61fb582
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 244 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ There are a few corequisites and assumptions that go into using this project:
- [Cluster API Bootstrap Provider Talos](https://github.com/talos-systems/cluster-api-bootstrap-provider-talos)
- [Cluster API Provider Metal](https://github.com/talos-systems/cluster-api-provider-metal) (optional)

## Compatibility with Cluster API and Kubernetes Versions

This provider's versions are compatible with the following versions of Cluster API:

| | v1alpha3 (v0.3) | v1alpha4 (v0.4) | v1beta1 (v1.0) |
| -------------------------------------------- | --------------- | --------------- | -------------- |
| Control Plane Provider Talos v1alpha3 (v0.2) || | |
| Control Plane Provider Talos v1alpha3 (v0.3) | || |
| Control Plane Provider Talos v1alpha3 (v0.4) | | ||


This provider's versions are able to install and manage the following versions of Kubernetes:

| | v1.16 | v 1.17 | v1.18 | v1.19 | v1.20 | v1.21 | v1.22 |
| ------------------------------------------- | ----- | ------ | ----- | ----- | ----- | ----- | ----- |
| Control Plane Provider Talos v1alpha3 (v0.2) ||||||| |
| Control Plane Provider Talos v1alpha3 (v0.3) ||||||| |
| Control Plane Provider Talos v1alpha3 (v0.4) | | | |||||

This provider's versions are compatible with the following versions of Talos:

| | v0.11 | v 0.12 | v0.13 |
| -------------------------------------------- | ----- | ------ | ----- |
| Control Plane Provider Talos v1alpha3 (v0.3) ||| |
| Control Plane Provider Talos v1alpha3 (v0.3) ||||
| Control Plane Provider Talos v1alpha3 (v0.4) ||||

## Building and Installing

This control plane provider can be installed with clusterctl.
Expand Down Expand Up @@ -70,12 +97,12 @@ See your infrastructure provider for how to craft that.

Note the generateType mentioned above.
This is a required value in the spec for both init and controlplane nodes.
For a no-frills control plane config, you can simply specify `init` or `controlplane` depending on each config section.
For a no-frills control plane config, you can simply specify `controlplane` depending on each config section.
When creating a TalosControlPlane this way, you can then retrieve the talosconfig file that allows for osctl interaction with your nodes by doing something like `kubectl get talosconfig -o yaml talos-cp-xxxx -o jsonpath='{.status.talosConfig}'` after creation.

If you wish to do something more complex, we allow for the ability to supply an entire Talos config file to the resource.
This can be done by setting the generateType to `none` and specifying a `data` field.
This config file can be generated with `osctl config generate` and the edited to supply the various options you may desire.
This config file can be generated with `talosctl config generate` and the edited to supply the various options you may desire.
This full config is blindly copied from the `data` section of the spec and presented under `.status.controlPlaneData` so that the upstream CAPI controllers can see it and make use.

An example of a more complex config:
Expand Down Expand Up @@ -104,4 +131,4 @@ spec:
```

Note that specifying the full config above removes the ability for our control plane provider to generate a talosconfig for use.
As such, you should keep track of the talosconfig that's generated when running `osctl config generate`.
As such, you should keep track of the talosconfig that's generated when running `talosctl config generate`.
2 changes: 1 addition & 1 deletion api/v1alpha3/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// +groupName=controlplane.cluster.x-k8s.io
package v1alpha3

import clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

// Conditions and condition Reasons for the TalosControlPlane object

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/taloscontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
cabptv1 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ spec:
description: Type of condition in CamelCase or in foo.example.com/CamelCase. Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be useful (see .node.status.conditions), the ability to deconflict is important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
Expand Down
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
commonLabels:
cluster.x-k8s.io/v1alpha3: v1alpha3
cluster.x-k8s.io/v1alpha4: v1alpha3
cluster.x-k8s.io/v1beta1: v1alpha3

# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
Expand Down
3 changes: 3 additions & 0 deletions config/metadata/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ releaseSeries:
- major: 0
minor: 3
contract: v1alpha4
- major: 0
minor: 4
contract: v1beta1
4 changes: 2 additions & 2 deletions controllers/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/connrotation"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -76,7 +76,7 @@ func (r *TalosControlPlaneReconciler) kubeconfigForCluster(ctx context.Context,
}

// talosconfigForMachine will generate a talosconfig that uses *all* found addresses as the endpoints.
func (r *TalosControlPlaneReconciler) talosconfigForMachines(ctx context.Context, clientset *kubernetes.Clientset, machines ...capiv1.Machine) (*talosclient.Client, error) {
func (r *TalosControlPlaneReconciler) talosconfigForMachines(ctx context.Context, clientset *kubernetes.Clientset, machines ...clusterv1.Machine) (*talosclient.Client, error) {
if len(machines) == 0 {
return nil, fmt.Errorf("at least one machine should be provided")
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (

"github.com/talos-systems/talos/pkg/machinery/api/machine"
talosclient "github.com/talos-systems/talos/pkg/machinery/client"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (r *TalosControlPlaneReconciler) etcdHealthcheck(ctx context.Context, cluster *capiv1.Cluster, ownedMachines []capiv1.Machine) error {
func (r *TalosControlPlaneReconciler) etcdHealthcheck(ctx context.Context, cluster *clusterv1.Cluster, ownedMachines []clusterv1.Machine) error {
kubeclient, err := r.kubeconfigForCluster(ctx, util.ObjectKey(cluster))
if err != nil {
return err
}

defer kubeclient.Close() //nolint:errcheck

machines := []capiv1.Machine{}
machines := []clusterv1.Machine{}

for _, machine := range ownedMachines {
if machine.ObjectMeta.DeletionTimestamp.IsZero() {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (r *TalosControlPlaneReconciler) etcdHealthcheck(ctx context.Context, clust

// gracefulEtcdLeave removes a given machine from the etcd cluster by forfeiting leadership
// and issuing a "leave" request from the machine itself.
func (r *TalosControlPlaneReconciler) gracefulEtcdLeave(ctx context.Context, c *talosclient.Client, cluster client.ObjectKey, machineToLeave capiv1.Machine) error {
func (r *TalosControlPlaneReconciler) gracefulEtcdLeave(ctx context.Context, c *talosclient.Client, cluster client.ObjectKey, machineToLeave clusterv1.Machine) error {
r.Log.Info("Verifying etcd status", "machine", machineToLeave.Name, "node", machineToLeave.Status.NodeRef.Name)

svcs, err := c.ServiceInfo(ctx, "etcd")
Expand Down Expand Up @@ -166,7 +166,7 @@ func (r *TalosControlPlaneReconciler) auditEtcd(ctx context.Context, cluster cli
}
}
// Select the first CP machine that's not being deleted and has a noderef
var designatedCPMachine capiv1.Machine
var designatedCPMachine clusterv1.Machine

for _, machine := range machines {
if !machine.ObjectMeta.DeletionTimestamp.IsZero() || machine.Status.NodeRef == nil {
Expand Down
5 changes: 2 additions & 3 deletions controllers/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
talosclient "github.com/talos-systems/talos/pkg/machinery/client"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
)

Expand All @@ -29,7 +28,7 @@ func (e *errServiceUnhealthy) Error() string {
return fmt.Sprintf("Service %s is unhealthy: %s", e.service, e.reason)
}

func (r *TalosControlPlaneReconciler) nodesHealthcheck(ctx context.Context, cluster *capiv1.Cluster, machines []capiv1.Machine) error {
func (r *TalosControlPlaneReconciler) nodesHealthcheck(ctx context.Context, cluster *clusterv1.Cluster, machines []clusterv1.Machine) error {
kubeclient, err := r.kubeconfigForCluster(ctx, util.ObjectKey(cluster))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion controllers/taloscontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/external"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
Expand Down
62 changes: 31 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ require (
github.com/go-logr/zapr v0.4.0 // indirect
github.com/google/uuid v1.3.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.15.0
github.com/onsi/gomega v1.16.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
github.com/talos-systems/capi-utils v0.0.0-20210930173123-b2f8f83d3df6
github.com/talos-systems/cluster-api-bootstrap-provider-talos v0.4.0-alpha.0
github.com/talos-systems/capi-utils v0.0.0-20211101220445-144451cdef39
github.com/talos-systems/cluster-api-bootstrap-provider-talos v0.5.0-alpha.0
github.com/talos-systems/go-retry v0.3.1
github.com/talos-systems/talos/pkg/machinery v0.12.3
google.golang.org/grpc v1.40.0
github.com/talos-systems/talos/pkg/machinery v0.13.0
google.golang.org/grpc v1.41.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/apiserver v0.22.1
k8s.io/client-go v0.22.1
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
sigs.k8s.io/cluster-api v0.4.3
sigs.k8s.io/controller-runtime v0.9.7
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/apiserver v0.22.2
k8s.io/client-go v0.22.2
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
sigs.k8s.io/cluster-api v1.0.0
sigs.k8s.io/controller-runtime v0.10.2
)

require (
cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go v0.93.3 // indirect
github.com/AlekSi/pointer v1.1.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/containerd/go-cni v1.0.2 // indirect
github.com/containernetworking/cni v0.8.1 // indirect
github.com/cosi-project/runtime v0.0.0-20210707150857-25f235cd0682 // indirect
github.com/containerd/go-cni v1.1.0 // indirect
github.com/containernetworking/cni v1.0.1 // indirect
github.com/cosi-project/runtime v0.0.0-20210906201716-5cb7f5002d77 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/drone/envsubst/v2 v2.0.0-20210615175204-7bf45dbf5372 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gobuffalo/flect v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -57,48 +57,48 @@ require (
github.com/json-iterator/go v1.1.11 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.7.2 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.8.1 // indirect
github.com/spf13/viper v1.9.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/talos-systems/crypto v0.3.2 // indirect
github.com/talos-systems/crypto v0.3.4 // indirect
github.com/talos-systems/net v0.3.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f // indirect
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.21.4 // indirect
k8s.io/cluster-bootstrap v0.21.4 // indirect
k8s.io/component-base v0.22.1 // indirect
k8s.io/apiextensions-apiserver v0.22.2 // indirect
k8s.io/cluster-bootstrap v0.22.2 // indirect
k8s.io/component-base v0.22.2 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

0 comments on commit 61fb582

Please sign in to comment.