Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make imagePullPolicy configurable #20543

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions hack/update-manifests-imagepullpolicy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"flag"
"fmt"
"os"
"strings"

"gopkg.in/yaml.v2"
)

const AutoGenMsg = "# This is an auto-generated file. DO NOT EDIT"

func main() {
manifestFilePathPtr := flag.String("manifest", "", "")
imagePtr := flag.String("image", "quay.io/argoproj/argocd:latest", "")
imagePullPlolicyPtr := flag.String("image-pull-policy", "Always", "")

flag.Parse()

if manifestFilePathPtr == nil || *manifestFilePathPtr == "" {
fmt.Println("no manifest file path specified")
os.Exit(1)
}

manifestFileContent, err := os.ReadFile(*manifestFilePathPtr)
if err != nil {
fmt.Printf("failed to read manifest file %s: %v\n", *manifestFilePathPtr, err)
os.Exit(1)
}

manifests := strings.Split(string(manifestFileContent), "---")
convertedManifests := make([]string, 0, len(manifests))
for _, manifest := range manifests {
manifest = strings.TrimSpace(manifest)

unmarshalledManifest := yaml.MapSlice{}
if err := yaml.Unmarshal([]byte(manifest), &unmarshalledManifest); err != nil {
fmt.Println("failed to unmarshal manifest file:", err)
os.Exit(1)
}

loop(unmarshalledManifest, *imagePtr, *imagePullPlolicyPtr)

marshalledManifest, err := yaml.Marshal(unmarshalledManifest)
if err != nil {
fmt.Printf("failed to marshal manifest file: %v\n", err)
os.Exit(1)
}

convertedManifests = append(convertedManifests, strings.TrimSpace(string(marshalledManifest)))
}

convertedMergedManifest := strings.Join(convertedManifests, "\n---\n")
convertedMergedManifest = fmt.Sprintf("%s\n%s\n", AutoGenMsg, convertedMergedManifest)

manifestFileContent = []byte(convertedMergedManifest)

if err = os.WriteFile(*manifestFilePathPtr, manifestFileContent, 0o644); err != nil {
fmt.Printf("failed to write manifest file %s: %v\n", *manifestFilePathPtr, err)
os.Exit(1)
}
}

func loop(obj yaml.MapSlice, imageName, imagePullPolicy string) {
isTarget := false
for _, kv := range obj {
k, ok := kv.Key.(string)
if !ok || k != "image" {
continue
}

v, ok := kv.Value.(string)
if !ok || v != imageName {
continue
}

isTarget = true
}

if isTarget {
for i, kv := range obj {
k, ok := kv.Key.(string)
if ok && k == "imagePullPolicy" {
kv.Value = imagePullPolicy
}
obj[i] = kv
}
}

for _, kv := range obj {
obj, ok := kv.Value.(yaml.MapSlice)
if ok {
loop(obj, imageName, imagePullPolicy)
continue
}

items, ok := kv.Value.([]any)
if !ok {
continue
}
for _, item := range items {
obj, ok := item.(yaml.MapSlice)
if ok {
loop(obj, imageName, imagePullPolicy)
}
}
}
}
19 changes: 13 additions & 6 deletions hack/update-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ set -o nounset
set -o pipefail

SRCROOT="$( CDPATH='' cd -- "$(dirname "$0")/.." && pwd -P )"
AUTOGENMSG="# This is an auto-generated file. DO NOT EDIT"

KUSTOMIZE=kustomize
[ -f "$SRCROOT/dist/kustomize" ] && KUSTOMIZE="$SRCROOT/dist/kustomize"

HACK_IMAGEPULLPOLICY="${SRCROOT}/hack/update-manifests-imagepullpolicy"

cd ${SRCROOT}/manifests/ha/base/redis-ha && ./generate.sh

IMAGE_NAMESPACE="${IMAGE_NAMESPACE:-quay.io/argoproj}"
IMAGE_TAG="${IMAGE_TAG:-}"
IMAGE_PULL_POLICY="${IMAGE_PULL_POLICY:-Always}"

# if the tag has not been declared, and we are on a release branch, use the VERSION file.
if [ "$IMAGE_TAG" = "" ]; then
Expand All @@ -35,17 +37,22 @@ cd ${SRCROOT}/manifests/base && $KUSTOMIZE edit set image quay.io/argoproj/argoc
cd ${SRCROOT}/manifests/ha/base && $KUSTOMIZE edit set image quay.io/argoproj/argocd=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG}
cd ${SRCROOT}/manifests/core-install && $KUSTOMIZE edit set image quay.io/argoproj/argocd=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG}

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/install.yaml"
echo -n "" > "${SRCROOT}/manifests/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/cluster-install" >> "${SRCROOT}/manifests/install.yaml"
go run $HACK_IMAGEPULLPOLICY -manifest=${SRCROOT}/manifests/install.yaml -image=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG} -image-pull-policy=$IMAGE_PULL_POLICY

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/namespace-install.yaml"
echo -n "" > "${SRCROOT}/manifests/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/namespace-install" >> "${SRCROOT}/manifests/namespace-install.yaml"
go run $HACK_IMAGEPULLPOLICY -manifest=${SRCROOT}/manifests/namespace-install.yaml -image=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG} -image-pull-policy=$IMAGE_PULL_POLICY

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/ha/install.yaml"
echo -n "" > "${SRCROOT}/manifests/ha/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/cluster-install" >> "${SRCROOT}/manifests/ha/install.yaml"
go run $HACK_IMAGEPULLPOLICY -manifest=${SRCROOT}/manifests/ha/install.yaml -image=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG} -image-pull-policy=$IMAGE_PULL_POLICY

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/ha/namespace-install.yaml"
echo -n "" > "${SRCROOT}/manifests/ha/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/namespace-install" >> "${SRCROOT}/manifests/ha/namespace-install.yaml"
go run $HACK_IMAGEPULLPOLICY -manifest=${SRCROOT}/manifests/ha/namespace-install.yaml -image=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG} -image-pull-policy=$IMAGE_PULL_POLICY

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/core-install.yaml"
echo -n "" > "${SRCROOT}/manifests/core-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/core-install" >> "${SRCROOT}/manifests/core-install.yaml"
go run $HACK_IMAGEPULLPOLICY -manifest=${SRCROOT}/manifests/core-install.yaml -image=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG} -image-pull-policy=$IMAGE_PULL_POLICY
2 changes: 1 addition & 1 deletion manifests/base/dex/argocd-dex-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
containers:
- name: dex
image: ghcr.io/dexidp/dex:v2.41.1
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
command: [/shared/argocd-dex, rundex]
env:
- name: ARGOCD_DEX_SERVER_LOGFORMAT
Expand Down
4 changes: 2 additions & 2 deletions manifests/base/redis/argocd-redis-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
- admin
- redis-initial-password
image: quay.io/argoproj/argocd:latest
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
name: secret-init
securityContext:
allowPrivilegeEscalation: false
Expand All @@ -41,7 +41,7 @@ spec:
containers:
- name: redis
image: redis:7.0.15-alpine
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
args:
- "--save"
- ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ spec:
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/argoproj/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
runAsNonRoot: true
Expand Down
5 changes: 3 additions & 2 deletions manifests/core-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: secret-init
command: [ 'argocd', 'admin', 'redis-initial-password' ]
image: quay.io/argoproj/argocd:latest
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
5 changes: 3 additions & 2 deletions manifests/ha/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions manifests/ha/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions manifests/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions manifests/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.