Skip to content

Commit 390891f

Browse files
committed
create cluster ISO image
1 parent 0ecfe96 commit 390891f

File tree

12 files changed

+305
-60
lines changed

12 files changed

+305
-60
lines changed

.github/workflows/lint.yml

+11-14
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ on:
33
push:
44
branches:
55
- master
6-
pull_request:
7-
paths:
8-
- '**'
96

10-
concurrency:
11-
group: lint-${{ github.ref || github.head_ref }}
12-
cancel-in-progress: true
13-
14-
env:
15-
FORCE_COLOR: 1
167
jobs:
17-
call-workflow:
18-
uses: kairos-io/linting-composite-action/.github/workflows/[email protected]
19-
with:
20-
yamldirs: ".github/workflows/ config/"
21-
is-go: true
8+
lint:
9+
name: Lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-go@v5
14+
with:
15+
go-version-file: go.mod
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v6
18+

.github/workflows/test.yml

-32
This file was deleted.

charts/osbuilder/templates/deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
image: '{{ .Values.builder.image.repository | default "ghcr.io/pluralsh/osbuilder" }}:{{ .Values.builder.image.tag | default .Chart.AppVersion }}'
2929
command: [ '/manager' ]
3030
args:
31+
- --console-url={{ .Values.builder.consoleUrl }}
32+
- --console-token={{ .Values.builder.consoleToken }}
3133
- --pvc-storage-size={{ .Values.builder.pvcStorageSize }}
3234
- --health-probe-bind-address=:8081
3335
- --metrics-bind-address=127.0.0.1:8080

charts/osbuilder/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ builder:
1616
tag: ~
1717

1818
replicas: 1
19+
consoleUrl: ""
20+
consoleToken: ""
21+
1922

2023
# The PVC storage size for the build process
2124
pvcStorageSize: "30Gi"

controllers/osartifact_controller.go

