mirror of
https://github.com/kairos-io/osbuilder.git
synced 2025-08-01 15:47:31 +00:00
Add option to build netboot files and disk image size
This commit is contained in:
parent
ebbd1c9a1a
commit
7ae1f7105a
@ -31,10 +31,16 @@ type OSArtifactSpec struct {
|
|||||||
// Foo is an example field of OSArtifact. Edit osartifact_types.go to remove/update
|
// Foo is an example field of OSArtifact. Edit osartifact_types.go to remove/update
|
||||||
ImageName string `json:"imageName,omitempty"`
|
ImageName string `json:"imageName,omitempty"`
|
||||||
// This needs to be revisited
|
// This needs to be revisited
|
||||||
ISO bool `json:"iso,omitempty"`
|
ISO bool `json:"iso,omitempty"`
|
||||||
CloudImage bool `json:"cloudImage,omitempty"`
|
|
||||||
AzureImage bool `json:"azureImage,omitempty"`
|
//Disk-only stuff
|
||||||
GCEImage bool `json:"gceImage,omitempty"`
|
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)
|
// TODO: treat cloudconfig as a secret, and take a secretRef where to store it (optionally)
|
||||||
CloudConfig string `json:"cloudConfig,omitempty"`
|
CloudConfig string `json:"cloudConfig,omitempty"`
|
||||||
|
@ -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{
|
objMeta := metav1.ObjectMeta{
|
||||||
Name: artifact.Name,
|
Name: artifact.Name,
|
||||||
Namespace: artifact.Namespace,
|
Namespace: artifact.Namespace,
|
||||||
@ -179,13 +180,41 @@ func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact)
|
|||||||
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
||||||
Name: "build-cloud-image",
|
Name: "build-cloud-image",
|
||||||
Image: r.ToolImage,
|
Image: r.ToolImage,
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
|
||||||
|
Command: []string{"/bin/bash", "-cxe"},
|
||||||
Args: []string{
|
Args: []string{
|
||||||
cloudImgCmd,
|
cloudImgCmd,
|
||||||
},
|
},
|
||||||
VolumeMounts: volumeMounts,
|
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{
|
buildAzureCloudImageContainer := v1.Container{
|
||||||
ImagePullPolicy: v1.PullAlways,
|
ImagePullPolicy: v1.PullAlways,
|
||||||
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
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)
|
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 {
|
if artifact.Spec.CloudImage || artifact.Spec.AzureImage || artifact.Spec.GCEImage {
|
||||||
pod.InitContainers = append(pod.InitContainers, buildCloudImageContainer)
|
pod.InitContainers = append(pod.InitContainers, buildCloudImageContainer)
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func (r *OSArtifactReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||||||
}
|
}
|
||||||
logger.Info(fmt.Sprintf("Checking deployment %v", osbuild))
|
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{})
|
deployment, err := r.clientSet.AppsV1().Deployments(req.Namespace).Get(ctx, desiredDeployment.Name, v1.GetOptions{})
|
||||||
if deployment == nil || apierrors.IsNotFound(err) {
|
if deployment == nil || apierrors.IsNotFound(err) {
|
||||||
logger.Info(fmt.Sprintf("Creating Deployment %v", deployment))
|
logger.Info(fmt.Sprintf("Creating Deployment %v", deployment))
|
||||||
|
3
go.sum
3
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 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
||||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
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-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/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 h1:BSYA8+T60cdyq+vynaSUjqSVI9mDEg9ZfQUXKmfjo4I=
|
||||||
github.com/gobuffalo/flect v0.2.4/go.mod h1:1ZyCLIbg0YD7sDkzvFdPoOydPtD8y9JQnrOROolUcM8=
|
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-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-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-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/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
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.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/tools v0.1.4/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.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/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-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
ISO=$1
|
ISO=$1
|
||||||
OUTPUT_NAME=$2
|
OUTPUT_NAME=$2
|
||||||
VERSION=$3
|
ARTIFACT_NAME=$(basename $OUTPUT_NAME)
|
||||||
|
|
||||||
isoinfo -x /rootfs.squashfs -R -i $ISO > $OUTPUT_NAME.squashfs
|
isoinfo -x /rootfs.squashfs -R -i $ISO > $OUTPUT_NAME.squashfs
|
||||||
isoinfo -x /boot/kernel -R -i $ISO > $OUTPUT_NAME-kernel
|
isoinfo -x /boot/kernel -R -i $ISO > $OUTPUT_NAME-kernel
|
||||||
isoinfo -x /boot/initrd -R -i $ISO > $OUTPUT_NAME-initrd
|
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
|
cat > $OUTPUT_NAME.ipxe << EOF
|
||||||
#!ipxe
|
#!ipxe
|
||||||
set url ${RELEASE_URL}/
|
set url ${URL}/
|
||||||
set kernel $OUTPUT_NAME-kernel
|
set kernel $ARTIFACT_NAME-kernel
|
||||||
set initrd $OUTPUT_NAME-initrd
|
set initrd $ARTIFACT_NAME-initrd
|
||||||
set rootfs $OUTPUT_NAME.squashfs
|
set rootfs $ARTIFACT_NAME.squashfs
|
||||||
# set config https://example.com/machine-config
|
# set config https://example.com/machine-config
|
||||||
# set cmdline extra.values=1
|
# 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}
|
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}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
: "${OEM_LABEL:=COS_OEM}"
|
: "${OEM_LABEL:=COS_OEM}"
|
||||||
: "${RECOVERY_LABEL:=COS_RECOVERY}"
|
: "${RECOVERY_LABEL:=COS_RECOVERY}"
|
||||||
|
: "${EXTEND:=}"
|
||||||
|
|
||||||
DIRECTORY=$1
|
DIRECTORY=$1
|
||||||
OUT=${2:-disk.raw}
|
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.
|
# 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
|
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)
|
# 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 1:2048:+2M -c 1:legacy -t 1:EF02 $OUT
|
||||||
sgdisk -n 2:0:+20M -c 2:UEFI -t 2:EF00 $OUT
|
sgdisk -n 2:0:+20M -c 2:UEFI -t 2:EF00 $OUT
|
||||||
|
Loading…
Reference in New Issue
Block a user