mirror of https://github.com/fluxcd/flux2.git
Embed the install manifests in flux binary
- add make target for generating the install manifests using kustomize - embed the generated manifests in flux binary - the install and bootstrap commands default to using the embedded manifests - download the install manifests from GitHub only if the install/bootstrap version arg is set Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>pull/987/head
parent
1f16b6d639
commit
6003d11156
@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed manifests/*.yaml
|
||||||
|
var embeddedManifests embed.FS
|
||||||
|
|
||||||
|
func writeEmbeddedManifests(dir string) error {
|
||||||
|
manifests, err := fs.ReadDir(embeddedManifests, "manifests")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, manifest := range manifests {
|
||||||
|
data, err := fs.ReadFile(embeddedManifests, path.Join("manifests", manifest.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("reading file failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(path.Join(dir, manifest.Name()), data, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("writing file failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getVersion(input string) (string, error) {
|
||||||
|
if input == "" {
|
||||||
|
return rootArgs.defaults.Version, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if isEmbeddedVersion(input) {
|
||||||
|
return input, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if input == install.MakeDefaultOptions().Version {
|
||||||
|
input, err = install.GetLatestVersion()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ok, err := install.ExistingVersion(input); err != nil || !ok {
|
||||||
|
if err == nil {
|
||||||
|
err = fmt.Errorf("targeted version '%s' does not exist", input)
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !utils.CompatibleVersion(VERSION, input) {
|
||||||
|
return "", fmt.Errorf("targeted version '%s' is not compatible with your current version of flux (%s)", input, VERSION)
|
||||||
|
}
|
||||||
|
return input, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isEmbeddedVersion(input string) bool {
|
||||||
|
return input == rootArgs.defaults.Version
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright 2020 The Flux authors. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||||
|
OUT_PATH=${1:-"${REPO_ROOT}/cmd/flux/manifests"}
|
||||||
|
TAR=${2}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
echo '[INFO] ' "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal() {
|
||||||
|
echo '[ERROR] ' "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
info "building $(basename $2)"
|
||||||
|
kustomize build "$1" > "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! [ -x "$(command -v kustomize)" ]; then
|
||||||
|
fatal 'kustomize is not installed'
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf $OUT_PATH
|
||||||
|
mkdir -p $OUT_PATH
|
||||||
|
files=""
|
||||||
|
|
||||||
|
info using "$(kustomize version --short)"
|
||||||
|
|
||||||
|
# build controllers
|
||||||
|
for controller in ${REPO_ROOT}/manifests/bases/*/; do
|
||||||
|
output_path="${OUT_PATH}/$(basename $controller).yaml"
|
||||||
|
build $controller $output_path
|
||||||
|
files+=" $(basename $output_path)"
|
||||||
|
done
|
||||||
|
|
||||||
|
# build rbac
|
||||||
|
rbac_path="${REPO_ROOT}/manifests/rbac"
|
||||||
|
rbac_output_path="${OUT_PATH}/rbac.yaml"
|
||||||
|
build $rbac_path $rbac_output_path
|
||||||
|
files+=" $(basename $rbac_output_path)"
|
||||||
|
|
||||||
|
# build policies
|
||||||
|
policies_path="${REPO_ROOT}/manifests/policies"
|
||||||
|
policies_output_path="${OUT_PATH}/policies.yaml"
|
||||||
|
build $policies_path $policies_output_path
|
||||||
|
files+=" $(basename $policies_output_path)"
|
||||||
|
|
||||||
|
# create tarball
|
||||||
|
if [[ -n $TAR ]];then
|
||||||
|
info "archiving $TAR"
|
||||||
|
cd ${OUT_PATH} && tar -czf $TAR $files
|
||||||
|
fi
|
Loading…
Reference in New Issue