+38-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import (
2121
"fmt"
2222
"time"
2323

24-
"k8s.io/apimachinery/pkg/api/meta"
25-
26-
"k8s.io/apimachinery/pkg/api/errors"
27-
24+
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
25+
consoleclient "github.com/kairos-io/osbuilder/pkg/client"
26+
console "github.com/pluralsh/console/go/client"
2827
batchv1 "k8s.io/api/batch/v1"
2928
corev1 "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/api/errors"
3030
apierrors "k8s.io/apimachinery/pkg/api/errors"
31+
"k8s.io/apimachinery/pkg/api/meta"
3132
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3233
"k8s.io/apimachinery/pkg/labels"
3334
"k8s.io/apimachinery/pkg/runtime"
@@ -40,8 +41,6 @@ import (
4041
"sigs.k8s.io/controller-runtime/pkg/log"
4142
"sigs.k8s.io/controller-runtime/pkg/predicate"
4243
"sigs.k8s.io/controller-runtime/pkg/reconcile"
43-
44-
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
4544
)
4645

4746
const (
@@ -60,6 +59,7 @@ var (
6059
// OSArtifactReconciler reconciles a OSArtifact object
6160
type OSArtifactReconciler struct {
6261
client.Client
62+
ConsoleClient consoleclient.Client
6363
Scheme *runtime.Scheme
6464
ServingImage, ToolImage, CopierImage, PVCStorage string
6565
}
@@ -404,8 +404,18 @@ func (r *OSArtifactReconciler) checkExport(ctx context.Context, artifact *osbuil
404404
}
405405

406406
} else if job.Spec.Completions != nil {
407-
if job.Status.Succeeded > 0 {
407+
if job.Status.Succeeded > 0 && artifact.Status.Phase == osbuilder.Exporting {
408408
artifact.Status.Phase = osbuilder.Ready
409+
if err := r.upsertClusterIsoImage(artifact); err != nil {
410+
artifact.Status.Phase = osbuilder.Error
411+
meta.SetStatusCondition(&artifact.Status.Conditions, metav1.Condition{
412+
Type: "Ready",
413+
Status: metav1.ConditionFalse,
414+
Reason: "Error",
415+
Message: consoleclient.GetErrorResponse(err, "CreateClusterIsoImage").Error(),
416+
})
417+
}
418+
409419
if err := TryToUpdateStatus(ctx, r.Client, artifact); err != nil {
410420
log.FromContext(ctx).Error(err, "failed to update artifact status")
411421
return ctrl.Result{}, err
@@ -434,6 +444,27 @@ func (r *OSArtifactReconciler) checkExport(ctx context.Context, artifact *osbuil
434444
return requeue, nil
435445
}
436446

447+
func (r *OSArtifactReconciler) upsertClusterIsoImage(artifact *osbuilder.OSArtifact) error {
448+
image := fmt.Sprintf("%s:%s", artifact.Spec.Exporter.Registry.Image.Repository, artifact.Spec.Exporter.Registry.Image.Tag)
449+
attr := console.ClusterIsoImageAttributes{
450+
Image: image,
451+
Registry: artifact.Spec.Exporter.Registry.Name,
452+
}
453+
454+
getResponse, err := r.ConsoleClient.GetClusterIsoImage(&image)
455+
if err != nil {
456+
if errors.IsNotFound(err) {
457+
_, err := r.ConsoleClient.CreateClusterIsoImage(attr)
458+
return err
459+
}
460+
return err
461+
}
462+
if _, err := r.ConsoleClient.UpdateClusterIsoImage(getResponse.ID, attr); err != nil {
463+
return err
464+
}
465+
return nil
466+
}
467+
437468
// SetupWithManager sets up the controller with the Manager.
438469
func (r *OSArtifactReconciler) SetupWithManager(mgr ctrl.Manager) error {
439470
return ctrl.NewControllerManagedBy(mgr).

go.mod

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module github.com/kairos-io/osbuilder
33
go 1.23.4
44

55
require (
6+
github.com/Yamashou/gqlgenc v0.23.2
7+
github.com/pkg/errors v0.9.1
8+
github.com/pluralsh/console/go/client v1.28.3
69
k8s.io/api v0.32.1
710
k8s.io/apimachinery v0.32.1
811
k8s.io/client-go v0.32.1
@@ -11,6 +14,7 @@ require (
1114
)
1215

1316
require (
17+
github.com/99designs/gqlgen v0.17.49 // indirect
1418
github.com/beorn7/perks v1.0.1 // indirect
1519
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1620
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -39,12 +43,13 @@ require (
3943
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4044
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
4145
github.com/onsi/gomega v1.36.2 // indirect
42-
github.com/pkg/errors v0.9.1 // indirect
4346
github.com/prometheus/client_golang v1.19.1 // indirect
4447
github.com/prometheus/client_model v0.6.1 // indirect
4548
github.com/prometheus/common v0.55.0 // indirect
4649
github.com/prometheus/procfs v0.15.1 // indirect
50+
github.com/sosodev/duration v1.3.1 // indirect
4751
github.com/spf13/pflag v1.0.5 // indirect
52+
github.com/vektah/gqlparser/v2 v2.5.16 // indirect
4853
github.com/x448/float16 v0.8.4 // indirect
4954
go.uber.org/multierr v1.11.0 // indirect
5055
go.uber.org/zap v1.27.0 // indirect

go.sum

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ=
2+
github.com/99designs/gqlgen v0.17.49/go.mod h1:tC8YFVZMed81x7UJ7ORUwXF4Kn6SXuucFqQBhN8+BU0=
3+
github.com/Yamashou/gqlgenc v0.23.2 h1:WPxYPrwc6W4Z1eY4qKxoH3nb5PC4jAMWqQA0G8toQMI=
4+
github.com/Yamashou/gqlgenc v0.23.2/go.mod h1:oMc4EQBQeDwLIODvgcvpaSp6rO+KMf47FuOhplv5D3A=
5+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
6+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
17
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
28
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
39
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -77,6 +83,8 @@ github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
7783
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
7884
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7985
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
86+
github.com/pluralsh/console/go/client v1.28.3 h1:KyHpOoVHhMRMAZp99k7LqZqX6+FrOwy9sGVXaDSi9FA=
87+
github.com/pluralsh/console/go/client v1.28.3/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
8088
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8189
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
8290
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -90,6 +98,10 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
9098
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
9199
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
92100
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
101+
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
102+
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
103+
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
104+
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
93105
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
94106
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
95107
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -101,6 +113,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
101113
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
102114
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
103115
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
116+
github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8=
117+
github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
104118
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
105119
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
106120
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

main.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"flag"
2121
"os"
2222

23+
consoleclient "github.com/kairos-io/osbuilder/pkg/client"
24+
"github.com/kairos-io/osbuilder/pkg/helpers"
2325
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2426

2527
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -43,6 +45,8 @@ var (
4345
setupLog = ctrl.Log.WithName("setup")
4446
)
4547

48+
const EnvConsoleToken = "CONSOLE_TOKEN"
49+
4650
func init() {
4751
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4852

@@ -55,6 +59,10 @@ func main() {
5559
var enableLeaderElection bool
5660
var probeAddr string
5761
var serveImage, toolImage, copierImage, pvcStorage string
62+
var consoleUrl, consoleToken string
63+
64+
flag.StringVar(&consoleUrl, "console-url", "", "The URL of the console api to fetch services from.")
65+
flag.StringVar(&consoleToken, "console-token", helpers.GetEnv(EnvConsoleToken, ""), "The deploy token to auth to Console API with.")
5866

5967
flag.StringVar(&pvcStorage, "pvc-storage-size", "20Gi", "The PVC storage size for building process")
6068

@@ -75,6 +83,8 @@ func main() {
7583

7684
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
7785

86+
extConsoleClient := consoleclient.New(consoleUrl, consoleToken)
87+
7888
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7989
Scheme: scheme,
8090
Metrics: metricsserver.Options{BindAddress: metricsAddr},
@@ -99,12 +109,13 @@ func main() {
99109
}
100110

101111
if err = (&controllers.OSArtifactReconciler{
102-
Client: mgr.GetClient(),
103-
Scheme: mgr.GetScheme(),
104-
ServingImage: serveImage,
105-
ToolImage: toolImage,
106-
CopierImage: copierImage,
107-
PVCStorage: pvcStorage,
112+
Client: mgr.GetClient(),
113+
Scheme: mgr.GetScheme(),
114+
ServingImage: serveImage,
115+
ToolImage: toolImage,
116+
CopierImage: copierImage,
117+
PVCStorage: pvcStorage,
118+
ConsoleClient: extConsoleClient,
108119
}).SetupWithManager(mgr); err != nil {
109120
setupLog.Error(err, "unable to create controller", "controller", "OSArtifact")
110121
os.Exit(1)

0 commit comments

Comments
 (0)