mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-07-08 03:54:26 +00:00
Move directories around
This commit is contained in:
+2
-1
@@ -2,6 +2,7 @@
|
|||||||
FROM golang:1.22 AS builder
|
FROM golang:1.22 AS builder
|
||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
ARG IMAGE_VERSION_TAG
|
||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
# Copy the Go Modules manifests
|
# Copy the Go Modules manifests
|
||||||
@@ -21,7 +22,7 @@ COPY internal/ internal/
|
|||||||
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
|
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
|
||||||
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
|
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
|
||||||
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
|
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
|
||||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
|
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags "-X shared.BACKUP_JOB_IMAGE=ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:v${IMAGE_VERSION_TAG}" -a -o manager cmd/main.go
|
||||||
|
|
||||||
# Use distroless as minimal base image to package the manager binary
|
# Use distroless as minimal base image to package the manager binary
|
||||||
# Refer to https://github.com/GoogleContainerTools/distroless for more details
|
# Refer to https://github.com/GoogleContainerTools/distroless for more details
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# Image URL to use all building/pushing image targets
|
# Image URL to use all building/pushing image targets
|
||||||
IMG ?= ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
IMG ?= ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
|
IMG_WORKER ?= ghcr.io/lukaszraczylo/kubernetes-images-sync-worker
|
||||||
|
CHART_NAME = kube-images-sync-operator
|
||||||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
|
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
|
||||||
ENVTEST_K8S_VERSION = 1.31.0
|
ENVTEST_K8S_VERSION = 1.31.0
|
||||||
|
|
||||||
@@ -115,10 +117,22 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
|
|||||||
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
||||||
- $(CONTAINER_TOOL) buildx create --name kubernetes-images-sync-operator-builder
|
- $(CONTAINER_TOOL) buildx create --name kubernetes-images-sync-operator-builder
|
||||||
$(CONTAINER_TOOL) buildx use kubernetes-images-sync-operator-builder
|
$(CONTAINER_TOOL) buildx use kubernetes-images-sync-operator-builder
|
||||||
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG}:${CURRENT_VERSION} -f Dockerfile.cross .
|
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --build-arg IMAGE_VERSION_TAG=${CURRENT_VERSION} --tag ${IMG}:${CURRENT_VERSION} -f Dockerfile.cross .
|
||||||
- $(CONTAINER_TOOL) buildx rm kubernetes-images-sync-operator-builder
|
- $(CONTAINER_TOOL) buildx rm kubernetes-images-sync-operator-builder
|
||||||
rm Dockerfile.cross
|
rm Dockerfile.cross
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: docker-buildx-job-container
|
||||||
|
docker-buildx-job-container: ## Build and push docker image for the manager for cross-platform support
|
||||||
|
@cd docker-image-worker && ( \
|
||||||
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross && \
|
||||||
|
$(CONTAINER_TOOL) buildx create --name kubernetes-images-sync-operator-builder || true && \
|
||||||
|
$(CONTAINER_TOOL) buildx use kubernetes-images-sync-operator-builder && \
|
||||||
|
$(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --build-arg IMAGE_VERSION_TAG=${CURRENT_VERSION} --tag ${IMG_WORKER}:${CURRENT_VERSION} -f Dockerfile.cross . && \
|
||||||
|
$(CONTAINER_TOOL) buildx rm kubernetes-images-sync-operator-builder || true && \
|
||||||
|
rm Dockerfile.cross \
|
||||||
|
) && cd ..
|
||||||
|
|
||||||
.PHONY: build-installer
|
.PHONY: build-installer
|
||||||
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
|
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -204,6 +218,22 @@ helm: manifests kustomize helmify
|
|||||||
cp chart-defaults/Chart.yaml chart/Chart.yaml && \
|
cp chart-defaults/Chart.yaml chart/Chart.yaml && \
|
||||||
./update-version.sh $(CURRENT_VERSION) $(IMG)
|
./update-version.sh $(CURRENT_VERSION) $(IMG)
|
||||||
|
|
||||||
|
.PHONY: release # Generates helm chart, builds docker images and pushes them to the registry
|
||||||
|
release: helm docker-buildx docker-buildx-job-container release-chart
|
||||||
|
|
||||||
|
.PHONY: release-chart
|
||||||
|
release-chart:
|
||||||
|
@test -d ../helm-charts || exit 1
|
||||||
|
rm -fr ../helm-charts/charts/${CHART_NAME} || true
|
||||||
|
mkdir -p ../helm-charts/charts/${CHART_NAME}
|
||||||
|
cp -R chart/* ../helm-charts/charts/${CHART_NAME}
|
||||||
|
cd ../helm-charts/charts/${CHART_NAME}; \
|
||||||
|
cr package --config ../../chart-releaser.yaml;
|
||||||
|
cd ../helm-charts/; git add -A charts/packages; git fix; git push;
|
||||||
|
cd ../helm-charts/charts/${CHART_NAME}; cr upload --config ../../chart-releaser.yaml --skip-existing;
|
||||||
|
cd ../helm-charts/charts/${CHART_NAME}; rm -fr .cr-index; mkdir .cr-index; cr index --config ../../chart-releaser.yaml; cp .cr-index/index.yaml ../../index.yaml; || true
|
||||||
|
git fix; git push
|
||||||
|
|
||||||
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
|
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
|
||||||
# $1 - target path with name of binary
|
# $1 - target path with name of binary
|
||||||
# $2 - package url which can be installed
|
# $2 - package url which can be installed
|
||||||
|
|||||||
@@ -1,102 +1,58 @@
|
|||||||
# kubernetes-images-sync-operator
|
# kubernetes-images-sync-operator
|
||||||
// TODO(user): Add simple overview of use/purpose
|
|
||||||
|
Kubernetes operator backing up images into the local / S3 compatible storage
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
// TODO(user): An in-depth paragraph about your project and overview of use
|
|
||||||
|
Operator was created to simplify the impex between open-to-world and air-gapped environment.
|
||||||
|
As transfer of the deployment manifests is relatively easy, images are a completely different story.
|
||||||
|
Air-gapped environments usually have issues with missing images and amount of data required to be transferred between them.
|
||||||
|
This operator takes care of it and ensures that no images were missed out ( including initImages and ephemeralImages ) and
|
||||||
|
impex itself is as small as possible due to the cross comparison with previouslly executed backups.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
### Prerequisites
|
Operator installation
|
||||||
- go version v1.22.0+
|
|
||||||
- docker version 17.03+.
|
|
||||||
- kubectl version v1.11.3+.
|
|
||||||
- Access to a Kubernetes v1.11.3+ cluster.
|
|
||||||
|
|
||||||
### To Deploy on the cluster
|
|
||||||
**Build and push your image to the location specified by `IMG`:**
|
|
||||||
|
|
||||||
```sh
|
```
|
||||||
make docker-build docker-push IMG=<some-registry>/kubernetes-images-sync-operator:tag
|
helm repo add raczylo https://lukaszraczylo.github.io/helm-charts/
|
||||||
|
helm install raczylo/kube-images-sync
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE:** This image ought to be published in the personal registry you specified.
|
## Starting the backup
|
||||||
And it is required to have access to pull the image from the working environment.
|
|
||||||
Make sure you have the proper permission to the registry if the above commands don’t work.
|
|
||||||
|
|
||||||
**Install the CRDs into the cluster:**
|
Please remember that backups are triggered whenever the new object appears
|
||||||
|
|
||||||
```sh
|
```
|
||||||
make install
|
apiVersion: raczylo.com/v1
|
||||||
|
kind: ClusterImageExport
|
||||||
|
metadata:
|
||||||
|
name: backup-20240901
|
||||||
|
spec:
|
||||||
|
# Excludes will remove all images with listed wording from the backup list
|
||||||
|
# excludes:
|
||||||
|
# - nginx
|
||||||
|
# Includes will add ONLY images with listed wording to the backup list
|
||||||
|
includes:
|
||||||
|
- busybox
|
||||||
|
basePath: /images # base path in the target directory
|
||||||
|
storage:
|
||||||
|
target: S3 # file backup is not ready yet
|
||||||
|
s3:
|
||||||
|
bucket: my-backup-in-s3
|
||||||
|
region: us-west-2
|
||||||
|
accessKey: yyy
|
||||||
|
secretKey: zzz
|
||||||
|
# Endpoint allows you to direct the backup to your own S3 compatible endpoint like minio
|
||||||
|
# endpoint: http://127.0.0.1:8010
|
||||||
|
# secretName: my-secret-in-cluster # Not ready yet
|
||||||
|
# useRole: true # Current role to be used instead of access / secret keys
|
||||||
|
# roleARN: my-awesome-role # Instead of picking the default role, use the specified one
|
||||||
|
maxConcurrentJobs: 1
|
||||||
```
|
```
|
||||||
|
|
||||||
**Deploy the Manager to the cluster with the image specified by `IMG`:**
|
#### Random fluff
|
||||||
|
|
||||||
```sh
|
|
||||||
make deploy IMG=<some-registry>/kubernetes-images-sync-operator:tag
|
|
||||||
```
|
|
||||||
|
|
||||||
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
|
|
||||||
privileges or be logged in as admin.
|
|
||||||
|
|
||||||
**Create instances of your solution**
|
|
||||||
You can apply the samples (examples) from the config/sample:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
kubectl apply -k config/samples/
|
|
||||||
```
|
|
||||||
|
|
||||||
>**NOTE**: Ensure that the samples has default values to test it out.
|
|
||||||
|
|
||||||
### To Uninstall
|
|
||||||
**Delete the instances (CRs) from the cluster:**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
kubectl delete -k config/samples/
|
|
||||||
```
|
|
||||||
|
|
||||||
**Delete the APIs(CRDs) from the cluster:**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make uninstall
|
|
||||||
```
|
|
||||||
|
|
||||||
**UnDeploy the controller from the cluster:**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make undeploy
|
|
||||||
```
|
|
||||||
|
|
||||||
## Project Distribution
|
|
||||||
|
|
||||||
Following are the steps to build the installer and distribute this project to users.
|
|
||||||
|
|
||||||
1. Build the installer for the image built and published in the registry:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make build-installer IMG=<some-registry>/kubernetes-images-sync-operator:tag
|
|
||||||
```
|
|
||||||
|
|
||||||
NOTE: The makefile target mentioned above generates an 'install.yaml'
|
|
||||||
file in the dist directory. This file contains all the resources built
|
|
||||||
with Kustomize, which are necessary to install this project without
|
|
||||||
its dependencies.
|
|
||||||
|
|
||||||
2. Using the installer
|
|
||||||
|
|
||||||
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
kubectl apply -f https://raw.githubusercontent.com/<org>/kubernetes-images-sync-operator/<tag or branch>/dist/install.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
// TODO(user): Add detailed information on how you would like others to contribute to this project
|
|
||||||
|
|
||||||
**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 2024.
|
Copyright 2024.
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -10,9 +10,9 @@ description: |
|
|||||||
|
|
||||||
type: application
|
type: application
|
||||||
|
|
||||||
version: 0.0.26
|
version: 0.1.5
|
||||||
|
|
||||||
appVersion: "0.0.26"
|
appVersion: "0.1.5"
|
||||||
|
|
||||||
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -10,8 +10,8 @@ cmRaczyloCom:
|
|||||||
drop:
|
drop:
|
||||||
- ALL
|
- ALL
|
||||||
image:
|
image:
|
||||||
repository: controller
|
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
tag: latest
|
tag: 0.1.5
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 500m
|
cpu: 500m
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// JOB IMAGES
|
// JOB IMAGES
|
||||||
BACKUP_JOB_IMAGE = "ghcr.io/lukaszraczylo/docker-image-management:v0.0.6"
|
BACKUP_JOB_IMAGE = "ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:1.0.2"
|
||||||
|
|
||||||
// AVAILABLE STATUSES
|
// AVAILABLE STATUSES
|
||||||
STATUS_PENDING = "PENDING"
|
STATUS_PENDING = "PENDING"
|
||||||
|
|||||||
+4
-2
@@ -1,8 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
find chart/ -type f -exec sed -i '' "s/0.0.0/$1/g" {} +
|
find chart/ -type f -exec sed -i '' "s/0.0.0/$1/g" {} +
|
||||||
find chart/values.yaml -type f -exec sed -i '' "s/repository: controller/$2/g" {} +
|
find chart/values.yaml -type f -exec sed -i '' "s|controller|$2|g" {} +
|
||||||
|
find chart/values.yaml -type f -exec sed -i '' "s|latest|$1|g" {} +
|
||||||
else
|
else
|
||||||
find chart/ -type f -exec sed -i "s/0.0.0/$1/g" {} +
|
find chart/ -type f -exec sed -i "s/0.0.0/$1/g" {} +
|
||||||
find chart/values.yaml -type f -exec sed -i "s/repository: controller/$2/g" {} +
|
find chart/values.yaml -type f -exec sed "s|controller|$2|g" {} +
|
||||||
|
find chart/values.yaml -type f -exec sed -i "s|latest|$1|g" {} +
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user