Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 30 additions & 27 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ jobs:
run: |

# Install clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.9.3/clusterctl-linux-amd64 -o clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.11.2/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl
sudo mv clusterctl /usr/local/bin/

#Install Kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-amd64
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.30.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

# Install envsubst
GOBIN="$(pwd)/bin" go install -tags tools github.com/drone/envsubst/v2/cmd/[email protected]

# Install kubectl
curl -LO "https://dl.k8s.io/release/v1.31.4/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/v1.33.2/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Expand All @@ -87,7 +87,7 @@ jobs:

- name: Create and Start Kind Cluster
run: |
kind create cluster --image=kindest/node:v1.31.4@sha256:2cb39f7295fe7eafee0842b1052a599a4fb0f8bcf3f83d96c7f4864c357c6c30
kind create cluster --image=kindest/node:v1.33.2
echo "=== cluster-info ==="
kubectl cluster-info --context kind-kind

Expand All @@ -97,7 +97,7 @@ jobs:
echo "=== config get-contexts ==="
kubectl config get-contexts

- name: DevSpace Deploy
- name: Deploy
run: |
devspace deploy -p deploy

Expand All @@ -114,32 +114,12 @@ jobs:
echo "=== Test get crd ==="
kubectl get crd

- name: Create Vcluster Custom Resource K3S
run: |
export CLUSTER_NAME=vcluster-k3s
export CLUSTER_NAMESPACE=vcluster-k3s
export VCLUSTER_YAML=$(cat ./test/e2e/k3s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

- name: Validate Resource Ready K3S
run: |
kubectl wait --for=condition=ready vcluster.infrastructure.cluster.x-k8s.io -n vcluster-k3s vcluster-k3s --timeout=100s

- name: Connect to vcluster and install nginx
run: |
vcluster -n vcluster-k3s connect vcluster-k3s --background-proxy=true
kubectl create namespace demo-nginx
kubectl -n demo-nginx create deployment nginx-deployment --image=nginx
kubectl -n demo-nginx rollout status deployment/nginx-deployment --timeout=100s
vcluster disconnect

- name: Create Vcluster Custom Resource K8S
- name: Create VCluster Custom Resource K8S
run: |
export CLUSTER_NAME=vcluster-k8s
export CLUSTER_NAMESPACE=vcluster-k8s
export CHART_NAME=vcluster
export VCLUSTER_YAML=$(cat ./test/e2e/k8s-values.yaml | sed -z 's/\n/\\n/g')
export VCLUSTER_YAML=$(cat ./test/e2e/values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

Expand All @@ -154,3 +134,26 @@ jobs:
kubectl -n demo-nginx create deployment nginx-deployment --image=nginx
kubectl -n demo-nginx rollout status deployment/nginx-deployment --timeout=100s
vcluster disconnect

- name: Print logs if e2e tests fail
if: ${{ failure() }}
run: |
set -x
free -h
df -h
docker system df
lscpu
echo "======================================================================================================================"
kubectl get clusters -o yaml -n vcluster-k8s
kubectl get vclusters -o yaml -n vcluster-k8s
echo "======================================================================================================================"
kubectl get pods -o yaml -n vcluster-k8s
echo "======================================================================================================================"
kubectl get events -n vcluster-k8s --sort-by='.lastTimestamp'
echo "======================================================================================================================"
kubectl get pods -A
echo "======================================================================================================================"
kubectl get ns
echo "======================================================================================================================"
kubectl logs -l release=vcluster-k8s -n vcluster-k8s --tail=-1 -p || kubectl logs -l release=vcluster-k8s -n vcluster-k8s --tail=-1
exit 1
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ linters:
- misspell
- nakedret
- nilnil
- prealloc
- promlinter
- revive
- staticcheck
Expand Down
4 changes: 2 additions & 2 deletions api/infrastructure/v1alpha1/vcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
Expand All @@ -30,7 +30,7 @@ type VClusterSpec struct {

// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1beta1.APIEndpoint `json:"controlPlaneEndpoint"`
ControlPlaneEndpoint *clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// The helm release configuration for the virtual cluster. This is optional, but
// when filled, specified chart will be deployed.
Expand Down
112 changes: 112 additions & 0 deletions api/infrastructure/v1alpha1/vnodecluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2022.

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 v1alpha1

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

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// VNodeClusterSpec defines the desired state of VCluster
type VNodeClusterSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

// VNodeClusterStatus defines the observed state of VCluster
type VNodeClusterStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// Ready defines if the virtual cluster control plane is ready.
// +optional
// +kubebuilder:default=false
Ready bool `json:"ready"`

// Reason describes the reason in machine readable form why the cluster is in the current
// phase
// +optional
Reason string `json:"reason,omitempty"`

// Message describes the reason in human readable form why the cluster is in the currrent
// phase
// +optional
Message string `json:"message,omitempty"`

// Conditions holds several conditions the vcluster might be in
// +optional
Conditions Conditions `json:"conditions,omitempty"`

// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// ExternalManagedControlPlane is required by Cluster API to indicate that the control plane
// is externally managed.
// +optional
ExternalManagedControlPlane *bool `json:"externalManagedControlPlane,omitempty"`
}

// GetConditions returns the set of conditions for this object.
func (v *VNodeCluster) GetConditions() Conditions {
return v.Status.Conditions
}

// SetConditions sets the conditions on this object.
func (v *VNodeCluster) SetConditions(conditions Conditions) {
v.Status.Conditions = conditions
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
//+kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// VNodeCluster is the Schema for the vnodeclusters API
type VNodeCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VNodeClusterSpec `json:"spec,omitempty"`
Status VNodeClusterStatus `json:"status,omitempty"`
}

func (v *VNodeCluster) GetSpec() *VNodeClusterSpec {
return &v.Spec
}

func (v *VNodeCluster) GetStatus() *VNodeClusterStatus {
return &v.Status
}

//+kubebuilder:object:root=true

// VNodeClusterList contains a list of VNodeCluster
type VNodeClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VNodeCluster `json:"items"`
}

func init() {
SchemeBuilder.Register(&VNodeCluster{}, &VNodeClusterList{})
}
134 changes: 134 additions & 0 deletions api/infrastructure/v1alpha1/vnodemachine_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package v1alpha1

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

// Common ConditionTypes used by Cluster API objects.
const (
PodProvisionedCondition ConditionType = "PodProvisioned"
)

const (
// MachineFinalizer allows ReconcileKubevirtMachine to clean up resources associated with machine before
// removing it from the apiserver.
MachineFinalizer = "vnodemachine.infrastructure.cluster.x-k8s.io"
)

// VNodeMachineSpec defines the desired state of VNodeMachine.
type VNodeMachineSpec struct {
// ProviderID TBD what to use for VNode
// +optional
ProviderID *string `json:"providerID,omitempty"`

// PodTemplate contains the pod template to use for the machine.
PodTemplate PodTemplate `json:"podTemplate,omitempty"`
}

// VNodeMachineStatus defines the observed state of VNodeMachine.
type VNodeMachineStatus struct {
// Ready denotes that the machine is ready
// +kubebuilder:default=false
Ready bool `json:"ready"`

// Addresses contains the associated addresses for the machine.
// +optional
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`

// Conditions defines current service state of the KubevirtMachine.
// +optional
Conditions Conditions `json:"conditions,omitempty"`

// NodeUpdated denotes that the ProviderID is updated on Node of this KubevirtMachine
// +optional
NodeUpdated bool `json:"nodeupdated"`

// FailureReason will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a succinct value suitable
// for machine interpretation.
//
// This field should not be set for transitive errors that a controller
// faces that are expected to be fixed automatically over
// time (like service outages), but instead indicate that something is
// fundamentally wrong with the Machine's spec or the configuration of
// the controller, and that manual intervention is required. Examples
// of terminal errors would be invalid combinations of settings in the
// spec, values that are unsupported by the controller, or the
// responsible controller itself being critically misconfigured.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureReason string `json:"failureReason,omitempty"`

// FailureMessage will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a more verbose string suitable
// for logging and human consumption.
//
// This field should not be set for transitive errors that a controller
// faces that are expected to be fixed automatically over
// time (like service outages), but instead indicate that something is
// fundamentally wrong with the Machine's spec or the configuration of
// the controller, and that manual intervention is required. Examples
// of terminal errors would be invalid combinations of settings in the
// spec, values that are unsupported by the controller, or the
// responsible controller itself being critically misconfigured.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
}

type PodTemplate struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Specification of the desired behavior of the pod.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Spec runtime.RawExtension `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}

// +kubebuilder:resource:path=vnodemachines,scope=Namespaced,categories=cluster-api
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready",description="Is machine ready"

// VNodeMachine is the Schema for the vnodemachines API.
type VNodeMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VNodeMachineSpec `json:"spec,omitempty"`
Status VNodeMachineStatus `json:"status,omitempty"`
}

func (c *VNodeMachine) GetConditions() Conditions {
return c.Status.Conditions
}

func (c *VNodeMachine) SetConditions(conditions Conditions) {
c.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

// VNodeMachineList contains a list of VNodeMachine.
type VNodeMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VNodeMachine `json:"items"`
}

func init() {
SchemeBuilder.Register(&VNodeMachine{}, &VNodeMachineList{})
}
Loading