forked from Katenary/katenary
Compare commits
5 Commits
feat-fix-i
...
svc-option
| Author | SHA1 | Date | |
|---|---|---|---|
|
3a1c170140
|
|||
| 7230081401 | |||
| f0fc694d50 | |||
| d92cc8a01c | |||
| 3abfaf591c |
23
install.sh
23
install.sh
@@ -4,20 +4,25 @@
|
|||||||
# Can be launched with the following command:
|
# Can be launched with the following command:
|
||||||
# sh <(curl -sSL https://raw.githubusercontent.com/Katenary/katenary/master/install.sh)
|
# sh <(curl -sSL https://raw.githubusercontent.com/Katenary/katenary/master/install.sh)
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Detect the OS and architecture
|
# Detect the OS and architecture
|
||||||
OS=$(uname)
|
OS=$(uname)
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
for c in curl grep cut tr; do
|
||||||
|
if ! command -v $c >/dev/null 2>&1; then
|
||||||
|
echo "Error: $c is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Detect the home directory "bin" directory, it is commonly:
|
# Detect the home directory "bin" directory, it is commonly:
|
||||||
# - $HOME/.local/bin
|
# - $HOME/.local/bin
|
||||||
# - $HOME/.bin
|
# - $HOME/.bin
|
||||||
# - $HOME/bin
|
# - $HOME/bin
|
||||||
COMON_INSTALL_PATHS="$HOME/.local/bin $HOME/.bin $HOME/bin"
|
COMMON_INSTALL_PATHS="$HOME/.local/bin $HOME/.bin $HOME/bin"
|
||||||
|
|
||||||
INSTALL_PATH=""
|
INSTALL_PATH=""
|
||||||
for p in $COMON_INSTALL_PATHS; do
|
for p in $COMMON_INSTALL_PATHS; do
|
||||||
if [ -d $p ]; then
|
if [ -d $p ]; then
|
||||||
INSTALL_PATH=$p
|
INSTALL_PATH=$p
|
||||||
break
|
break
|
||||||
@@ -43,20 +48,22 @@ if ! echo "$PATH" | grep -q "$INSTALL_PATH"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Where to download the binary
|
# Where to download the binary
|
||||||
BASE="https://github.com/Katenary/katenary/releases/latest/download/"
|
TAG=$(curl -sLf https://repo.katenary.io/api/v1/repos/katenary/katenary/releases/latest 2>/dev/null | grep -Po '"tag_name":\s*"[^"]*"' | cut -d ":" -f2 | tr -d '"')
|
||||||
|
TAG=${TAG#releases/}
|
||||||
|
|
||||||
# for compatibility with older ARM versions
|
# use the right names for the OS and architecture
|
||||||
if [ $ARCH = "x86_64" ]; then
|
if [ $ARCH = "x86_64" ]; then
|
||||||
ARCH="amd64"
|
ARCH="amd64"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BIN_URL="$BASE/katenary-$OS-$ARCH"
|
BIN_URL="https://repo.katenary.io/api/packages/Katenary/generic/katenary/$TAG/katenary-$OS-$ARCH"
|
||||||
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Downloading $BIN_URL"
|
echo "Downloading $BIN_URL"
|
||||||
|
|
||||||
T=$(mktemp -u)
|
T=$(mktemp -u)
|
||||||
curl -SL -# $BIN_URL -o $T || (echo "Failed to download katenary" && rm -f $T && exit 1)
|
curl -sLf -# $BIN_URL -o $T 2>/dev/null || (echo -e "Failed to download katenary version $TAG.\n\nPlease open an issue and explain the problem, following the link:\nhttps://repo.katenary.io/Katenary/katenary/issues/new?title=[install.sh]%20Install%20$TAG%20failed" && rm -f $T && exit 1)
|
||||||
|
|
||||||
mv "$T" "${INSTALL_PATH}/katenary"
|
mv "$T" "${INSTALL_PATH}/katenary"
|
||||||
chmod +x "${INSTALL_PATH}/katenary"
|
chmod +x "${INSTALL_PATH}/katenary"
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// isgnored service
|
// is ignored service
|
||||||
if isIgnored(service) {
|
if isIgnored(service) {
|
||||||
logger.Info("Ignoring service ", service.Name)
|
logger.Info("Ignoring service ", service.Name)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ type Service struct {
|
|||||||
SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
|
SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
|
||||||
Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
|
Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
|
||||||
Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
|
Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
|
||||||
|
SvcOptional *bool `yaml:"svc-optional,omitempty" json:"svc-optional,omitempty" jsonschema:"title=SvcOptional,description=SvcOptional the service in the conversion"`
|
||||||
Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
|
Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
|
||||||
ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
|
ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
|
||||||
MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
|
MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
|
||||||
@@ -94,6 +95,7 @@ func OverrideWithConfig(project *types.Project) {
|
|||||||
mustGetLabelContent(s.SamePod, labels.LabelSamePod)
|
mustGetLabelContent(s.SamePod, labels.LabelSamePod)
|
||||||
mustGetLabelContent(s.Description, labels.LabelDescription)
|
mustGetLabelContent(s.Description, labels.LabelDescription)
|
||||||
mustGetLabelContent(s.Ignore, labels.LabelIgnore)
|
mustGetLabelContent(s.Ignore, labels.LabelIgnore)
|
||||||
|
mustGetLabelContent(s.SvcOptional, labels.LabelSvcOptional)
|
||||||
mustGetLabelContent(s.Dependencies, labels.LabelDependencies)
|
mustGetLabelContent(s.Dependencies, labels.LabelDependencies)
|
||||||
mustGetLabelContent(s.ConfigMapFiles, labels.LabelConfigMapFiles)
|
mustGetLabelContent(s.ConfigMapFiles, labels.LabelConfigMapFiles)
|
||||||
mustGetLabelContent(s.MapEnv, labels.LabelMapEnv)
|
mustGetLabelContent(s.MapEnv, labels.LabelMapEnv)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const (
|
|||||||
LabelSamePod Label = KatenaryLabelPrefix + "/same-pod"
|
LabelSamePod Label = KatenaryLabelPrefix + "/same-pod"
|
||||||
LabelDescription Label = KatenaryLabelPrefix + "/description"
|
LabelDescription Label = KatenaryLabelPrefix + "/description"
|
||||||
LabelIgnore Label = KatenaryLabelPrefix + "/ignore"
|
LabelIgnore Label = KatenaryLabelPrefix + "/ignore"
|
||||||
|
LabelSvcOptional Label = KatenaryLabelPrefix + "/svc-optional"
|
||||||
LabelDependencies Label = KatenaryLabelPrefix + "/dependencies"
|
LabelDependencies Label = KatenaryLabelPrefix + "/dependencies"
|
||||||
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
|
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
|
||||||
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"
|
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"
|
||||||
|
|||||||
@@ -183,6 +183,12 @@
|
|||||||
example: "labels:\n {{ .KatenaryPrefix }}/ignore: \"true\""
|
example: "labels:\n {{ .KatenaryPrefix }}/ignore: \"true\""
|
||||||
type: "bool"
|
type: "bool"
|
||||||
|
|
||||||
|
"svc-optional":
|
||||||
|
short: "Make the service optional in the resulting helm chart"
|
||||||
|
long: "Making a service optional to be exported in helm chart."
|
||||||
|
example: "labels:\n {{ .KatenaryPrefix }}/svc-optional: \"true\""
|
||||||
|
type: "bool"
|
||||||
|
|
||||||
"dependencies":
|
"dependencies":
|
||||||
short: "Add Helm dependencies to the service."
|
short: "Add Helm dependencies to the service."
|
||||||
long: |-
|
long: |-
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ func (s *Service) Yaml() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any loadBalancer lines that may have been added unintentionally.
|
||||||
lines := []string{}
|
lines := []string{}
|
||||||
for line := range strings.SplitSeq(string(y), "\n") {
|
for line := range strings.SplitSeq(string(y), "\n") {
|
||||||
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {
|
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {
|
||||||
@@ -93,5 +94,19 @@ func (s *Service) Yaml() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
y = []byte(strings.Join(lines, "\n"))
|
y = []byte(strings.Join(lines, "\n"))
|
||||||
|
|
||||||
|
// If the service has the label "katenary.v3/svc-optional", wrap the output
|
||||||
|
// with a Helm values conditional.
|
||||||
|
if s.service != nil && s.service.Labels != nil {
|
||||||
|
if _, ok := s.service.Labels["katenary.v3/svc-optional"]; ok {
|
||||||
|
// Ensure we have a trailing newline before appending the closing block.
|
||||||
|
content := string(y)
|
||||||
|
if !strings.HasSuffix(content, "\n") {
|
||||||
|
content += "\n"
|
||||||
|
}
|
||||||
|
content = "{{- if .Values.service.enabled }}\n" + content + "{{- end }}\n"
|
||||||
|
y = []byte(content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return y, err
|
return y, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,14 @@ func isIgnored(service types.ServiceConfig) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isSvcOptionald returns true if the service is optional.
|
||||||
|
func isSvcOptional(service types.ServiceConfig) bool {
|
||||||
|
if v, ok := service.Labels[labels.LabelSvcOptional]; ok {
|
||||||
|
return v == "true" || v == "yes" || v == "1"
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// UnWrapTPL removes the line wrapping from a template.
|
// UnWrapTPL removes the line wrapping from a template.
|
||||||
func UnWrapTPL(in []byte) []byte {
|
func UnWrapTPL(in []byte) []byte {
|
||||||
return regexpLineWrap.ReplaceAll(in, []byte(" }}"))
|
return regexpLineWrap.ReplaceAll(in, []byte(" }}"))
|
||||||
|
|||||||
Reference in New Issue
Block a user