Skip to content

Commit

Permalink
fix: cluster not getting created because of improper if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
waveywaves committed Aug 22, 2023
1 parent e7349c1 commit 70fb86c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include tests/e2e/Makefile

VERSION ?= 0.4.1
VERSION ?= 0.4.2

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version: 0.4.0
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.4.1"
appVersion: "v0.4.2"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
Expand Down
2 changes: 1 addition & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

image:
repository: docker.io/uffizzi/uffizzi-cluster-operator
tag: v0.4.1
tag: v0.4.2

# `flux` dependency values
flux:
Expand Down
63 changes: 21 additions & 42 deletions controllers/uffizzicluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// Check if there is already exists a VClusterK3S HelmRelease for this UCluster, if not create one
helmReleaseName := BuildVClusterHelmReleaseName(uCluster)
helmRelease := &fluxhelmv2beta1.HelmRelease{}
var newHelmRelease *fluxhelmv2beta1.HelmRelease
helmReleaseNamespacedName := client.ObjectKey{
Namespace: uCluster.Namespace,
Name: helmReleaseName,
Expand All @@ -169,7 +170,6 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if err != nil && k8serrors.IsNotFound(err) {
// helm release does not exist so let's create one
lifecycleOpType = LIFECYCLE_OP_TYPE_CREATE
newHelmRelease := &fluxhelmv2beta1.HelmRelease{}
if uCluster.Spec.Distro == VCLUSTER_K8S_DISTRO {
newHelmRelease, err = r.upsertVClusterK8sHelmRelease(false, ctx, uCluster)
if err != nil {
Expand All @@ -185,6 +185,10 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
}

if newHelmRelease == nil {
return ctrl.Result{}, nil
}

// create the ingress for the vcluster
vclusterIngressHost := BuildVClusterIngressHost(uCluster) // r.createVClusterIngress(ctx, uCluster)
if err != nil {
Expand Down Expand Up @@ -238,7 +242,7 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque

uCluster.Status.Conditions = uClusterConditions
if err := r.Status().Update(ctx, uCluster); err != nil {
logger.Error(err, "Failed to update UffizziCluster status")
//logger.Error(err, "Failed to update UffizziCluster status")
return ctrl.Result{RequeueAfter: time.Second * 5}, err
}
}
Expand All @@ -264,22 +268,27 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
}

var updatedHelmRelease *fluxhelmv2beta1.HelmRelease
if lifecycleOpType == LIFECYCLE_OP_TYPE_UPDATE {
if currentSpec != lastAppliedSpec {
if uCluster.Spec.Distro == VCLUSTER_K8S_DISTRO {
if _, err := r.upsertVClusterK8sHelmRelease(true, ctx, uCluster); err != nil {
if updatedHelmRelease, err = r.upsertVClusterK8sHelmRelease(true, ctx, uCluster); err != nil {
logger.Error(err, "Failed to update HelmRelease")
return ctrl.Result{Requeue: true}, err
return ctrl.Result{Requeue: true, RequeueAfter: time.Second * 5}, err
}
} else {
if _, err := r.upsertVClusterK3sHelmRelease(true, ctx, uCluster); err != nil {
if updatedHelmRelease, err = r.upsertVClusterK3sHelmRelease(true, ctx, uCluster); err != nil {
logger.Error(err, "Failed to update HelmRelease")
return ctrl.Result{Requeue: true}, err
return ctrl.Result{Requeue: true, RequeueAfter: time.Second * 5}, err
}
}
}
}

if updatedHelmRelease == nil {
return ctrl.Result{}, nil
}

// Requeue the request to check the status
return ctrl.Result{Requeue: true}, nil
}
Expand Down Expand Up @@ -342,38 +351,8 @@ func (r *UffizziClusterReconciler) upsertVClusterK3sHelmRelease(update bool, ctx
)

vclusterK3sHelmValues := VClusterK3S{
VCluster: Container{
VCluster: VClusterContainer{
Image: "rancher/k3s:v1.27.3-k3s1",
Command: []string{
"/bin/k3s",
},
BaseArgs: []string{
"server",
"--write-kubeconfig=/data/k3s-config/kube-config.yaml",
"--data-dir=/data",
"--disable=traefik,servicelb,metrics-server,local-storage,coredns",
"--disable-network-policy",
"--disable-agent",
"--disable-cloud-controller",
"--flannel-backend=none",
},
ExtraArgs: []string{},
VolumeMounts: []VClusterContainerVolumeMounts{
{
Name: "data",
MountPath: "/data",
},
},
Env: []Env{},
Resources: VClusterContainerResources{
Limits: VClusterContainerResourcesLimits{
Memory: "2Gi",
},
Requests: VClusterContainerResourcesRequests{
Memory: "256Mi",
Cpu: "200m",
},
},
},
Init: VClusterInit{},
FsGroup: 12345,
Expand All @@ -394,9 +373,9 @@ func (r *UffizziClusterReconciler) upsertVClusterK3sHelmRelease(update bool, ctx
RequestsMemory: "10Gi",
RequestsEphemeralStorage: "15Gi",
RequestsStorage: "10Gi",
LimitsCpu: "2.5",
LimitsMemory: "10Gi",
LimitsEphemeralStorage: "15Gi",
LimitsCpu: "10",
LimitsMemory: "15Gi",
LimitsEphemeralStorage: "30Gi",
ServicesLoadbalancers: 5,
ServicesNodePorts: 0,
CountEndpoints: 40,
Expand Down Expand Up @@ -482,7 +461,7 @@ func (r *UffizziClusterReconciler) upsertVClusterK3sHelmRelease(update bool, ctx
}

if uCluster.Spec.Ingress.Host != "" {
vclusterK3sHelmValues.Plugin.UffizziClusterSyncPlugin.Env = []Env{
vclusterK3sHelmValues.Plugin.UffizziClusterSyncPlugin.Env = []VClusterContainerEnv{
{
Name: "VCLUSTER_INGRESS_HOST",
Value: VClusterIngressHostname,
Expand Down Expand Up @@ -750,7 +729,7 @@ func (r *UffizziClusterReconciler) upsertVClusterK8sHelmRelease(update bool, ctx
}

if uCluster.Spec.Ingress.Host != "" {
vclusterHelmValues.Plugin.UffizziClusterSyncPlugin.Env = []Env{
vclusterHelmValues.Plugin.UffizziClusterSyncPlugin.Env = []VClusterContainerEnv{
{
Name: "VCLUSTER_INGRESS_HOST",
Value: VClusterIngressHostname,
Expand Down
30 changes: 15 additions & 15 deletions controllers/vcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controllers
import "github.com/UffizziCloud/uffizzi-cluster-operator/api/v1alpha1"

type VClusterK3S struct {
VCluster Container `json:"vcluster,omitempty"`
VCluster VClusterContainer `json:"vcluster,omitempty"`
Init VClusterInit `json:"init,omitempty"`
Syncer VClusterSyncer `json:"syncer,omitempty"`
Sync VClusterSync `json:"sync,omitempty"`
Expand Down Expand Up @@ -48,15 +48,15 @@ type VClusterK8SAPIServer struct {
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
}

// Container - parameters to create the vcluster container with
type Container struct {
Image string `json:"image,omitempty"`
Command []string `json:"command,omitempty"`
BaseArgs []string `json:"baseArgs,omitempty"`
ExtraArgs []string `json:"extraArgs,omitempty"`
Env []Env `json:"env,omitempty"`
VolumeMounts []VClusterContainerVolumeMounts `json:"volumeMounts,omitempty"`
Resources VClusterContainerResources `json:"resources,omitempty"`
// VClusterContainer - parameters to create the vcluster container with
type VClusterContainer struct {
Image string `json:"image,omitempty"`
//Command []string `json:"command,omitempty"`
//BaseArgs []string `json:"baseArgs,omitempty"`
//ExtraArgs []string `json:"extraArgs,omitempty"`
//Env []VClusterContainerEnv `json:"env,omitempty"`
//VolumeMounts []VClusterContainerVolumeMounts `json:"volumeMounts,omitempty"`
//Resources VClusterContainerResources `json:"resources,omitempty"`
}

type VClusterContainerResources struct {
Expand Down Expand Up @@ -96,13 +96,13 @@ type VClusterPlugins struct {
}

type VClusterPlugin struct {
Env []Env `json:"env,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Rbac VClusterRbac `json:"rbac,omitempty"`
Env []VClusterContainerEnv `json:"env,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Rbac VClusterRbac `json:"rbac,omitempty"`
}

type Env struct {
type VClusterContainerEnv struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
Expand Down
8 changes: 3 additions & 5 deletions examples/k3s-manifest-basic.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
kind: UffizziCluster
apiVersion: uffizzi.com/v1alpha1
metadata:
name: i39
name: i132
spec:
distro: k3s
apiServer:
image: "rancher/k3s:v1.26.0-k3s1"
distro: k8s
ingress:
host: app.qa-gke.uffizzi.com
host: i.app.uffizzi.com
resourceQuota:
enabled: false
limitRange:
Expand Down

0 comments on commit 70fb86c

Please sign in to comment.