Skip to content

Commit

Permalink
[POC] Cluster API provider for workers
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Nummelin <[email protected]>

Very rough skeleton for control plane provider using k0smotron

Signed-off-by: Jussi Nummelin <[email protected]>

Use k8s 1.27 as dependency

Signed-off-by: Jussi Nummelin <[email protected]>
  • Loading branch information
jnummelin committed Jun 5, 2023
1 parent f8a6e23 commit c9a073a
Show file tree
Hide file tree
Showing 31 changed files with 3,284 additions and 163 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ help: ## Display this help.
##@ Development

### manifests
manifests_targets += config/crd/bases/bootstrap.cluster.x-k8s.io_kzerosconfigs.yaml
config/crd/bases/bootstrap.cluster.x-k8s.io_kzerosconfigs.yaml: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

manifests_targets += config/crd/bases/k0smotron.io_clusters.yaml
config/crd/bases/k0smotron.io_clusters.yaml: $(CONTROLLER_GEN) api/k0smotron.io/v1beta1/k0smotroncluster_types.go
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Expand All @@ -69,13 +73,15 @@ api/k0smotron.io/v1beta1/zz_generated.deepcopy.go: $(CONTROLLER_GEN)

generate: $(generate_targets) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.


GO_PKGS=$(shell go list ./... | grep -v /inttest/)
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
go fmt $(GO_PKGS)

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
go vet $(GO_PKGS)

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
Expand Down
36 changes: 36 additions & 0 deletions api/bootstrap/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023.
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.
*/

// Package v1beta1 contains API Schema definitions for the v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=bootstrap.cluster.x-k8s.io
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "bootstrap.cluster.x-k8s.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
74 changes: 74 additions & 0 deletions api/bootstrap/v1beta1/kzeros_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
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.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

func init() {
SchemeBuilder.Register(&KZerosWorkerConfig{}, &KZerosWorkerConfigList{})
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="cluster.x-k8s.io/v1beta1=v1beta1"

type KZerosWorkerConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KZerosWorkerConfigSpec `json:"spec,omitempty"`
Status KZerosWorkerConfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

type KZerosWorkerConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KZerosWorkerConfig `json:"items"`
}

type KZerosWorkerConfigSpec struct {
// JoinTokenSecretRef is a reference to a secret that contains the join token
// +kubebuilder:validation:Required
JoinTokenSecretRef *JoinTokenSecretRef `json:"joinTokenSecretRef,omitempty"`
}

type JoinTokenSecretRef struct {
// Name is the name of the secret
// +kubebuilder:validation:Required
Name string `json:"name"`
// Key is the key in the secret that contains the join token
// +kubebuilder:validation:Required
Key string `json:"key"`
}

type KZerosWorkerConfigStatus struct {
// Ready indicates the Bootstrapdata field is ready to be consumed
Ready bool `json:"ready,omitempty"`

// DataSecretName is the name of the secret that stores the bootstrap data script.
// +optional
DataSecretName *string `json:"dataSecretName,omitempty"`
// TODO Conditions etc
}
140 changes: 140 additions & 0 deletions api/bootstrap/v1beta1/zz_generated.deepcopy.go

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

36 changes: 36 additions & 0 deletions api/controlplane/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023.
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.
*/

// Package v1beta1 contains API Schema definitions for the v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=controlplane.cluster.x-k8s.io
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
56 changes: 56 additions & 0 deletions api/controlplane/v1beta1/k0smotron_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
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.
*/

package v1beta1

import (
kmapi "github.com/k0sproject/k0smotron/api/k0smotron.io/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const K0smotronControlPlaneFinalizer = "k0smotron.controlplane.cluster.x-k8s.io"

func init() {
SchemeBuilder.Register(&K0smotronControlPlane{}, &K0smotronControlPlaneList{})
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="cluster.x-k8s.io/v1beta1=v1beta1"

type K0smotronControlPlane struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec kmapi.ClusterSpec `json:"spec,omitempty"`

Status K0smotronControlPlaneStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

type K0smotronControlPlaneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []K0smotronControlPlane `json:"items"`
}

type K0smotronControlPlaneStatus struct {
// Ready denotes that the control plane is ready
Ready bool `json:"ready"`
ControlPlaneReady bool `json:"controlPlaneReady"`
Inititalized bool `json:"initialized"`
ExternalManagedControlPlane bool `json:"externalManagedControlPlane"`
}
Loading

0 comments on commit c9a073a

Please sign in to comment.