mirror of
https://github.com/kairos-io/osbuilder.git
synced 2026-01-04 23:14:22 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cb37cd1c9 |
2
.github/workflows/image.yml
vendored
2
.github/workflows/image.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
DOCKER_IMAGE=quay.io/kairos/osbuilder
|
DOCKER_IMAGE=quay.io/c3os/osbuilder
|
||||||
VERSION=latest
|
VERSION=latest
|
||||||
SHORTREF=${GITHUB_SHA::8}
|
SHORTREF=${GITHUB_SHA::8}
|
||||||
# If this is git tag, use the tag name as a docker tag
|
# If this is git tag, use the tag name as a docker tag
|
||||||
|
|||||||
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
name: 'test'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Test
|
|
||||||
run: |
|
|
||||||
make kind-e2e-tests
|
|
||||||
63
.github/workflows/tool-image.yml
vendored
63
.github/workflows/tool-image.yml
vendored
@@ -1,63 +0,0 @@
|
|||||||
---
|
|
||||||
name: 'build tools container images'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
id: prep
|
|
||||||
run: |
|
|
||||||
DOCKER_IMAGE=quay.io/kairos/osbuilder-tools
|
|
||||||
VERSION=latest
|
|
||||||
SHORTREF=${GITHUB_SHA::8}
|
|
||||||
# If this is git tag, use the tag name as a docker tag
|
|
||||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
||||||
VERSION=${GITHUB_REF#refs/tags/}
|
|
||||||
fi
|
|
||||||
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}"
|
|
||||||
# If the VERSION looks like a version number, assume that
|
|
||||||
# this is the most recent version of the image and also
|
|
||||||
# tag it 'latest'.
|
|
||||||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
|
||||||
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
|
|
||||||
fi
|
|
||||||
# Set output parameters.
|
|
||||||
echo ::set-output name=tags::${TAGS}
|
|
||||||
echo ::set-output name=docker_image::${DOCKER_IMAGE}
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@master
|
|
||||||
with:
|
|
||||||
platforms: all
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@master
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
registry: quay.io
|
|
||||||
username: ${{ secrets.QUAY_USERNAME }}
|
|
||||||
password: ${{ secrets.QUAY_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
builder: ${{ steps.buildx.outputs.name }}
|
|
||||||
context: ./tools-image
|
|
||||||
file: ./tools-image/Dockerfile
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.prep.outputs.tags }}
|
|
||||||
25
Makefile
25
Makefile
@@ -4,8 +4,8 @@
|
|||||||
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
|
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
|
||||||
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
|
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
|
||||||
VERSION ?= 0.0.1
|
VERSION ?= 0.0.1
|
||||||
IMG ?= quay.io/kairos/osbuilder:test
|
IMG ?= quay.io/c3os/osbuilder:test
|
||||||
CLUSTER_NAME?="kairos-osbuilder-e2e"
|
CLUSTER_NAME?="c3os-osbuilder-e2e"
|
||||||
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
# CHANNELS define the bundle channels used in the bundle.
|
# CHANNELS define the bundle channels used in the bundle.
|
||||||
@@ -31,8 +31,8 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
|
|||||||
# This variable is used to construct full image tags for bundle and catalog images.
|
# This variable is used to construct full image tags for bundle and catalog images.
|
||||||
#
|
#
|
||||||
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
|
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
|
||||||
# kairos.io/osbuilder-bundle:$VERSION and kairos.io/osbuilder-catalog:$VERSION.
|
# c3os-x.io/osbuilder-operator-bundle:$VERSION and c3os-x.io/osbuilder-operator-catalog:$VERSION.
|
||||||
IMAGE_TAG_BASE ?= kairos.io/osbuilder
|
IMAGE_TAG_BASE ?= c3os-x.io/osbuilder-operator
|
||||||
|
|
||||||
# BUNDLE_IMG defines the image:tag used for the bundle.
|
# BUNDLE_IMG defines the image:tag used for the bundle.
|
||||||
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
|
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
|
||||||
@@ -172,7 +172,6 @@ $(LOCALBIN):
|
|||||||
|
|
||||||
## Tool Binaries
|
## Tool Binaries
|
||||||
KUSTOMIZE ?= $(LOCALBIN)/kustomize
|
KUSTOMIZE ?= $(LOCALBIN)/kustomize
|
||||||
GINKGO ?= $(LOCALBIN)/ginkgo
|
|
||||||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
|
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
|
||||||
ENVTEST ?= $(LOCALBIN)/setup-envtest
|
ENVTEST ?= $(LOCALBIN)/setup-envtest
|
||||||
|
|
||||||
@@ -191,10 +190,6 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
|
|||||||
$(CONTROLLER_GEN): $(LOCALBIN)
|
$(CONTROLLER_GEN): $(LOCALBIN)
|
||||||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
|
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
|
||||||
|
|
||||||
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
|
|
||||||
$(GINKGO): $(LOCALBIN)
|
|
||||||
GOBIN=$(LOCALBIN) go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
|
|
||||||
|
|
||||||
.PHONY: envtest
|
.PHONY: envtest
|
||||||
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
|
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
|
||||||
$(ENVTEST): $(LOCALBIN)
|
$(ENVTEST): $(LOCALBIN)
|
||||||
@@ -271,15 +266,9 @@ test_deps:
|
|||||||
|
|
||||||
.PHONY: unit-tests
|
.PHONY: unit-tests
|
||||||
unit-tests: test_deps
|
unit-tests: test_deps
|
||||||
$(GINKGO) -r -v --covermode=atomic --coverprofile=coverage.out -p -r ./pkg/...
|
ginkgo -r -v --covermode=atomic --coverprofile=coverage.out -p -r ./pkg/...
|
||||||
|
|
||||||
e2e-tests:
|
e2e-tests:
|
||||||
GINKGO=$(GINKGO) KUBE_VERSION=${KUBE_VERSION} $(ROOT_DIR)/script/test.sh
|
KUBE_VERSION=${KUBE_VERSION} $(ROOT_DIR)/script/test.sh
|
||||||
|
|
||||||
kind-e2e-tests: ginkgo kind-setup install undeploy-dev deploy-dev e2e-tests
|
kind-e2e-tests: kind-setup install undeploy-dev deploy-dev e2e-tests
|
||||||
|
|
||||||
|
|
||||||
kubesplit: manifests kustomize
|
|
||||||
rm -rf helm-chart
|
|
||||||
mkdir helm-chart
|
|
||||||
$(KUSTOMIZE) build config/default | kubesplit -helm helm-chart
|
|
||||||
8
PROJECT
8
PROJECT
@@ -1,19 +1,19 @@
|
|||||||
domain: kairos.io
|
domain: c3os-x.io
|
||||||
layout:
|
layout:
|
||||||
- go.kubebuilder.io/v3
|
- go.kubebuilder.io/v3
|
||||||
plugins:
|
plugins:
|
||||||
manifests.sdk.operatorframework.io/v2: {}
|
manifests.sdk.operatorframework.io/v2: {}
|
||||||
scorecard.sdk.operatorframework.io/v2: {}
|
scorecard.sdk.operatorframework.io/v2: {}
|
||||||
projectName: osartifactbuilder-operator
|
projectName: osartifactbuilder-operator
|
||||||
repo: github.com/kairos-io/osbuilder
|
repo: github.com/c3os-io/osbuilder-operator
|
||||||
resources:
|
resources:
|
||||||
- api:
|
- api:
|
||||||
crdVersion: v1
|
crdVersion: v1
|
||||||
namespaced: true
|
namespaced: true
|
||||||
controller: true
|
controller: true
|
||||||
domain: kairos.io
|
domain: c3os-x.io
|
||||||
group: build
|
group: build
|
||||||
kind: OSArtifact
|
kind: OSArtifact
|
||||||
path: github.com/kairos-io/osbuilder/api/v1alpha1
|
path: github.com/c3os-io/osbuilder-operator/api/v1alpha1
|
||||||
version: v1alpha1
|
version: v1alpha1
|
||||||
version: "3"
|
version: "3"
|
||||||
|
|||||||
110
README.md
110
README.md
@@ -1,30 +1,94 @@
|
|||||||
# osbuilder
|
# osartifactbuilder-operator
|
||||||
|
// TODO(user): Add simple overview of use/purpose
|
||||||
|
|
||||||
| :exclamation: | This is experimental! |
|
## Description
|
||||||
|-|:-|
|
// TODO(user): An in-depth paragraph about your project and overview of use
|
||||||
|
|
||||||
This is the Kairos osbuilder Kubernetes Native Extension.
|
## Getting Started
|
||||||
|
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
|
||||||
|
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
|
||||||
|
|
||||||
To install, use helm:
|
### Running on the cluster
|
||||||
|
1. Install Instances of Custom Resources:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
kubectl apply -f config/samples/
|
||||||
```
|
```
|
||||||
# Adds the kairos repo to helm
|
|
||||||
$ helm repo add kairos https://kairos-io.github.io/helm-charts
|
|
||||||
"kairos" has been added to your repositories
|
|
||||||
$ helm repo update
|
|
||||||
Hang tight while we grab the latest from your chart repositories...
|
|
||||||
...Successfully got an update from the "kairos" chart repository
|
|
||||||
Update Complete. ⎈Happy Helming!⎈
|
|
||||||
|
|
||||||
# Install the CRD chart
|
2. Build and push your image to the location specified by `IMG`:
|
||||||
$ helm install kairos-crd kairos/kairos-crds
|
|
||||||
NAME: kairos-crd
|
```sh
|
||||||
LAST DEPLOYED: Tue Sep 6 20:35:34 2022
|
make docker-build docker-push IMG=<some-registry>/osartifactbuilder-operator:tag
|
||||||
NAMESPACE: default
|
|
||||||
STATUS: deployed
|
|
||||||
REVISION: 1
|
|
||||||
TEST SUITE: None
|
|
||||||
|
|
||||||
# Installs osbuilder
|
|
||||||
$ helm install kairos-osbuilder kairos/osbuilder
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
3. Deploy the controller to the cluster with the image specified by `IMG`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make deploy IMG=<some-registry>/osartifactbuilder-operator:tag
|
||||||
|
```
|
||||||
|
|
||||||
|
### Uninstall CRDs
|
||||||
|
To delete the CRDs from the cluster:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make uninstall
|
||||||
|
```
|
||||||
|
|
||||||
|
### Undeploy controller
|
||||||
|
UnDeploy the controller to the cluster:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make undeploy
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
// TODO(user): Add detailed information on how you would like others to contribute to this project
|
||||||
|
|
||||||
|
### How it works
|
||||||
|
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
|
||||||
|
|
||||||
|
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
|
||||||
|
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
|
||||||
|
|
||||||
|
### Test It Out
|
||||||
|
1. Install the CRDs into the cluster:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make run
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE:** You can also run this in one step by running: `make install run`
|
||||||
|
|
||||||
|
### Modifying the API definitions
|
||||||
|
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make manifests
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE:** Run `make --help` for more information on all potential `make` targets
|
||||||
|
|
||||||
|
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Copyright 2022.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Package v1alpha1 contains API Schema definitions for the build v1alpha1 API group
|
// Package v1alpha1 contains API Schema definitions for the build v1alpha1 API group
|
||||||
// +kubebuilder:object:generate=true
|
//+kubebuilder:object:generate=true
|
||||||
// +groupName=build.kairos.io
|
//+groupName=build.c3os-x.io
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// GroupVersion is group version used to register these objects
|
// GroupVersion is group version used to register these objects
|
||||||
GroupVersion = schema.GroupVersion{Group: "build.kairos.io", Version: "v1alpha1"}
|
GroupVersion = schema.GroupVersion{Group: "build.c3os-x.io", Version: "v1alpha1"}
|
||||||
|
|
||||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
||||||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
||||||
|
|||||||
@@ -30,26 +30,14 @@ 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
|
ISO bool `json:"iso,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:"netbootURL,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"`
|
||||||
GRUBConfig string `json:"grubConfig,omitempty"`
|
GRUBConfig string `json:"grubConfig,omitempty"`
|
||||||
|
|
||||||
Bundles []string `json:"bundles,omitempty"`
|
Bundles []string `json:"bundles,omitempty"`
|
||||||
PullOptions Pull `json:"pull,omitempty"`
|
PullOptions *Pull `json:"pull,omitempty"`
|
||||||
OSRelease string `json:"osRelease,omitempty"`
|
PushOptions *Push `json:"push,omitempty"`
|
||||||
PushOptions Push `json:"push,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Push struct {
|
type Push struct {
|
||||||
|
|||||||
@@ -25,27 +25,12 @@ import (
|
|||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *LocalObjectReference) DeepCopyInto(out *LocalObjectReference) {
|
|
||||||
*out = *in
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LocalObjectReference.
|
|
||||||
func (in *LocalObjectReference) DeepCopy() *LocalObjectReference {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(LocalObjectReference)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *OSArtifact) DeepCopyInto(out *OSArtifact) {
|
func (in *OSArtifact) DeepCopyInto(out *OSArtifact) {
|
||||||
*out = *in
|
*out = *in
|
||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
in.Spec.DeepCopyInto(&out.Spec)
|
out.Spec = in.Spec
|
||||||
out.Status = in.Status
|
out.Status = in.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,13 +87,6 @@ func (in *OSArtifactList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *OSArtifactSpec) DeepCopyInto(out *OSArtifactSpec) {
|
func (in *OSArtifactSpec) DeepCopyInto(out *OSArtifactSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
if in.Bundles != nil {
|
|
||||||
in, out := &in.Bundles, &out.Bundles
|
|
||||||
*out = make([]string, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
in.PullOptions.DeepCopyInto(&out.PullOptions)
|
|
||||||
in.PushOptions.DeepCopyInto(&out.PushOptions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OSArtifactSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OSArtifactSpec.
|
||||||
@@ -135,59 +113,3 @@ func (in *OSArtifactStatus) DeepCopy() *OSArtifactStatus {
|
|||||||
in.DeepCopyInto(out)
|
in.DeepCopyInto(out)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *Pull) DeepCopyInto(out *Pull) {
|
|
||||||
*out = *in
|
|
||||||
if in.ContainerRegistryCredentials != nil {
|
|
||||||
in, out := &in.ContainerRegistryCredentials, &out.ContainerRegistryCredentials
|
|
||||||
*out = new(SecretKeySelector)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pull.
|
|
||||||
func (in *Pull) DeepCopy() *Pull {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(Pull)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *Push) DeepCopyInto(out *Push) {
|
|
||||||
*out = *in
|
|
||||||
if in.ContainerRegistryCredentials != nil {
|
|
||||||
in, out := &in.ContainerRegistryCredentials, &out.ContainerRegistryCredentials
|
|
||||||
*out = new(SecretKeySelector)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Push.
|
|
||||||
func (in *Push) DeepCopy() *Push {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(Push)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *SecretKeySelector) DeepCopyInto(out *SecretKeySelector) {
|
|
||||||
*out = *in
|
|
||||||
out.LocalObjectReference = in.LocalObjectReference
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretKeySelector.
|
|
||||||
func (in *SecretKeySelector) DeepCopy() *SecretKeySelector {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(SecretKeySelector)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ metadata:
|
|||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.9.0
|
controller-gen.kubebuilder.io/version: v0.9.0
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: osartifacts.build.kairos.io
|
name: osartifacts.build.c3os-x.io
|
||||||
spec:
|
spec:
|
||||||
group: build.kairos.io
|
group: build.c3os-x.io
|
||||||
names:
|
names:
|
||||||
kind: OSArtifact
|
kind: OSArtifact
|
||||||
listKind: OSArtifactList
|
listKind: OSArtifactList
|
||||||
@@ -35,23 +35,10 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
description: OSArtifactSpec defines the desired state of OSArtifact
|
description: OSArtifactSpec defines the desired state of OSArtifact
|
||||||
properties:
|
properties:
|
||||||
azureImage:
|
|
||||||
type: boolean
|
|
||||||
bundles:
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
type: array
|
|
||||||
cloudConfig:
|
cloudConfig:
|
||||||
description: 'TODO: treat cloudconfig as a secret, and take a secretRef
|
description: 'TODO: treat cloudconfig as a secret, and take a secretRef
|
||||||
where to store it (optionally)'
|
where to store it (optionally)'
|
||||||
type: string
|
type: string
|
||||||
cloudImage:
|
|
||||||
type: boolean
|
|
||||||
diskSize:
|
|
||||||
description: Disk-only stuff
|
|
||||||
type: string
|
|
||||||
gceImage:
|
|
||||||
type: boolean
|
|
||||||
grubConfig:
|
grubConfig:
|
||||||
type: string
|
type: string
|
||||||
imageName:
|
imageName:
|
||||||
@@ -59,46 +46,9 @@ spec:
|
|||||||
to remove/update
|
to remove/update
|
||||||
type: string
|
type: string
|
||||||
iso:
|
iso:
|
||||||
description: This needs to be revisited
|
|
||||||
type: boolean
|
type: boolean
|
||||||
netboot:
|
pullFromKube:
|
||||||
type: boolean
|
type: boolean
|
||||||
netbootURL:
|
|
||||||
type: string
|
|
||||||
osRelease:
|
|
||||||
type: string
|
|
||||||
pull:
|
|
||||||
properties:
|
|
||||||
containerRegistryCredentials:
|
|
||||||
properties:
|
|
||||||
key:
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
namespace:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- name
|
|
||||||
type: object
|
|
||||||
type: object
|
|
||||||
push:
|
|
||||||
properties:
|
|
||||||
containerRegistryCredentials:
|
|
||||||
properties:
|
|
||||||
key:
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
namespace:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- name
|
|
||||||
type: object
|
|
||||||
imageName:
|
|
||||||
type: string
|
|
||||||
push:
|
|
||||||
type: boolean
|
|
||||||
type: object
|
|
||||||
type: object
|
type: object
|
||||||
status:
|
status:
|
||||||
description: OSArtifactStatus defines the observed state of OSArtifact
|
description: OSArtifactStatus defines the observed state of OSArtifact
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
# since it depends on service name and namespace that are out of this kustomize package.
|
# since it depends on service name and namespace that are out of this kustomize package.
|
||||||
# It should be run by config/default
|
# It should be run by config/default
|
||||||
resources:
|
resources:
|
||||||
- bases/build.kairos.io_osartifacts.yaml
|
- bases/build.c3os-x.io_osartifacts.yaml
|
||||||
#+kubebuilder:scaffold:crdkustomizeresource
|
#+kubebuilder:scaffold:crdkustomizeresource
|
||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ kind: CustomResourceDefinition
|
|||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
|
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
|
||||||
name: osartifacts.build.kairos.io
|
name: osartifacts.build.c3os-x.io
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
apiVersion: apiextensions.k8s.io/v1
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
name: osartifacts.build.kairos.io
|
name: osartifacts.build.c3os-x.io
|
||||||
spec:
|
spec:
|
||||||
conversion:
|
conversion:
|
||||||
strategy: Webhook
|
strategy: Webhook
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ webhook:
|
|||||||
port: 9443
|
port: 9443
|
||||||
leaderElection:
|
leaderElection:
|
||||||
leaderElect: true
|
leaderElect: true
|
||||||
resourceName: 98ca89ca.kairos.io
|
resourceName: 98ca89ca.c3os-x.io
|
||||||
# leaderElectionReleaseOnCancel defines if the leader should step down volume
|
# leaderElectionReleaseOnCancel defines if the leader should step down volume
|
||||||
# when the Manager ends. This requires the binary to immediately end when the
|
# when the Manager ends. This requires the binary to immediately end when the
|
||||||
# Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
|
# Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
|
|||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
images:
|
images:
|
||||||
- name: controller
|
- name: controller
|
||||||
newName: quay.io/kairos/osbuilder
|
newName: quay.io/c3os/osbuilder
|
||||||
newTag: test
|
newTag: test
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ metadata:
|
|||||||
name: osartifact-editor-role
|
name: osartifact-editor-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts
|
- osartifacts
|
||||||
verbs:
|
verbs:
|
||||||
@@ -17,7 +17,7 @@ rules:
|
|||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/status
|
- osartifacts/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ metadata:
|
|||||||
name: osartifact-viewer-role
|
name: osartifact-viewer-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts
|
- osartifacts
|
||||||
verbs:
|
verbs:
|
||||||
@@ -13,7 +13,7 @@ rules:
|
|||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/status
|
- osartifacts/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ metadata:
|
|||||||
name: manager-role
|
name: manager-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts
|
- osartifacts
|
||||||
verbs:
|
verbs:
|
||||||
@@ -18,13 +18,13 @@ rules:
|
|||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/finalizers
|
- osartifacts/finalizers
|
||||||
verbs:
|
verbs:
|
||||||
- update
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/status
|
- osartifacts/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ metadata:
|
|||||||
name: manager-role
|
name: manager-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts
|
- osartifacts
|
||||||
verbs:
|
verbs:
|
||||||
@@ -18,13 +18,13 @@ rules:
|
|||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/finalizers
|
- osartifacts/finalizers
|
||||||
verbs:
|
verbs:
|
||||||
- update
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/status
|
- osartifacts/status
|
||||||
verbs:
|
verbs:
|
||||||
@@ -32,7 +32,7 @@ rules:
|
|||||||
- patch
|
- patch
|
||||||
- update
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- build.kairos.io
|
- build.c3os-x.io
|
||||||
resources:
|
resources:
|
||||||
- osartifacts/finalizers
|
- osartifacts/finalizers
|
||||||
verbs:
|
verbs:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
apiVersion: build.kairos.io/v1alpha1
|
apiVersion: build.c3os-x.io/v1alpha1
|
||||||
kind: OSArtifact
|
kind: OSArtifact
|
||||||
metadata:
|
metadata:
|
||||||
name: osartifact-sample
|
name: osartifact-sample
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -32,8 +32,7 @@ func (r *OSArtifactReconciler) genConfigMap(artifact buildv1alpha1.OSArtifact) *
|
|||||||
OwnerReferences: genOwner(artifact),
|
OwnerReferences: genOwner(artifact),
|
||||||
},
|
},
|
||||||
Data: map[string]string{
|
Data: map[string]string{
|
||||||
"config": artifact.Spec.CloudConfig,
|
"config": artifact.Spec.CloudConfig,
|
||||||
"grub.cfg": artifact.Spec.GRUBConfig,
|
"grub.cfg": artifact.Spec.GRUBConfig,
|
||||||
"os-release": artifact.Spec.OSRelease,
|
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
@@ -34,10 +34,10 @@ func genDeploymentLabel(s string) map[string]string {
|
|||||||
|
|
||||||
// TODO: Handle registry auth
|
// TODO: Handle registry auth
|
||||||
// TODO: This shells out, but needs ENV_VAR with key refs mapping
|
// TODO: This shells out, but needs ENV_VAR with key refs mapping
|
||||||
func unpackContainer(id, containerImage, pullImage string, pullOptions buildv1alpha1.Pull) v1.Container {
|
func unpackContainer(containerImage, pullImage string, pullOptions buildv1alpha1.Pull) v1.Container {
|
||||||
return v1.Container{
|
return v1.Container{
|
||||||
ImagePullPolicy: v1.PullAlways,
|
ImagePullPolicy: v1.PullAlways,
|
||||||
Name: fmt.Sprintf("pull-image-%s", id),
|
Name: "pull-image",
|
||||||
Image: containerImage,
|
Image: containerImage,
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
Command: []string{"/bin/bash", "-cxe"},
|
||||||
Args: []string{
|
Args: []string{
|
||||||
@@ -81,170 +81,70 @@ func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func osReleaseContainer(containerImage string) v1.Container {
|
func pushImageContainer(containerImage string, pushOptions buildv1alpha1.Push) v1.Container {
|
||||||
return v1.Container{
|
return v1.Container{
|
||||||
ImagePullPolicy: v1.PullAlways,
|
ImagePullPolicy: v1.PullAlways,
|
||||||
Name: "os-release",
|
Name: "push-image",
|
||||||
Image: containerImage,
|
Image: containerImage,
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
Command: []string{"/bin/bash", "-cxe"},
|
||||||
Args: []string{
|
Args: []string{
|
||||||
"cp -rfv /etc/os-release /rootfs/etc/os-release",
|
fmt.Sprintf(
|
||||||
|
"skopeo /public/image.tar %s",
|
||||||
|
pushOptions.ImageName,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
VolumeMounts: []v1.VolumeMount{
|
VolumeMounts: []v1.VolumeMount{
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "config",
|
Name: "public",
|
||||||
MountPath: "/etc/os-release",
|
MountPath: "/public",
|
||||||
SubPath: "os-release",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "rootfs",
|
|
||||||
MountPath: "/rootfs",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact, svc *v1.Service) *appsv1.Deployment {
|
func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact) *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,
|
||||||
OwnerReferences: genOwner(artifact),
|
OwnerReferences: genOwner(artifact),
|
||||||
}
|
}
|
||||||
|
|
||||||
pushImage := artifact.Spec.PushOptions.Push
|
|
||||||
|
|
||||||
privileged := false
|
privileged := false
|
||||||
serviceAccount := false
|
serviceAccount := false
|
||||||
|
|
||||||
cmd := fmt.Sprintf(
|
|
||||||
"/entrypoint.sh --debug --name %s build-iso --date=false --output /public dir:/rootfs",
|
|
||||||
artifact.Name,
|
|
||||||
)
|
|
||||||
|
|
||||||
volumeMounts := []v1.VolumeMount{
|
|
||||||
{
|
|
||||||
Name: "public",
|
|
||||||
MountPath: "/public",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "rootfs",
|
|
||||||
MountPath: "/rootfs",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if artifact.Spec.GRUBConfig != "" {
|
|
||||||
volumeMounts = append(volumeMounts, v1.VolumeMount{
|
|
||||||
Name: "config",
|
|
||||||
MountPath: "/iso/iso-overlay/boot/grub2/grub.cfg",
|
|
||||||
SubPath: "grub.cfg",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
cloudImgCmd := fmt.Sprintf(
|
|
||||||
"/raw-images.sh /rootfs /public/%s.raw",
|
|
||||||
artifact.Name,
|
|
||||||
)
|
|
||||||
|
|
||||||
if artifact.Spec.CloudConfig != "" {
|
|
||||||
volumeMounts = append(volumeMounts, v1.VolumeMount{
|
|
||||||
Name: "config",
|
|
||||||
MountPath: "/iso/iso-overlay/cloud_config.yaml",
|
|
||||||
SubPath: "config",
|
|
||||||
})
|
|
||||||
|
|
||||||
cloudImgCmd += " /iso/iso-overlay/cloud_config.yaml"
|
|
||||||
}
|
|
||||||
|
|
||||||
if artifact.Spec.CloudConfig != "" || artifact.Spec.GRUBConfig != "" {
|
|
||||||
cmd = fmt.Sprintf(
|
|
||||||
"/entrypoint.sh --debug --name %s build-iso --date=false --overlay-iso /iso/iso-overlay --output /public dir:/rootfs",
|
|
||||||
artifact.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
buildIsoContainer := v1.Container{
|
buildIsoContainer := v1.Container{
|
||||||
ImagePullPolicy: v1.PullAlways,
|
ImagePullPolicy: v1.PullAlways,
|
||||||
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
||||||
Name: "build-iso",
|
Name: "build-iso",
|
||||||
Image: r.ToolImage,
|
Image: r.BuildImage,
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
|
||||||
Args: []string{
|
|
||||||
cmd,
|
|
||||||
},
|
|
||||||
VolumeMounts: volumeMounts,
|
|
||||||
}
|
|
||||||
|
|
||||||
buildCloudImageContainer := v1.Container{
|
|
||||||
ImagePullPolicy: v1.PullAlways,
|
|
||||||
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
|
||||||
Name: "build-cloud-image",
|
|
||||||
Image: r.ToolImage,
|
|
||||||
|
|
||||||
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},
|
|
||||||
Name: "build-azure-cloud-image",
|
|
||||||
Image: r.ToolImage,
|
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
Command: []string{"/bin/bash", "-cxe"},
|
||||||
Args: []string{
|
Args: []string{
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"/azure.sh /public/%s.raw /public/%s.vhd",
|
"elemental --debug --name %s build-iso --date=false --overlay-iso /iso/iso-overlay --output /public dir:/rootfs",
|
||||||
artifact.Name,
|
|
||||||
artifact.Name,
|
artifact.Name,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
VolumeMounts: volumeMounts,
|
VolumeMounts: []v1.VolumeMount{
|
||||||
}
|
{
|
||||||
|
Name: "public",
|
||||||
buildGCECloudImageContainer := v1.Container{
|
MountPath: "/public",
|
||||||
ImagePullPolicy: v1.PullAlways,
|
},
|
||||||
SecurityContext: &v1.SecurityContext{Privileged: &privileged},
|
{
|
||||||
Name: "build-gce-cloud-image",
|
Name: "config",
|
||||||
Image: r.ToolImage,
|
MountPath: "/iso/iso-overlay/cloud_config.yaml",
|
||||||
Command: []string{"/bin/bash", "-cxe"},
|
SubPath: "config",
|
||||||
Args: []string{
|
},
|
||||||
fmt.Sprintf(
|
{
|
||||||
"/gce.sh /public/%s.raw /public/%s.gce.raw",
|
Name: "grub",
|
||||||
artifact.Name,
|
MountPath: "/iso/iso-overlay/boot/grub2/grub.cfg",
|
||||||
artifact.Name,
|
SubPath: "grub.cfg",
|
||||||
),
|
},
|
||||||
|
{
|
||||||
|
Name: "rootfs",
|
||||||
|
MountPath: "/rootfs",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
VolumeMounts: volumeMounts,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
servingContainer := v1.Container{
|
servingContainer := v1.Container{
|
||||||
@@ -281,40 +181,13 @@ func (r *OSArtifactReconciler) genDeployment(artifact buildv1alpha1.OSArtifact,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.InitContainers = []v1.Container{unpackContainer("baseimage", r.ToolImage, artifact.Spec.ImageName, artifact.Spec.PullOptions)}
|
pod.InitContainers = []v1.Container{buildIsoContainer, unpackContainer(r.ToolImage, artifact.Spec.ImageName, *artifact.Spec.PullOptions)}
|
||||||
|
|
||||||
for i, bundle := range artifact.Spec.Bundles {
|
for _, bundle := range artifact.Spec.Bundles {
|
||||||
pod.InitContainers = append(pod.InitContainers, unpackContainer(fmt.Sprint(i), r.ToolImage, bundle, artifact.Spec.PullOptions))
|
pod.InitContainers = append(pod.InitContainers, unpackContainer(r.ToolImage, bundle, *artifact.Spec.PullOptions))
|
||||||
}
|
}
|
||||||
|
|
||||||
if artifact.Spec.OSRelease != "" {
|
pod.InitContainers = append(pod.InitContainers, buildIsoContainer)
|
||||||
pod.InitContainers = append(pod.InitContainers, osReleaseContainer(r.ToolImage))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if artifact.Spec.AzureImage {
|
|
||||||
pod.InitContainers = append(pod.InitContainers, buildAzureCloudImageContainer)
|
|
||||||
}
|
|
||||||
|
|
||||||
if artifact.Spec.GCEImage {
|
|
||||||
pod.InitContainers = append(pod.InitContainers, buildGCECloudImageContainer)
|
|
||||||
}
|
|
||||||
|
|
||||||
if pushImage {
|
|
||||||
pod.InitContainers = append(pod.InitContainers, createImageContainer(r.ToolImage, artifact.Spec.PushOptions))
|
|
||||||
}
|
|
||||||
|
|
||||||
pod.Containers = []v1.Container{servingContainer}
|
pod.Containers = []v1.Container{servingContainer}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -38,9 +38,9 @@ import (
|
|||||||
// OSArtifactReconciler reconciles a OSArtifact object
|
// OSArtifactReconciler reconciles a OSArtifact object
|
||||||
type OSArtifactReconciler struct {
|
type OSArtifactReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
clientSet *kubernetes.Clientset
|
clientSet *kubernetes.Clientset
|
||||||
ServingImage, ToolImage string
|
ServingImage, BuildImage, ToolImage string
|
||||||
}
|
}
|
||||||
|
|
||||||
func genOwner(artifact buildv1alpha1.OSArtifact) []metav1.OwnerReference {
|
func genOwner(artifact buildv1alpha1.OSArtifact) []metav1.OwnerReference {
|
||||||
@@ -53,9 +53,9 @@ func genOwner(artifact buildv1alpha1.OSArtifact) []metav1.OwnerReference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+kubebuilder:rbac:groups=build.kairos.io,resources=osartifacts,verbs=get;list;watch;create;update;patch;delete
|
//+kubebuilder:rbac:groups=build.c3os-x.io,resources=osartifacts,verbs=get;list;watch;create;update;patch;delete
|
||||||
//+kubebuilder:rbac:groups=build.kairos.io,resources=osartifacts/status,verbs=get;update;patch
|
//+kubebuilder:rbac:groups=build.c3os-x.io,resources=osartifacts/status,verbs=get;update;patch
|
||||||
//+kubebuilder:rbac:groups=build.kairos.io,resources=osartifacts/finalizers,verbs=update
|
//+kubebuilder:rbac:groups=build.c3os-x.io,resources=osartifacts/finalizers,verbs=update
|
||||||
|
|
||||||
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
||||||
// move the current state of the cluster closer to the desired state.
|
// move the current state of the cluster closer to the desired state.
|
||||||
@@ -110,7 +110,6 @@ func (r *OSArtifactReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||||||
logger.Error(err, "Failed while creating svc")
|
logger.Error(err, "Failed while creating svc")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctrl.Result{Requeue: true}, err
|
return ctrl.Result{Requeue: true}, err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +117,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, svc)
|
desiredDeployment := r.genDeployment(osbuild)
|
||||||
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))
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ limitations under the License.
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func genService(artifact buildv1alpha1.OSArtifact) *v1.Service {
|
func genService(artifact buildv1alpha1.OSArtifact) *v1.Service {
|
||||||
@@ -31,8 +32,7 @@ func genService(artifact buildv1alpha1.OSArtifact) *v1.Service {
|
|||||||
return &v1.Service{
|
return &v1.Service{
|
||||||
ObjectMeta: objMeta,
|
ObjectMeta: objMeta,
|
||||||
Spec: v1.ServiceSpec{
|
Spec: v1.ServiceSpec{
|
||||||
Type: v1.ServiceTypeNodePort,
|
Ports: []v1.ServicePort{{Name: "http", Port: int32(80), TargetPort: intstr.FromInt(80)}},
|
||||||
Ports: []v1.ServicePort{{Name: "http", Port: int32(80)}},
|
|
||||||
Selector: genDeploymentLabel(artifact.Name),
|
Selector: genDeploymentLabel(artifact.Name),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
//+kubebuilder:scaffold:imports
|
//+kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/kairos-io/osbuilder
|
module github.com/c3os-io/osbuilder-operator
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
|||||||
3
go.sum
3
go.sum
@@ -189,7 +189,6 @@ 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=
|
||||||
@@ -278,7 +277,6 @@ 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=
|
||||||
@@ -828,7 +826,6 @@ 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=
|
||||||
|
|||||||
13
main.go
13
main.go
@@ -31,8 +31,8 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
buildv1alpha1 "github.com/c3os-io/osbuilder-operator/api/v1alpha1"
|
||||||
"github.com/kairos-io/osbuilder/controllers"
|
"github.com/c3os-io/osbuilder-operator/controllers"
|
||||||
//+kubebuilder:scaffold:imports
|
//+kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,11 +52,11 @@ func main() {
|
|||||||
var metricsAddr string
|
var metricsAddr string
|
||||||
var enableLeaderElection bool
|
var enableLeaderElection bool
|
||||||
var probeAddr string
|
var probeAddr string
|
||||||
var serveImage, toolImage string
|
var buildImage, serveImage, toolImage string
|
||||||
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
|
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
|
||||||
|
flag.StringVar(&buildImage, "build-image", "quay.io/costoolkit/elemental-cli:v0.0.15-ae4f000", "Build image.")
|
||||||
flag.StringVar(&serveImage, "serve-image", "nginx", "Serve image.")
|
flag.StringVar(&serveImage, "serve-image", "nginx", "Serve image.")
|
||||||
// It needs luet inside
|
flag.StringVar(&toolImage, "tool-image", "quay.io/costoolkit/elemental-cli:v0.0.15-ae4f000", "Tool image.")
|
||||||
flag.StringVar(&toolImage, "tool-image", "quay.io/kairos/osbuilder-tools:latest", "Tool image.")
|
|
||||||
|
|
||||||
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
|
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
|
||||||
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
|
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
|
||||||
@@ -76,7 +76,7 @@ func main() {
|
|||||||
Port: 9443,
|
Port: 9443,
|
||||||
HealthProbeBindAddress: probeAddr,
|
HealthProbeBindAddress: probeAddr,
|
||||||
LeaderElection: enableLeaderElection,
|
LeaderElection: enableLeaderElection,
|
||||||
LeaderElectionID: "98ca89ca.kairos.io",
|
LeaderElectionID: "98ca89ca.c3os-x.io",
|
||||||
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
|
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
|
||||||
// when the Manager ends. This requires the binary to immediately end when the
|
// when the Manager ends. This requires the binary to immediately end when the
|
||||||
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
|
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
|
||||||
@@ -98,6 +98,7 @@ func main() {
|
|||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
ServingImage: serveImage,
|
ServingImage: serveImage,
|
||||||
ToolImage: toolImage,
|
ToolImage: toolImage,
|
||||||
|
BuildImage: buildImage,
|
||||||
Scheme: mgr.GetScheme(),
|
Scheme: mgr.GetScheme(),
|
||||||
}).SetupWithManager(mgr); err != nil {
|
}).SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create controller", "controller", "OSArtifact")
|
setupLog.Error(err, "unable to create controller", "controller", "OSArtifact")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
KUBE_VERSION=${KUBE_VERSION:-v1.22.7}
|
KUBE_VERSION=${KUBE_VERSION:-v1.22.7}
|
||||||
CLUSTER_NAME="${CLUSTER_NAME:-kairos-osbuilder-e2e}"
|
CLUSTER_NAME="${CLUSTER_NAME:-c3os-osbuilder-e2e}"
|
||||||
|
|
||||||
if ! kind get clusters | grep "$CLUSTER_NAME"; then
|
if ! kind get clusters | grep "$CLUSTER_NAME"; then
|
||||||
cat << EOF > kind.config
|
cat << EOF > kind.config
|
||||||
@@ -29,4 +29,4 @@ kubectl wait --for=condition=Ready node/$CLUSTER_NAME-control-plane
|
|||||||
export EXTERNAL_IP=$(kubectl get nodes -o jsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}')
|
export EXTERNAL_IP=$(kubectl get nodes -o jsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}')
|
||||||
export BRIDGE_IP="172.18.0.1"
|
export BRIDGE_IP="172.18.0.1"
|
||||||
kubectl get nodes -o wide
|
kubectl get nodes -o wide
|
||||||
cd $ROOT_DIR/tests && $GINKGO -r -v ./e2e
|
cd $ROOT_DIR/tests && ginkgo -r -v ./e2e
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package e2e_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = Describe("ISO build test", func() {
|
|
||||||
//k := kubectl.New()
|
|
||||||
Context("registration", func() {
|
|
||||||
|
|
||||||
AfterEach(func() {
|
|
||||||
kubectl.New().Delete("osartifacts", "-n", "default", "hello-kairos")
|
|
||||||
})
|
|
||||||
|
|
||||||
It("creates a simple iso", func() {
|
|
||||||
err := kubectl.Apply("", "../../tests/fixtures/simple.yaml")
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
|
|
||||||
Eventually(func() string {
|
|
||||||
b, _ := kubectl.GetData("default", "osartifacts", "hello-kairos", "jsonpath={.spec.imageName}")
|
|
||||||
return string(b)
|
|
||||||
}, 2*time.Minute, 2*time.Second).Should(Equal("quay.io/kairos/core-opensuse:latest"))
|
|
||||||
|
|
||||||
Eventually(func() string {
|
|
||||||
b, _ := kubectl.GetData("default", "deployments", "hello-kairos", "jsonpath={.spec.template.metadata.labels.osbuild}")
|
|
||||||
return string(b)
|
|
||||||
}, 2*time.Minute, 2*time.Second).Should(Equal("workloadhello-kairos"))
|
|
||||||
Eventually(func() string {
|
|
||||||
b, _ := kubectl.GetData("default", "deployments", "hello-kairos", "jsonpath={.spec.status.unavailableReplicas}")
|
|
||||||
return string(b)
|
|
||||||
}, 15*time.Minute, 2*time.Second).ShouldNot(Equal("1"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,13 +1,39 @@
|
|||||||
package e2e_test
|
package e2e_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestE2e(t *testing.T) {
|
var _ = Describe("ISO build test", func() {
|
||||||
RegisterFailHandler(Fail)
|
//k := kubectl.New()
|
||||||
RunSpecs(t, "kairos-operator e2e test Suite")
|
Context("registration", func() {
|
||||||
}
|
|
||||||
|
AfterEach(func() {
|
||||||
|
kubectl.New().Delete("osartifacts", "-n", "default", "hello-c3os")
|
||||||
|
})
|
||||||
|
|
||||||
|
It("creates a simple iso", func() {
|
||||||
|
err := kubectl.Apply("", "../../tests/fixtures/simple.yaml")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Eventually(func() string {
|
||||||
|
b, _ := kubectl.GetData("default", "osartifacts", "hello-c3os", "jsonpath={.spec.imageName}")
|
||||||
|
return string(b)
|
||||||
|
}, 2*time.Minute, 2*time.Second).Should(Equal("quay.io/c3os/c3os:opensuse-latest"))
|
||||||
|
|
||||||
|
Eventually(func() string {
|
||||||
|
b, _ := kubectl.GetData("default", "deployments", "hello-c3os", "jsonpath={.spec.template.metadata.labels.osbuild}")
|
||||||
|
return string(b)
|
||||||
|
}, 2*time.Minute, 2*time.Second).Should(Equal("workloadhello-c3os"))
|
||||||
|
Eventually(func() string {
|
||||||
|
b, _ := kubectl.GetData("default", "deployments", "hello-c3os", "jsonpath={.spec.status.unavailableReplicas}")
|
||||||
|
return string(b)
|
||||||
|
}, 15*time.Minute, 2*time.Second).ShouldNot(Equal("1"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|||||||
13
tests/e2e/e2e_test.go
Normal file
13
tests/e2e/e2e_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package e2e_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestE2e(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "c3os-operator e2e test Suite")
|
||||||
|
}
|
||||||
53
tests/fixtures/simple.yaml
vendored
53
tests/fixtures/simple.yaml
vendored
@@ -1,52 +1,7 @@
|
|||||||
apiVersion: build.kairos.io/v1alpha1
|
apiVersion: build.c3os-x.io/v1alpha1
|
||||||
kind: OSArtifact
|
kind: OSArtifact
|
||||||
metadata:
|
metadata:
|
||||||
name: hello-kairos
|
name: hello-c3os
|
||||||
spec:
|
spec:
|
||||||
imageName: "quay.io/kairos/core-opensuse:latest"
|
imageName: "quay.io/c3os/c3os:opensuse-latest"
|
||||||
iso: true
|
iso: true
|
||||||
bundles:
|
|
||||||
- quay.io/kairos/packages:goreleaser-utils-1.11.1
|
|
||||||
grubConfig: |
|
|
||||||
search --file --set=root /boot/kernel.xz
|
|
||||||
set default=0
|
|
||||||
set timeout=10
|
|
||||||
set timeout_style=menu
|
|
||||||
set linux=linux
|
|
||||||
set initrd=initrd
|
|
||||||
if [ "${grub_cpu}" = "x86_64" -o "${grub_cpu}" = "i386" -o "${grub_cpu}" = "arm64" ];then
|
|
||||||
if [ "${grub_platform}" = "efi" ]; then
|
|
||||||
if [ "${grub_cpu}" != "arm64" ]; then
|
|
||||||
set linux=linuxefi
|
|
||||||
set initrd=initrdefi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ "${grub_platform}" = "efi" ]; then
|
|
||||||
echo "Please press 't' to show the boot menu on this console"
|
|
||||||
fi
|
|
||||||
set font=($root)/boot/${grub_cpu}/loader/grub2/fonts/unicode.pf2
|
|
||||||
if [ -f ${font} ];then
|
|
||||||
loadfont ${font}
|
|
||||||
fi
|
|
||||||
menuentry "install" --class os --unrestricted {
|
|
||||||
echo Loading kernel...
|
|
||||||
$linux ($root)/boot/kernel.xz cdroot root=live:CDLABEL=COS_LIVE rd.live.dir=/ rd.live.squashimg=rootfs.squashfs console=tty1 console=ttyS0 rd.cos.disable vga=795 nomodeset nodepair.enable
|
|
||||||
echo Loading initrd...
|
|
||||||
$initrd ($root)/boot/rootfs.xz
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "${grub_platform}" = "efi" ]; then
|
|
||||||
hiddenentry "Text mode" --hotkey "t" {
|
|
||||||
set textmode=true
|
|
||||||
terminal_output console
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
cloudConfig: |
|
|
||||||
#node-config
|
|
||||||
install:
|
|
||||||
device: "/dev/sda"
|
|
||||||
reboot: true
|
|
||||||
poweroff: true
|
|
||||||
auto: true # Required, for automated installations
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
ARG ELEMENTAL_CLI_VERSION=0.20221107.1
|
|
||||||
ARG LEAP_VERSION=15.4
|
|
||||||
ARG LUET_VERSION=0.33.0
|
|
||||||
FROM quay.io/kairos/packages:elemental-cli-system-$ELEMENTAL_CLI_VERSION AS elemental
|
|
||||||
FROM quay.io/luet/base:$LUET_VERSION AS luet
|
|
||||||
|
|
||||||
### TODO: Replace those naked Dockerfiles copies with luet install so we can keep track of all versioning with 1 repository tag
|
|
||||||
### 1) Add the kairos repository with a reference
|
|
||||||
### 2) populate folders accordingly
|
|
||||||
|
|
||||||
## amd64 Live CD artifacts
|
|
||||||
FROM quay.io/kairos/packages:grub2-livecd-0.0.4 AS grub2
|
|
||||||
FROM quay.io/kairos/packages:grub2-efi-image-livecd-0.0.4 AS efi
|
|
||||||
|
|
||||||
## RPI64
|
|
||||||
|
|
||||||
## Firmware is in the amd64 repo (noarch)
|
|
||||||
FROM quay.io/kairos/packages:u-boot-rpi64-firmware-2021.01-5.1 AS rpi-u-boot
|
|
||||||
FROM quay.io/kairos/packages:raspberrypi-firmware-firmware-2021.03.10-2.1 AS rpi-firmware
|
|
||||||
FROM quay.io/kairos/packages:raspberrypi-firmware-config-firmware-2021.03.10-2.1 AS rpi-firmware-config
|
|
||||||
FROM quay.io/kairos/packages:raspberrypi-firmware-dt-firmware-2021.03.15-2.1 AS rpi-firmware-dt
|
|
||||||
|
|
||||||
## PineBook64 Pro
|
|
||||||
FROM quay.io/kairos/packages:u-boot-rockchip-arm-vendor-blob-0.1 AS pinebook-u-boot
|
|
||||||
|
|
||||||
## Generic ARM artifacts
|
|
||||||
FROM quay.io/kairos/packages-arm64:grub-efi-static-0.1 AS grub-efi
|
|
||||||
FROM quay.io/kairos/packages-arm64:grub-config-static-0.1 AS grub-config
|
|
||||||
FROM quay.io/kairos/packages-arm64:grub-artifacts-static-0.1 AS grub-artifacts
|
|
||||||
|
|
||||||
## RAW images
|
|
||||||
FROM quay.io/kairos/packages:grub-efi-static-0.1 AS grub-raw-efi
|
|
||||||
FROM quay.io/kairos/packages:grub-config-static-0.1 AS grub-raw-config
|
|
||||||
FROM quay.io/kairos/packages:grub-artifacts-static-0.1 AS grub-raw-artifacts
|
|
||||||
|
|
||||||
FROM opensuse/leap:$LEAP_VERSION
|
|
||||||
COPY --from=elemental /usr/bin/elemental /usr/bin/elemental
|
|
||||||
COPY --from=luet /usr/bin/luet /usr/bin/luet
|
|
||||||
|
|
||||||
# x86_64 ISOs
|
|
||||||
COPY --from=grub2 / /grub2
|
|
||||||
COPY --from=efi / /efi
|
|
||||||
|
|
||||||
# RAW images
|
|
||||||
COPY --from=grub-raw-efi / /raw/grub
|
|
||||||
COPY --from=grub-raw-config / /raw/grubconfig
|
|
||||||
COPY --from=grub-raw-artifacts / /raw/grubartifacts
|
|
||||||
|
|
||||||
# RPI64
|
|
||||||
COPY --from=rpi-u-boot / /rpi/u-boot
|
|
||||||
COPY --from=rpi-firmware / /rpi/rpi-firmware
|
|
||||||
COPY --from=rpi-firmware-config / /rpi/rpi-firmware-config
|
|
||||||
COPY --from=rpi-firmware-dt / /rpi/rpi-firmware-dt
|
|
||||||
|
|
||||||
# Pinebook
|
|
||||||
COPY --from=pinebook-u-boot / /pinebookpro/u-boot
|
|
||||||
|
|
||||||
# Generic
|
|
||||||
COPY --from=grub-efi / /arm/grub/efi
|
|
||||||
COPY --from=grub-config / /arm/grub/config
|
|
||||||
COPY --from=grub-artifacts / /arm/grub/artifacts
|
|
||||||
|
|
||||||
RUN zypper ref && zypper dup -y
|
|
||||||
|
|
||||||
## ISO Build depedencies
|
|
||||||
RUN zypper ref && zypper in -y xfsprogs parted util-linux-systemd e2fsprogs curl util-linux udev rsync grub2 dosfstools grub2-x86_64-efi squashfs mtools xorriso lvm2
|
|
||||||
RUN mkdir /config
|
|
||||||
|
|
||||||
# Arm image build deps
|
|
||||||
RUN zypper in -y jq docker git curl gptfdisk kpartx sudo
|
|
||||||
# Netboot
|
|
||||||
RUN zypper in -y cdrtools
|
|
||||||
# cloud images
|
|
||||||
RUN zypper in -y bc qemu-tools
|
|
||||||
|
|
||||||
# ISO build config
|
|
||||||
COPY ./config.yaml /config/manifest.yaml
|
|
||||||
COPY ./entrypoint.sh /entrypoint.sh
|
|
||||||
COPY ./add-cloud-init.sh /add-cloud-init.sh
|
|
||||||
|
|
||||||
# ARM helpers
|
|
||||||
COPY ./build-arm-image.sh /build-arm-image.sh
|
|
||||||
COPY ./arm /arm
|
|
||||||
|
|
||||||
# RAW images helpers
|
|
||||||
COPY ./gce.sh /gce.sh
|
|
||||||
COPY ./raw-images.sh /raw-images.sh
|
|
||||||
COPY ./azure.sh /azure.sh
|
|
||||||
COPY ./netboot.sh /netboot.sh
|
|
||||||
|
|
||||||
COPY defaults.yaml /defaults.yaml
|
|
||||||
|
|
||||||
|
|
||||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# docker run --entrypoint /add-cloud-init.sh -v $PWD:/work -ti --rm test https://github.com/kairos-io/kairos/releases/download/v1.1.2/kairos-alpine-v1.1.2.iso /work/test.iso /work/config.yaml
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
ISO=$1
|
|
||||||
OUT=$2
|
|
||||||
CONFIG=$3
|
|
||||||
|
|
||||||
case ${ISO} in
|
|
||||||
http*)
|
|
||||||
curl -L "${ISO}" -o in.iso
|
|
||||||
ISO=in.iso
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Needs xorriso >=1.5.4
|
|
||||||
xorriso -indev $ISO -outdev $OUT -map $CONFIG /config.yaml -boot_image any replay
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
image=$1
|
|
||||||
|
|
||||||
if [ -z "$image" ]; then
|
|
||||||
echo "No image specified"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -e "$WORKDIR/luet.yaml" ]; then
|
|
||||||
ls -liah $WORKDIR
|
|
||||||
echo "No valid config file"
|
|
||||||
cat "$WORKDIR/luet.yaml"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo luet install --config $WORKDIR/luet.yaml -y --system-target $WORKDIR firmware/odroid-c2
|
|
||||||
# conv=notrunc ?
|
|
||||||
dd if=$WORKDIR/bl1.bin.hardkernel of=$image conv=fsync bs=1 count=442
|
|
||||||
dd if=$WORKDIR/bl1.bin.hardkernel of=$image conv=fsync bs=512 skip=1 seek=1
|
|
||||||
dd if=$WORKDIR/u-boot.odroidc2 of=$image conv=fsync bs=512 seek=97
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
image=$1
|
|
||||||
|
|
||||||
if [ -z "$image" ]; then
|
|
||||||
echo "No image specified"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
LOADER_OFFSET=${LOADER_OFFSET:-"64"}
|
|
||||||
LOADER_IMAGE=${LOADER_IMAGE:-"idbloader.img"}
|
|
||||||
UBOOT_IMAGE=${UBOOT_IMAGE:-"u-boot.itb"}
|
|
||||||
UBOOT_OFFSET=${UBOOT_OFFSET:-"16384"}
|
|
||||||
|
|
||||||
echo "Writing idbloader"
|
|
||||||
dd conv=notrunc if=/pinebookpro/u-boot/usr/lib/u-boot/pinebook-pro-rk3399/${LOADER_IMAGE} of="$image" conv=fsync seek=${LOADER_OFFSET}
|
|
||||||
echo "Writing u-boot image"
|
|
||||||
dd conv=notrunc if=/pinebookpro/u-boot/usr/lib/u-boot/pinebook-pro-rk3399/${UBOOT_IMAGE} of="$image" conv=fsync seek=${UBOOT_OFFSET}
|
|
||||||
sync $image
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
partprobe
|
|
||||||
|
|
||||||
kpartx -va $DRIVE
|
|
||||||
|
|
||||||
image=$1
|
|
||||||
|
|
||||||
if [ -z "$image" ]; then
|
|
||||||
echo "No image specified"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -ax
|
|
||||||
TEMPDIR="$(mktemp -d)"
|
|
||||||
echo $TEMPDIR
|
|
||||||
mount "${device}p1" "${TEMPDIR}"
|
|
||||||
|
|
||||||
for dir in /rpi/u-boot /rpi/rpi-firmware /rpi/rpi-firmware-config /rpi/rpi-firmware-dt
|
|
||||||
do
|
|
||||||
cp -rfv ${dir}/* $TEMPDIR
|
|
||||||
done
|
|
||||||
|
|
||||||
umount "${TEMPDIR}"
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Transform a raw image disk to azure vhd
|
|
||||||
RAWIMAGE="$1"
|
|
||||||
VHDDISK="${2:-disk.vhd}"
|
|
||||||
cp -rf $RAWIMAGE $VHDDISK.work
|
|
||||||
|
|
||||||
MB=$((1024*1024))
|
|
||||||
size=$(qemu-img info -f raw --output json "$RAWIMAGE" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
|
|
||||||
# shellcheck disable=SC2004
|
|
||||||
ROUNDED_SIZE=$(((($size+$MB-1)/$MB)*$MB))
|
|
||||||
echo "Resizing raw image to $ROUNDED_SIZE"
|
|
||||||
qemu-img resize -f raw "$VHDDISK.work" $ROUNDED_SIZE
|
|
||||||
echo "Converting $RAWIMAGE to $VHDDISK"
|
|
||||||
qemu-img convert -f raw -o subformat=fixed,force_size -O vpc "$VHDDISK.work" "$VHDDISK"
|
|
||||||
echo "Done"
|
|
||||||
rm -rf "$VHDDISK.work"
|
|
||||||
@@ -1,426 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
## This is a re-adaptation of https://github.com/rancher/elemental-toolkit/blob/main/images/arm-img-builder.sh
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
load_vars() {
|
|
||||||
|
|
||||||
model=${MODEL:-odroid_c2}
|
|
||||||
|
|
||||||
directory=${DIRECTORY:-}
|
|
||||||
output_image="${OUTPUT_IMAGE:-arm.img}"
|
|
||||||
# Img creation options. Size is in MB for all of the vars below
|
|
||||||
size="${SIZE:-7544}"
|
|
||||||
state_size="${STATE_SIZE:-4992}"
|
|
||||||
recovery_size="${RECOVERY_SIZE:-2192}"
|
|
||||||
default_active_size="${DEFAULT_ACTIVE_SIZE:-2400}"
|
|
||||||
|
|
||||||
## Repositories
|
|
||||||
final_repo="${FINAL_REPO:-quay.io/costoolkit/releases-teal-arm64}"
|
|
||||||
repo_type="${REPO_TYPE:-docker}"
|
|
||||||
|
|
||||||
# Warning: these default values must be aligned with the values provided
|
|
||||||
# in 'packages/cos-config/cos-config', provide an environment file using the
|
|
||||||
# --cos-config flag if different values are needed.
|
|
||||||
: "${OEM_LABEL:=COS_OEM}"
|
|
||||||
: "${RECOVERY_LABEL:=COS_RECOVERY}"
|
|
||||||
: "${ACTIVE_LABEL:=COS_ACTIVE}"
|
|
||||||
: "${PASSIVE_LABEL:=COS_PASSIVE}"
|
|
||||||
: "${PERSISTENT_LABEL:=COS_PERSISTENT}"
|
|
||||||
: "${SYSTEM_LABEL:=COS_SYSTEM}"
|
|
||||||
: "${STATE_LABEL:=COS_STATE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
sync
|
|
||||||
sync
|
|
||||||
sleep 5
|
|
||||||
sync
|
|
||||||
if [ -n "$EFI" ]; then
|
|
||||||
rm -rf $EFI
|
|
||||||
fi
|
|
||||||
if [ -n "$RECOVERY" ]; then
|
|
||||||
rm -rf $RECOVERY
|
|
||||||
fi
|
|
||||||
if [ -n "$STATEDIR" ]; then
|
|
||||||
rm -rf $STATEDIR
|
|
||||||
fi
|
|
||||||
if [ -n "$TARGET" ]; then
|
|
||||||
umount $TARGET || true
|
|
||||||
umount $LOOP || true
|
|
||||||
rm -rf $TARGET
|
|
||||||
fi
|
|
||||||
if [ -n "$WORKDIR" ]; then
|
|
||||||
rm -rf $WORKDIR
|
|
||||||
fi
|
|
||||||
if [ -n "$DRIVE" ]; then
|
|
||||||
umount $DRIVE || true
|
|
||||||
fi
|
|
||||||
if [ -n "$recovery" ]; then
|
|
||||||
umount $recovery || true
|
|
||||||
fi
|
|
||||||
if [ -n "$state" ]; then
|
|
||||||
umount $state || true
|
|
||||||
fi
|
|
||||||
if [ -n "$efi" ]; then
|
|
||||||
umount $efi || true
|
|
||||||
fi
|
|
||||||
if [ -n "$oem" ]; then
|
|
||||||
umount $oem || true
|
|
||||||
fi
|
|
||||||
losetup -D || true
|
|
||||||
}
|
|
||||||
|
|
||||||
ensure_dir_structure() {
|
|
||||||
local target=$1
|
|
||||||
for mnt in /sys /proc /dev /tmp /boot /usr/local /oem
|
|
||||||
do
|
|
||||||
if [ ! -d "${target}${mnt}" ]; then
|
|
||||||
mkdir -p ${target}${mnt}
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
usage()
|
|
||||||
{
|
|
||||||
echo "Usage: $0 [options] image.img"
|
|
||||||
echo ""
|
|
||||||
echo "Example: $0 --cos-config cos-config --model odroid-c2 --docker-image <image> output.img"
|
|
||||||
echo ""
|
|
||||||
echo "Flags:"
|
|
||||||
echo " --cos-config: (optional) Specifies a cos-config file for required environment variables"
|
|
||||||
echo " --config: (optional) Specify a cloud-init config file to embed into the final image"
|
|
||||||
echo " --manifest: (optional) Specify a manifest file to customize efi/grub packages installed into the image"
|
|
||||||
echo " --size: (optional) Image size (MB)"
|
|
||||||
echo " --state-partition-size: (optional) Size of the state partition (MB)"
|
|
||||||
echo " --recovery-partition-size: (optional) Size of the recovery partition (MB)"
|
|
||||||
echo " --images-size: (optional) Size of the active/passive/recovery images (MB)"
|
|
||||||
echo " --docker-image: (optional) A container image which will be used for active/passive/recovery system"
|
|
||||||
echo " --local: (optional) Use local repository when building"
|
|
||||||
echo " --directory: (optional) A directory which will be used for active/passive/recovery system"
|
|
||||||
echo " --model: (optional) The board model"
|
|
||||||
echo " --efi-dir: (optional) A directory with files which will be added to the efi partition"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
get_url()
|
|
||||||
{
|
|
||||||
FROM=$1
|
|
||||||
TO=$2
|
|
||||||
case $FROM in
|
|
||||||
ftp*|http*|tftp*)
|
|
||||||
n=0
|
|
||||||
attempts=5
|
|
||||||
until [ "$n" -ge "$attempts" ]
|
|
||||||
do
|
|
||||||
curl -o $TO -fL ${FROM} && break
|
|
||||||
n=$((n+1))
|
|
||||||
echo "Failed to download, retry attempt ${n} out of ${attempts}"
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
cp -f $FROM $TO
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
trap "cleanup" 1 2 3 6 9 14 15 EXIT
|
|
||||||
|
|
||||||
load_vars
|
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
|
||||||
case $1 in
|
|
||||||
--cos-config)
|
|
||||||
shift 1
|
|
||||||
cos_config=$1
|
|
||||||
;;
|
|
||||||
--config)
|
|
||||||
shift 1
|
|
||||||
config=$1
|
|
||||||
;;
|
|
||||||
--manifest)
|
|
||||||
shift 1
|
|
||||||
manifest=$1
|
|
||||||
;;
|
|
||||||
--size)
|
|
||||||
shift 1
|
|
||||||
size=$1
|
|
||||||
;;
|
|
||||||
--local)
|
|
||||||
local_build=true
|
|
||||||
;;
|
|
||||||
--state-partition-size)
|
|
||||||
shift 1
|
|
||||||
state_size=$1
|
|
||||||
;;
|
|
||||||
--recovery-partition-size)
|
|
||||||
shift 1
|
|
||||||
recovery_size=$1
|
|
||||||
;;
|
|
||||||
--images-size)
|
|
||||||
shift 1
|
|
||||||
default_active_size=$1
|
|
||||||
;;
|
|
||||||
--docker-image)
|
|
||||||
shift 1
|
|
||||||
CONTAINER_IMAGE=$1
|
|
||||||
;;
|
|
||||||
--directory)
|
|
||||||
shift 1
|
|
||||||
directory=$1
|
|
||||||
;;
|
|
||||||
--model)
|
|
||||||
shift 1
|
|
||||||
model=$1
|
|
||||||
;;
|
|
||||||
--efi-dir)
|
|
||||||
shift 1
|
|
||||||
efi_dir=$1
|
|
||||||
;;
|
|
||||||
--final-repo)
|
|
||||||
shift 1
|
|
||||||
final_repo=$1
|
|
||||||
;;
|
|
||||||
--repo-type)
|
|
||||||
shift 1
|
|
||||||
repo_type=$1
|
|
||||||
;;
|
|
||||||
-h)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
--help)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
if [ "$#" -gt 2 ]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
output_image=$1
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift 1
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$model" == "rpi64" ]; then
|
|
||||||
container_image=${CONTAINER_IMAGE:-quay.io/costoolkit/examples:rpi-latest}
|
|
||||||
else
|
|
||||||
# Odroid C2 image contains kernel-default-extra, might have broader support
|
|
||||||
container_image=${CONTAINER_IMAGE:-quay.io/costoolkit/examples:odroid-c2-latest}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$cos_config"] && [ -e "$cos_config" ]; then
|
|
||||||
source "$cos_config"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$output_image" ]; then
|
|
||||||
echo "No image file specified"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$manifest" ]; then
|
|
||||||
YQ_PACKAGES_COMMAND=(yq e -o=json "$manifest")
|
|
||||||
final_repo=${final_repo:-$(yq e ".raw_disk.$model.repo" "${manifest}")}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
|
||||||
echo "Image Size: $size MB."
|
|
||||||
echo "Recovery Partition: $recovery_size."
|
|
||||||
echo "State Partition: $state_size MB."
|
|
||||||
echo "Images size (active/passive/recovery.img): $default_active_size MB."
|
|
||||||
echo "Model: $model"
|
|
||||||
if [ -n "$container_image" ] && [ -z "$directory" ]; then
|
|
||||||
echo "Container image: $container_image"
|
|
||||||
fi
|
|
||||||
if [ -n "$directory" ]; then
|
|
||||||
echo "Root from directory: $directory"
|
|
||||||
fi
|
|
||||||
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
|
||||||
|
|
||||||
# Temp dir used during build
|
|
||||||
WORKDIR=$(mktemp -d --tmpdir arm-builder.XXXXXXXXXX)
|
|
||||||
#ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
||||||
TARGET=$(mktemp -d --tmpdir arm-builder.XXXXXXXXXX)
|
|
||||||
STATEDIR=$(mktemp -d --tmpdir arm-builder.XXXXXXXXXX)
|
|
||||||
|
|
||||||
|
|
||||||
export WORKDIR
|
|
||||||
|
|
||||||
# Prepare active.img
|
|
||||||
|
|
||||||
echo ">> Preparing active.img"
|
|
||||||
mkdir -p ${STATEDIR}/cOS
|
|
||||||
|
|
||||||
dd if=/dev/zero of=${STATEDIR}/cOS/active.img bs=1M count=$default_active_size
|
|
||||||
|
|
||||||
mkfs.ext2 ${STATEDIR}/cOS/active.img -L ${ACTIVE_LABEL}
|
|
||||||
|
|
||||||
sync
|
|
||||||
|
|
||||||
LOOP=$(losetup --show -f ${STATEDIR}/cOS/active.img)
|
|
||||||
if [ -z "$LOOP" ]; then
|
|
||||||
echo "No device"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mount -t ext2 $LOOP $TARGET
|
|
||||||
|
|
||||||
ensure_dir_structure $TARGET
|
|
||||||
|
|
||||||
# Download the container image
|
|
||||||
if [ -z "$directory" ]; then
|
|
||||||
echo ">>> Downloading container image"
|
|
||||||
elemental pull-image $( (( $local_build == 'true')) && printf %s '--local' ) $container_image $TARGET
|
|
||||||
else
|
|
||||||
echo ">>> Copying files from $directory"
|
|
||||||
rsync -axq --exclude='host' --exclude='mnt' --exclude='proc' --exclude='sys' --exclude='dev' --exclude='tmp' ${directory}/ $TARGET
|
|
||||||
fi
|
|
||||||
|
|
||||||
umount $TARGET
|
|
||||||
sync
|
|
||||||
|
|
||||||
if [ -n "$LOOP" ]; then
|
|
||||||
losetup -d $LOOP
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ">> Preparing passive.img"
|
|
||||||
cp -rfv ${STATEDIR}/cOS/active.img ${STATEDIR}/cOS/passive.img
|
|
||||||
tune2fs -L ${PASSIVE_LABEL} ${STATEDIR}/cOS/passive.img
|
|
||||||
|
|
||||||
# Preparing recovery
|
|
||||||
echo ">> Preparing recovery.img"
|
|
||||||
RECOVERY=$(mktemp -d --tmpdir arm-builder.XXXXXXXXXX)
|
|
||||||
if [ -z "$RECOVERY" ]; then
|
|
||||||
echo "No recovery directory"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p ${RECOVERY}/cOS
|
|
||||||
cp -rfv ${STATEDIR}/cOS/active.img ${RECOVERY}/cOS/recovery.img
|
|
||||||
|
|
||||||
tune2fs -L ${SYSTEM_LABEL} ${RECOVERY}/cOS/recovery.img
|
|
||||||
|
|
||||||
# Install real grub config to recovery
|
|
||||||
cp -rfv /arm/grub/config/* $RECOVERY
|
|
||||||
mkdir -p $RECOVERY/grub2
|
|
||||||
cp -rfv /arm/grub/artifacts/* $RECOVERY/grub2
|
|
||||||
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Prepare efi files
|
|
||||||
echo ">> Preparing EFI partition"
|
|
||||||
EFI=$(mktemp -d --tmpdir arm-builder.XXXXXXXXXX)
|
|
||||||
if [ -z "$EFI" ]; then
|
|
||||||
echo "No EFI directory"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp -rfv /arm/grub/efi/* $EFI
|
|
||||||
if [ -n "$EFI" ] && [ -n "$efi_dir" ]; then
|
|
||||||
echo "Copy $efi_dir to EFI directory"
|
|
||||||
cp -rfv $efi_dir/* $EFI
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ">> Writing image and partition table"
|
|
||||||
dd if=/dev/zero of="${output_image}" bs=1024000 count="${size}" || exit 1
|
|
||||||
if [ "$model" == "rpi64" ]; then
|
|
||||||
sgdisk -n 1:8192:+96M -c 1:EFI -t 1:0c00 ${output_image}
|
|
||||||
else
|
|
||||||
sgdisk -n 1:8192:+16M -c 1:EFI -t 1:0700 ${output_image}
|
|
||||||
fi
|
|
||||||
sgdisk -n 2:0:+${state_size}M -c 2:state -t 2:8300 ${output_image}
|
|
||||||
sgdisk -n 3:0:+${recovery_size}M -c 3:recovery -t 3:8300 ${output_image}
|
|
||||||
sgdisk -n 4:0:+64M -c 4:persistent -t 4:8300 ${output_image}
|
|
||||||
|
|
||||||
sgdisk -m 1:2:3:4 ${output_image}
|
|
||||||
|
|
||||||
if [ "$model" == "rpi64" ]; then
|
|
||||||
sfdisk --part-type ${output_image} 1 c
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prepare the image and copy over the files
|
|
||||||
|
|
||||||
export DRIVE=$(losetup -f "${output_image}" --show)
|
|
||||||
if [ -z "${DRIVE}" ]; then
|
|
||||||
echo "Cannot execute losetup for $output_image"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
device=${DRIVE/\/dev\//}
|
|
||||||
|
|
||||||
if [ -z "$device" ]; then
|
|
||||||
echo "No device"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
export device="/dev/mapper/${device}"
|
|
||||||
|
|
||||||
partprobe
|
|
||||||
|
|
||||||
kpartx -va $DRIVE
|
|
||||||
|
|
||||||
echo ">> Populating partitions"
|
|
||||||
efi=${device}p1
|
|
||||||
state=${device}p2
|
|
||||||
recovery=${device}p3
|
|
||||||
persistent=${device}p4
|
|
||||||
|
|
||||||
# Create partitions (RECOVERY, STATE, COS_PERSISTENT)
|
|
||||||
mkfs.vfat -F 32 ${efi}
|
|
||||||
fatlabel ${efi} COS_GRUB
|
|
||||||
|
|
||||||
mkfs.ext4 -F -L ${RECOVERY_LABEL} $recovery
|
|
||||||
mkfs.ext4 -F -L ${STATE_LABEL} $state
|
|
||||||
mkfs.ext4 -F -L ${PERSISTENT_LABEL} $persistent
|
|
||||||
|
|
||||||
mkdir $WORKDIR/state
|
|
||||||
mkdir $WORKDIR/recovery
|
|
||||||
mkdir $WORKDIR/efi
|
|
||||||
|
|
||||||
mount $recovery $WORKDIR/recovery
|
|
||||||
mount $state $WORKDIR/state
|
|
||||||
mount $efi $WORKDIR/efi
|
|
||||||
|
|
||||||
mkdir $WORKDIR/persistent
|
|
||||||
mount $persistent $WORKDIR/persistent
|
|
||||||
mkdir -p $WORKDIR/persistent/cloud-config
|
|
||||||
|
|
||||||
cp -rfv /defaults.yaml $WORKDIR/persistent/cloud-config/01_defaults.yaml
|
|
||||||
|
|
||||||
grub2-editenv $WORKDIR/state/grub_oem_env set "default_menu_entry=Kairos"
|
|
||||||
|
|
||||||
# Set a OEM config file if specified
|
|
||||||
if [ -n "$config" ]; then
|
|
||||||
echo ">> Copying $config OEM config file"
|
|
||||||
get_url $config $WORKDIR/persistent/cloud-config/99_custom.yaml
|
|
||||||
fi
|
|
||||||
umount $WORKDIR/persistent
|
|
||||||
|
|
||||||
# Copy over content
|
|
||||||
cp -arf $EFI/* $WORKDIR/efi
|
|
||||||
cp -arf $RECOVERY/* $WORKDIR/recovery
|
|
||||||
cp -arf $STATEDIR/* $WORKDIR/state
|
|
||||||
|
|
||||||
umount $WORKDIR/recovery
|
|
||||||
umount $WORKDIR/state
|
|
||||||
umount $WORKDIR/efi
|
|
||||||
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Flash uboot and vendor-specific bits
|
|
||||||
echo ">> Performing $model specific bits.."
|
|
||||||
/arm/boards/$model.sh ${DRIVE}
|
|
||||||
|
|
||||||
kpartx -dv $DRIVE
|
|
||||||
|
|
||||||
umount $DRIVE || true
|
|
||||||
|
|
||||||
echo ">> Done writing $output_image"
|
|
||||||
|
|
||||||
echo ">> Creating SHA256 sum"
|
|
||||||
|
|
||||||
sha256sum $output_image > $output_image.sha256
|
|
||||||
|
|
||||||
cleanup
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
iso:
|
|
||||||
uefi:
|
|
||||||
- dir:/efi
|
|
||||||
image:
|
|
||||||
- dir:/efi
|
|
||||||
- dir:/grub2
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
name: "Default user"
|
|
||||||
stages:
|
|
||||||
initramfs:
|
|
||||||
- name: "Set default user/pass"
|
|
||||||
users:
|
|
||||||
kairos:
|
|
||||||
passwd: "kairos"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
elemental --config-dir /config $@
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Transform a raw image disk to gce compatible
|
|
||||||
RAWIMAGE="$1"
|
|
||||||
OUT="${2:-$RAWIMAGE.gce.raw}"
|
|
||||||
cp -rf $RAWIMAGE $OUT
|
|
||||||
|
|
||||||
GB=$((1024*1024*1024))
|
|
||||||
size=$(qemu-img info -f raw --output json "$OUT" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
|
|
||||||
# shellcheck disable=SC2004
|
|
||||||
ROUNDED_SIZE=$(echo "$size/$GB+1"|bc)
|
|
||||||
echo "Resizing raw image from \"$size\"MB to \"$ROUNDED_SIZE\"GB"
|
|
||||||
qemu-img resize -f raw "$OUT" "$ROUNDED_SIZE"G
|
|
||||||
echo "Compressing raw image $OUT to $OUT.tar.gz"
|
|
||||||
tar -c -z --format=oldgnu -f "$OUT".tar.gz $OUT
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Extracts squashfs, kernel, initrd and generates a ipxe template script
|
|
||||||
|
|
||||||
ISO=$1
|
|
||||||
OUTPUT_NAME=$2
|
|
||||||
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
|
|
||||||
|
|
||||||
URL=${URL:-https://github.com/kairos-io/kairos/releases/download}
|
|
||||||
|
|
||||||
cat > $OUTPUT_NAME.ipxe << EOF
|
|
||||||
#!ipxe
|
|
||||||
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}
|
|
||||||
initrd \${url}/\${initrd}
|
|
||||||
boot
|
|
||||||
EOF
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Generates EFI bootable images (statically)
|
|
||||||
# This is a re-adaptation of https://github.com/rancher/elemental-toolkit/blob/v0.8.10-1/images/img-builder.sh, which was dropped
|
|
||||||
# How to use:
|
|
||||||
# First extract the image which you want to create an image from:
|
|
||||||
### luet util unpack <image> rootfs
|
|
||||||
# Then convert it to a raw disk (EFI only):
|
|
||||||
### docker run -v $PWD:/output --entrypoint /raw-images.sh -ti --rm test-image /output/rootfs /output/foo.raw cloud-init.yaml
|
|
||||||
|
|
||||||
: "${OEM_LABEL:=COS_OEM}"
|
|
||||||
: "${RECOVERY_LABEL:=COS_RECOVERY}"
|
|
||||||
: "${EXTEND:=}"
|
|
||||||
|
|
||||||
DIRECTORY=$1
|
|
||||||
OUT=${2:-disk.raw}
|
|
||||||
CONFIG=$3
|
|
||||||
|
|
||||||
echo "Output: $OUT"
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
mkdir -p /build/root/grub2
|
|
||||||
mkdir /build/root/cOS
|
|
||||||
mkdir /build/efi
|
|
||||||
|
|
||||||
cp -rf /raw/grub/* /build/efi
|
|
||||||
cp -rf /raw/grubconfig/* /build/root
|
|
||||||
cp -rf /raw/grubartifacts/* /build/root/grub2
|
|
||||||
|
|
||||||
echo "Generating squashfs from $DIRECTORY"
|
|
||||||
mksquashfs $DIRECTORY recovery.squashfs -b 1024k -comp xz -Xbcj x86
|
|
||||||
mv recovery.squashfs /build/root/cOS/recovery.squashfs
|
|
||||||
|
|
||||||
grub2-editenv /build/root/grub_oem_env set "default_menu_entry=Kairos"
|
|
||||||
|
|
||||||
# Create a 2GB filesystem for RECOVERY including the contents for root (grub config and squasfs container)
|
|
||||||
truncate -s $((2048*1024*1024)) rootfs.part
|
|
||||||
mkfs.ext2 -L "${RECOVERY_LABEL}" -d /build/root rootfs.part
|
|
||||||
|
|
||||||
# Create the EFI partition FAT16 and include the EFI image and a basic grub.cfg
|
|
||||||
truncate -s $((20*1024*1024)) efi.part
|
|
||||||
|
|
||||||
mkfs.fat -F16 -n COS_GRUB efi.part
|
|
||||||
mcopy -s -i efi.part /build/efi/EFI ::EFI
|
|
||||||
|
|
||||||
# Create the grubenv forcing first boot to be on recovery system
|
|
||||||
mkdir -p /build/oem
|
|
||||||
cp /build/root/etc/cos/grubenv_firstboot /build/oem/grubenv
|
|
||||||
if [ -n "$CONFIG" ]; then
|
|
||||||
echo "Copying config file ($CONFIG)"
|
|
||||||
cp $CONFIG /build/oem
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create a 64MB filesystem for OEM volume
|
|
||||||
truncate -s $((64*1024*1024)) oem.part
|
|
||||||
mkfs.ext2 -L "${OEM_LABEL}" -d /build/oem oem.part
|
|
||||||
|
|
||||||
echo "Generating image $OUT"
|
|
||||||
# Create disk image, add 3MB of initial free space to disk, 1MB is for proper alignement, 2MB are for the hybrid legacy boot.
|
|
||||||
truncate -s $((3*1024*1024)) $OUT
|
|
||||||
{
|
|
||||||
cat efi.part
|
|
||||||
cat oem.part
|
|
||||||
cat rootfs.part
|
|
||||||
} >> $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
|
|
||||||
sgdisk -n 3:0:+64M -c 3:oem -t 3:8300 $OUT
|
|
||||||
sgdisk -n 4:0:+2048M -c 4:root -t 4:8300 $OUT
|
|
||||||
Reference in New Issue
Block a user