Skip to content

Commit

Permalink
added version label to components to allow operator to perform upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhatter committed Oct 24, 2023
1 parent 4858d96 commit 5425612
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 82 deletions.
10 changes: 10 additions & 0 deletions components/operator/controller/component_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"

"golang.org/x/mod/semver"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -43,6 +44,14 @@ func (cm *ComponentManager) SetupComponent(ctx context.Context, td *TemplateData
return false, log.ErrorN("unable to fetch component workload: %w", err)
}

// TODO use kubefox.LabelK8sVersion on lib release
ver := td.Obj.GetLabels()["kubefox.xigxog.io/version"]

if semver.Compare(ver, kubefox.Version()) < 0 {
log.Infof("version upgrade detected, applying template to upgrade %s->%s", ver, kubefox.Version())
return false, cm.Client.ApplyTemplate(ctx, td.Template, &td.Data)
}

var available int32
switch obj := td.Obj.(type) {
case *appsv1.StatefulSet:
Expand Down Expand Up @@ -116,6 +125,7 @@ func (cm *ComponentManager) ReconcileComponents(ctx context.Context, namespace s
Instance: templates.Instance{
Name: cm.Instance,
BootstrapImage: BootstrapImage,
Version: kubefox.Version(),
},
Platform: templates.Platform{
Name: platform.Name,
Expand Down
33 changes: 33 additions & 0 deletions components/operator/controller/component_mgr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright © 2023 XigXog
This Source Code Form is subject to the terms of the Mozilla Public License,
v2.0. If a copy of the MPL was not distributed with this file, You can obtain
one at https://mozilla.org/MPL/2.0/.
*/

package controller

import (
"testing"

"golang.org/x/mod/semver"
)

func TestSemVerCompare(t *testing.T) {
compare("main", "v0.1.0-alpha", t)
compare("v0.1.0-alpha", "v0.2.0-alpha", t)
compare("v0.2.0-alpha", "v0.1.0-alpha", t)
compare("v0.2.0-alpha", "v0.2.0-beta", t)
}

func compare(v, w string, t *testing.T) {
switch semver.Compare(v, w) {
case -1:
t.Logf("%s < %s", v, w)
case 0:
t.Logf("%s == %s", v, w)
case 1:
t.Logf("%s > %s", v, w)
}
}
4 changes: 0 additions & 4 deletions components/operator/controller/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func (r *DeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=deployments,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=deployments/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=deployments/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand Down
6 changes: 2 additions & 4 deletions components/operator/controller/platform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func (r *PlatformReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=platforms,verbs=get;list;watch
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=platforms/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=platforms/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *PlatformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand Down Expand Up @@ -130,6 +126,7 @@ func (r *PlatformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
Name: r.Instance,
Namespace: r.Namespace,
BootstrapImage: BootstrapImage,
Version: kubefox.Version(),
},
Component: templates.Component{
Name: "vault",
Expand Down Expand Up @@ -172,6 +169,7 @@ func (r *PlatformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
Namespace: r.Namespace,
RootCA: string(cm.Data["ca.crt"]),
BootstrapImage: BootstrapImage,
Version: kubefox.Version(),
},
Platform: templates.Platform{
Name: p.Name,
Expand Down
4 changes: 0 additions & 4 deletions components/operator/controller/release_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ type ReleaseReconciler struct {
log *logkf.Logger
}

//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=releases,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=releases/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=kubefox.xigxog.io,resources=releases/finalizers,verbs=update

// SetupWithManager sets up the controller with the Manager.
func (r *ReleaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.log = logkf.Global.With(logkf.KeyController, "release")
Expand Down
1 change: 1 addition & 0 deletions components/operator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/hashicorp/vault/api/auth/kubernetes v0.5.0
github.com/xigxog/kubefox/libs/api v0.2.1-alpha
github.com/xigxog/kubefox/libs/core v0.2.1-alpha
golang.org/x/mod v0.13.0
k8s.io/api v0.28.3
k8s.io/apiextensions-apiserver v0.28.3
k8s.io/apimachinery v0.28.3
Expand Down
2 changes: 2 additions & 0 deletions components/operator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
6 changes: 2 additions & 4 deletions components/operator/templates/helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ app.kubernetes.io/component: {{ . | quote }}
{{- with .Component.Commit }}
app.kubernetes.io/version: {{ . | quote }}
{{- end }}
{{- with .App.Commit }}
kubefox.xigxog.io/app-commit: {{ . | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ printf "%s-operator" .Instance.Name | quote }}
{{ .Labels | toYaml }}
kubefox.xigxog.io/version: {{ .Instance.Version | quote }}
{{ .ExtraLabels | toYaml }}
{{- end }}

{{- define "selectors" -}}
Expand Down
5 changes: 3 additions & 2 deletions components/operator/templates/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Data struct {
App App
Component Component

Labels map[string]string
Owner []*metav1.OwnerReference
ExtraLabels map[string]string
Owner []*metav1.OwnerReference

Values map[string]any
}
Expand All @@ -28,6 +28,7 @@ type Instance struct {
LogLevel string
LogFormat string
BootstrapImage string
Version string
}

type Platform struct {
Expand Down
7 changes: 6 additions & 1 deletion docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:root {
--md-tooltip-width: 300px;
--md-tooltip-width: 400px;
--md-text-font: "Open Sans", sans-serif;
--md-code-font: "Source Code Pro", monospace;
}
Expand Down Expand Up @@ -28,8 +28,13 @@ img[alt="diagram"] {

.md-typeset summary {
font-size: 0.9em;
font-weight: 600;
}

.md-typeset details {
font-size: 1em;
}

.md-tooltip {
text-align: center;
}
143 changes: 80 additions & 63 deletions docs/stylesheets/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,86 @@
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* cyrillic-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSKmu1aB.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSumu1aB.woff2) format('woff2');
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSOmu1aB.woff2) format('woff2');
unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSymu1aB.woff2) format('woff2');
unicode-range: U+0370-03FF;
}
/* hebrew */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTS2mu1aB.woff2) format('woff2');
unicode-range: U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}
/* vietnamese */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSCmu1aB.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSGmu1aB.woff2) format('woff2');
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
font-stretch: 100%;
font-display: swap;
src: url(https://fonts.gstatic.com/s/opensans/v36/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTS-muw.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* cyrillic-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
Expand Down Expand Up @@ -588,69 +668,6 @@
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* cyrillic-ext */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlMOvWjMY.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlOevWjMY.woff2) format('woff2');
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlMevWjMY.woff2) format('woff2');
unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlPuvWjMY.woff2) format('woff2');
unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlMuvWjMY.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlM-vWjMY.woff2) format('woff2');
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(https://fonts.gstatic.com/s/sourcecodepro/v23/HI_SiYsKILxRpg3hIP6sJ7fM7PqlPevW.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* cyrillic-ext */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
1 change: 1 addition & 0 deletions libs/core/kubefox/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
LabelK8sComponent string = "kubefox.xigxog.io/component"
LabelK8sComponentCommit string = "kubefox.xigxog.io/component-commit"
LabelK8sPlatform string = "kubefox.xigxog.io/platform"
LabelK8sVersion string = "kubefox.xigxog.io/version"
LabelOCIApp string = "com.xigxog.kubefox.app"
LabelOCIComponent string = "com.xigxog.kubefox.component"
LabelOCICreated string = "org.opencontainers.image.created"
Expand Down

0 comments on commit 5425612

Please sign in to comment.