diff --git a/api/v1alpha1/osartifact_types.go b/api/v1alpha1/osartifact_types.go index e15fdb0..298224a 100644 --- a/api/v1alpha1/osartifact_types.go +++ b/api/v1alpha1/osartifact_types.go @@ -31,10 +31,16 @@ type OSArtifactSpec struct { // Foo is an example field of OSArtifact. Edit osartifact_types.go to remove/update ImageName string `json:"imageName,omitempty"` // This needs to be revisited - ISO bool `json:"iso,omitempty"` - CloudImage bool `json:"cloudImage,omitempty"` - AzureImage bool `json:"azureImage,omitempty"` - GCEImage bool `json:"gceImage,omitempty"` + ISO bool `json:"iso,omitempty"` + + //Disk-only stuff + DiskSize string `json:"diskSize,omitempty"` + CloudImage bool `json:"cloudImage,omitempty"` + AzureImage bool `json:"azureImage,omitempty"` + GCEImage bool `json:"gceImage,omitempty"` + + Netboot bool `json:"netboot,omitempty"` + NetbootURL string `json:"netboot_url",omitempty` // TODO: treat cloudconfig as a secret, and take a secretRef where to store it (optionally) CloudConfig string `json:"cloudConfig,omitempty"` diff --git a/controllers/deployment.go b/controllers/deployment.go index 08d8a74..d5dbc7b 100644 --- a/controllers/deployment.go +++ b/controllers/deployment.go @@ -104,7 +104,8 @@ func osReleaseContainer(containerImage string) v1.Container { } } -func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact) *appsv1.Deployment { +func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact, svc *v1.Service) *appsv1.Deployment { + // TODO: svc is unused, but could be used in the future to generate the Netboot URL objMeta := metav1.ObjectMeta{ Name: artifact.Name, Namespace: artifact.Namespace, @@ -179,13 +180,41 @@ func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact) SecurityContext: &v1.SecurityContext{Privileged: &privileged}, Name: "build-cloud-image", Image: r.ToolImage, - Command: []string{"/bin/bash", "-cxe"}, + + Command: []string{"/bin/bash", "-cxe"}, Args: []string{ cloudImgCmd, }, VolumeMounts: volumeMounts, } + if artifact.Spec.DiskSize != "" { + buildCloudImageContainer.Env = []v1.EnvVar{{ + Name: "EXTEND", + Value: artifact.Spec.DiskSize, + }} + } + + extractNetboot := v1.Container{ + ImagePullPolicy: v1.PullAlways, + SecurityContext: &v1.SecurityContext{Privileged: &privileged}, + Name: "build-netboot", + Image: r.ToolImage, + Command: []string{"/bin/bash", "-cxe"}, + Env: []v1.EnvVar{{ + Name: "URL", + Value: artifact.Spec.NetbootURL, + }}, + Args: []string{ + fmt.Sprintf( + "/netboot.sh /public/%s.iso /public/%s", + artifact.Name, + artifact.Name, + ), + }, + VolumeMounts: volumeMounts, + } + buildAzureCloudImageContainer := v1.Container{ ImagePullPolicy: v1.PullAlways, SecurityContext: &v1.SecurityContext{Privileged: &privileged}, @@ -263,10 +292,14 @@ func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact) } - if artifact.Spec.ISO { + if artifact.Spec.ISO || artifact.Spec.Netboot { pod.InitContainers = append(pod.InitContainers, buildIsoContainer) } + if artifact.Spec.Netboot { + pod.InitContainers = append(pod.InitContainers, extractNetboot) + } + if artifact.Spec.CloudImage || artifact.Spec.AzureImage || artifact.Spec.GCEImage { pod.InitContainers = append(pod.InitContainers, buildCloudImageContainer) } diff --git a/controllers/osartifact_controller.go b/controllers/osartifact_controller.go index 6060961..b10a7d7 100644 --- a/controllers/osartifact_controller.go +++ b/controllers/osartifact_controller.go @@ -118,7 +118,7 @@ func (r *OSArtifactReconciler) Reconcile(ctx context.Context, req ctrl.Request) } logger.Info(fmt.Sprintf("Checking deployment %v", osbuild)) - desiredDeployment := r.genDeployment(osbuild) + desiredDeployment := r.genDeployment(osbuild, svc) deployment, err := r.clientSet.AppsV1().Deployments(req.Namespace).Get(ctx, desiredDeployment.Name, v1.GetOptions{}) if deployment == nil || apierrors.IsNotFound(err) { logger.Info(fmt.Sprintf("Creating Deployment %v", deployment)) diff --git a/go.sum b/go.sum index 4bf6301..4a58aaa 100644 --- a/go.sum +++ b/go.sum @@ -189,6 +189,7 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gobuffalo/flect v0.2.4 h1:BSYA8+T60cdyq+vynaSUjqSVI9mDEg9ZfQUXKmfjo4I= github.com/gobuffalo/flect v0.2.4/go.mod h1:1ZyCLIbg0YD7sDkzvFdPoOydPtD8y9JQnrOROolUcM8= @@ -277,6 +278,7 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= @@ -826,6 +828,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717 h1:hI3jKY4Hpf63ns040onEbB3dAkR/H/P83hw1TG8dD3Y= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/tools-image/netboot.sh b/tools-image/netboot.sh index 4ef8163..a31767e 100755 --- a/tools-image/netboot.sh +++ b/tools-image/netboot.sh @@ -3,20 +3,20 @@ ISO=$1 OUTPUT_NAME=$2 -VERSION=$3 +ARTIFACT_NAME=$(basename $OUTPUT_NAME) isoinfo -x /rootfs.squashfs -R -i $ISO > $OUTPUT_NAME.squashfs isoinfo -x /boot/kernel -R -i $ISO > $OUTPUT_NAME-kernel isoinfo -x /boot/initrd -R -i $ISO > $OUTPUT_NAME-initrd -RELEASE_URL=${RELEASE_URL:-https://github.com/kairos-io/kairos/releases/download} +URL=${URL:-https://github.com/kairos-io/kairos/releases/download} cat > $OUTPUT_NAME.ipxe << EOF #!ipxe -set url ${RELEASE_URL}/ -set kernel $OUTPUT_NAME-kernel -set initrd $OUTPUT_NAME-initrd -set rootfs $OUTPUT_NAME.squashfs +set url ${URL}/ +set kernel $ARTIFACT_NAME-kernel +set initrd $ARTIFACT_NAME-initrd +set rootfs $ARTIFACT_NAME.squashfs # set config https://example.com/machine-config # set cmdline extra.values=1 kernel \${url}/\${kernel} initrd=\${initrd} ip=dhcp rd.cos.disable root=live:\${url}/\${rootfs} netboot nodepair.enable config_url=\${config} console=tty1 console=ttyS0 \${cmdline} diff --git a/tools-image/raw-images.sh b/tools-image/raw-images.sh index e5cc776..2da0ea9 100755 --- a/tools-image/raw-images.sh +++ b/tools-image/raw-images.sh @@ -9,6 +9,7 @@ : "${OEM_LABEL:=COS_OEM}" : "${RECOVERY_LABEL:=COS_RECOVERY}" +: "${EXTEND:=}" DIRECTORY=$1 OUT=${2:-disk.raw} @@ -66,6 +67,11 @@ truncate -s $((3*1024*1024)) $OUT # Add an extra MB at the end of the disk for the gpt headers, in fact 34 sectors would be enough, but adding some more does not hurt. truncate -s "+$((1024*1024))" $OUT +if [ -n "$EXTEND" ]; then + echo "Extending image of $EXTEND MB" + truncate -s "+$(($EXTEND*1024*1024))" $OUT +fi + # Create the partition table in $OUT (assumes sectors of 512 bytes) sgdisk -n 1:2048:+2M -c 1:legacy -t 1:EF02 $OUT sgdisk -n 2:0:+20M -c 2:UEFI -t 2:EF00 $OUT