Skip to content

Commit

Permalink
Merge pull request k0sproject#357 from makhov/remotemachine-pool
Browse files Browse the repository at this point in the history
RemoteMachine "pool"
  • Loading branch information
makhov authored Jan 2, 2024
2 parents 22d0b8f + ed3cd60 commit 4c83c7b
Show file tree
Hide file tree
Showing 19 changed files with 1,202 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
- check-capi-controlplane-docker-tunneling-proxy
- check-capi-controlplane-docker-worker
- check-capi-remote-machine
- check-capi-remote-machine-template
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ manifests: $(manifests_targets) ## Generate WebhookConfiguration, ClusterRole an
generate_targets += api/k0smotron.io/v1beta1/zz_generated.deepcopy.go
generate_targets += api/bootstrap/v1beta1/zz_generated.deepcopy.go
generate_targets += api/controlplane/v1beta1/zz_generated.deepcopy.go
generate_targets += api/infrastructure/v1beta1/zz_generated.deepcopy.go
$(generate_targets): $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

Expand Down
61 changes: 61 additions & 0 deletions api/infrastructure/v1beta1/remote_machine_template_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
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

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// 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(&RemoteMachineTemplate{}, &RemoteMachineTemplateList{})
}

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

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

Spec RemoteMachineTemplateSpec `json:"spec,omitempty"`
}

type RemoteMachineTemplateSpec struct {
Template RemoteMachineTemplateResource `json:"template"`
}

type RemoteMachineTemplateResource struct {
// +kubebuilder:validation:Optional
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RemoteMachineTemplateResourceSpec `json:"spec,omitempty"`
}

type RemoteMachineTemplateResourceSpec struct {
Pool string `json:"pool"`
}

// +kubebuilder:object:root=true

type RemoteMachineTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RemoteMachineTemplate `json:"items"`
}
76 changes: 67 additions & 9 deletions api/infrastructure/v1beta1/remote_machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

func init() {
SchemeBuilder.Register(&RemoteMachine{}, &RemoteMachineList{}, &RemoteCluster{}, &RemoteClusterList{})
SchemeBuilder.Register(&RemoteMachine{}, &RemoteMachineList{}, &RemoteCluster{}, &RemoteClusterList{}, &PooledRemoteMachine{}, &PooledRemoteMachineList{})
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -75,28 +75,32 @@ type RemoteMachine struct {

// RemoteMachineSpec defines the desired state of RemoteMachine
type RemoteMachineSpec struct {
// Pool is the name of the pool where the machine belongs to.
// +kubebuilder:validation:Optional
Pool string `json:"pool,omitempty"`

// ProviderID is the ID of the machine in the provider.
// +kubebuilder:validation:Optional
ProviderID string `json:"providerID,omitempty"`

// Address is the IP address or DNS name of the remote machine.
// +kubebuilder:validation:Required
Address string `json:"address"`
// +kubebuilder:validation:Optional
Address string `json:"address,omitempty"`

// Port is the SSH port of the remote machine.
// +kubebuilder:validation:Optional
// +kubebuilder:default=22
Port int `json:"port"`
Port int `json:"port,omitempty"`

// User is the user to use when connecting to the remote machine.
// +kubebuilder:validation:Optional
// +kubebuilder:default="root"
User string `json:"user"`
User string `json:"user,omitempty"`

// SSHKeyRef is a reference to a secret that contains the SSH private key.
// The key must be placed on the secret using the key "value".
// +kubebuilder:validation:Required
SSHKeyRef SecretRef `json:"sshKeyRef"`
// +kubebuilder:validation:Optional
SSHKeyRef SecretRef `json:"sshKeyRef,omitempty"`
}

// RemoteMachineStatus defines the observed state of RemoteMachine
Expand All @@ -107,8 +111,6 @@ type RemoteMachineStatus struct {

FailureReason string `json:"failureReason,omitempty"`
FailureMessage string `json:"failureMessage,omitempty"`

// TODO Add conditions
}

type SecretRef struct {
Expand All @@ -124,3 +126,59 @@ type RemoteMachineList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []RemoteMachine `json:"items"`
}

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

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

Spec PooledRemoteMachineSpec `json:"spec,omitempty"`
Status PooledRemoteMachineStatus `json:"status,omitempty"`
}

type PooledRemoteMachineSpec struct {
Pool string `json:"pool"`
Machine PooledMachineSpec `json:"machine"`
}

type PooledMachineSpec struct {
// Address is the IP address or DNS name of the remote machine.
// +kubebuilder:validation:Required
Address string `json:"address"`

// Port is the SSH port of the remote machine.
// +kubebuilder:validation:Optional
// +kubebuilder:default=22
Port int `json:"port"`

// User is the user to use when connecting to the remote machine.
// +kubebuilder:validation:Optional
// +kubebuilder:default="root"
User string `json:"user"`

// SSHKeyRef is a reference to a secret that contains the SSH private key.
// The key must be placed on the secret using the key "value".
// +kubebuilder:validation:Required
SSHKeyRef SecretRef `json:"sshKeyRef"`
}

type PooledRemoteMachineStatus struct {
Reserved bool `json:"reserved"`
MachineRef RemoteMachineRef `json:"machineRef"`
}

type RemoteMachineRef struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
}

// +kubebuilder:object:root=true

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

0 comments on commit 4c83c7b

Please sign in to comment.