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

update manifests for dev releases #9754

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ generate:
$(MAKE) gen-manifests

gen-manifests: bin/helm
cd ./manifests && \
OPERATOR_VERSION=$(OPERATOR_VERSION) \
CALICO_VERSION=$(CALICO_VERSION) \
./generate.sh
cd ./manifests && ./generate.sh

# Get operator CRDs from the operator repo, OPERATOR_BRANCH must be set
get-operator-crds: var-require-all-OPERATOR_BRANCH
Expand Down
111 changes: 65 additions & 46 deletions manifests/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ HELM=${HELM:-../bin/helm}
defaultCalicoVersion=$(cat ../charts/calico/values.yaml | grep version: | cut -d" " -f2)
CALICO_VERSION=${CALICO_VERSION:-$defaultCalicoVersion}

defaultRegistry="calico"
REGISTRY=${REGISTRY:-$defaultRegistry}

defaultOperatorVersion=$(cat ../charts/tigera-operator/values.yaml | grep version: | cut -d" " -f4)
OPERATOR_VERSION=${OPERATOR_VERSION:-$defaultOperatorVersion}

defaultOperatorRegistry=$($YQ .tigeraOperator.registry <../charts/tigera-operator/values.yaml)
OPERATOR_REGISTRY=${OPERATOR_REGISTRY:-$defaultOperatorRegistry}

defaultOperatorImage="tigera/operator"
OPERATOR_IMAGE=${OPERATOR_IMAGE:-$defaultOperatorImage}

NON_HELM_MANIFEST_IMAGES="calico/apiserver calico/windows calico/ctl calico/csi calico/node-driver-registrar calico/dikastes calico/flannel-migration-controller"

echo "Generating manifests for Calico=$CALICO_VERSION and tigera-operator=$OPERATOR_VERSION"

##########################################################################
# Update images in the values file
##########################################################################
if [[ $REGISTRY != "calico" ]]; then
sed -i "s|image: docker.io/calico|image: $REGISTRY|g" ../charts/calico/values.yaml
fi
##########################################################################
# Build the operator manifest.
##########################################################################
cat <<EOF > tigera-operator.yaml
cat <<EOF >tigera-operator.yaml
apiVersion: v1
kind: Namespace
metadata:
Expand All @@ -32,47 +47,48 @@ metadata:
EOF

${HELM} -n tigera-operator template \
--no-hooks \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set calicoctl.tag=$CALICO_VERSION \
../charts/tigera-operator >> tigera-operator.yaml
--no-hooks \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set tigeraOperator.image=$OPERATOR_IMAGE \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set tigeraOperator.registry=$OPERATOR_REGISTRY \
--set calicoctl.tag=$CALICO_VERSION \
../charts/tigera-operator >>tigera-operator.yaml

##########################################################################
# Build CRD manifest.
#
# This manifest is used in "Calico the hard way" documentation.
##########################################################################
echo "# CustomResourceDefinitions for Calico the Hard Way" > crds.yaml
echo "# CustomResourceDefinitions for Calico the Hard Way" >crds.yaml
for FILE in $(ls ../charts/calico/crds); do
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >> crds.yaml
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >>crds.yaml
done

##########################################################################
# Build manifest which includes both Calico and Operator CRDs.
##########################################################################
echo "# CustomResourceDefinitions for Calico and Tigera operator" > operator-crds.yaml
echo "# CustomResourceDefinitions for Calico and Tigera operator" >operator-crds.yaml
for FILE in $(ls ../charts/tigera-operator/crds/*.yaml | xargs -n1 basename); do
${HELM} -n tigera-operator template \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
../charts/tigera-operator >> operator-crds.yaml
${HELM} -n tigera-operator template \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
../charts/tigera-operator >>operator-crds.yaml
done
for FILE in $(ls ../charts/calico/crds); do
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >> operator-crds.yaml
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >>operator-crds.yaml
done


##########################################################################
# Build Calico manifests.
#
Expand All @@ -82,11 +98,11 @@ done
VALUES_FILES=$(cd ../charts/values && find . -type f -name "*.yaml")

for FILE in $VALUES_FILES; do
echo "Generating manifest from charts/values/$FILE"
${HELM} -n kube-system template \
../charts/calico \
--set version=$CALICO_VERSION \
-f ../charts/values/$FILE > $FILE
echo "Generating manifest from charts/values/$FILE"
${HELM} -n kube-system template \
../charts/calico \
--set version=$CALICO_VERSION \
-f ../charts/values/$FILE >$FILE
done

##########################################################################
Expand All @@ -96,15 +112,18 @@ done
# Then do a bit of cleanup to reduce the directory depth to 1.
##########################################################################
${HELM} template \
-n tigera-operator \
../charts/tigera-operator/ \
--output-dir ocp \
--no-hooks \
--set installation.kubernetesProvider=OpenShift \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set calicoctl.tag=$CALICO_VERSION
-n tigera-operator \
../charts/tigera-operator/ \
--output-dir ocp \
--no-hooks \
--set installation.kubernetesProvider=OpenShift \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set tigeraOperator.image=$OPERATOR_IMAGE \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set tigeraOperator.registry=$OPERATOR_REGISTRY \
--set calicoctl.image=$REGISTRY/ctl \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong that calicoctl.image is of the form REGISTRY/CTL whereas the tigeraOperator.image is just of the form tigera/operator with the registry configured separately - we should be using consistent meanings for image / version / registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the calicoctl images are pushed as /ctl

sadly we currently do not follow a consistent pattern b/w operator and monorepo images, that will require a bigger overhaul which is beyond the scope of this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calicoctl images are pushed as /ctl

Surely they must be pushed as docker.io/calico/ctl no?

Operator has two separate config options - registry and image

Calicoctl has a single option - image - that appears to be a merged version of registry and image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my dev images, it is created as docker.io/tuticat/ctl

When the default registry is not overwritten, this be set to calico/ctl which matches the current state of image: calico/ctl:master

--set calicoctl.tag=$CALICO_VERSION
# The first two lines are a newline and a yaml separator - remove them.
find ocp/tigera-operator -name "*.yaml" | xargs sed -i -e 1,2d
mv $(find ocp/tigera-operator -name "*.yaml") ocp/ && rm -r ocp/tigera-operator
Expand All @@ -115,16 +134,16 @@ mv $(find ocp/tigera-operator -name "*.yaml") ocp/ && rm -r ocp/tigera-operator
##########################################################################
echo "Generating manifest from charts/values/$FILE"
${HELM} -n kube-system template \
../charts/calico \
-f ../node/tests/k8st/infra/values.yaml > ../node/tests/k8st/infra/calico-kdd.yaml
../charts/calico \
-f ../node/tests/k8st/infra/values.yaml >../node/tests/k8st/infra/calico-kdd.yaml

##########################################################################
# Replace image versions for "static" Calico manifests.
##########################################################################
if [[ $CALICO_VERSION != master ]]; then
echo "Replacing image versions for static manifests"
for img in $NON_HELM_MANIFEST_IMAGES; do
echo $img
find . -type f -exec sed -i "s|$img:[A-Xa-z0-9_.-]*|$img:$CALICO_VERSION|g" {} \;
done
echo "Replacing image versions for static manifests"
for img in $NON_HELM_MANIFEST_IMAGES; do
echo $img
find . -type f -exec sed -i "s|$img:[A-Xa-z0-9_.-]*|$REGISTRY${img#calico}:$CALICO_VERSION|g" {} \;
done
fi
22 changes: 14 additions & 8 deletions release/pkg/manager/calico/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ func (r *CalicoManager) getRegistryFromManifests() (string, error) {
}
imgs := strings.Split(out, "\n")
for _, i := range imgs {
if strings.Contains(i, "operator") {
continue
} else if strings.Contains(i, "tigera/") {
splits := strings.SplitAfter(i, "/tigera/")
registry := splits[0]
logrus.WithField("registry", registry).Debugf("Using registry from image %s", i)
return registry, nil
if strings.HasPrefix(i, "calico/") {
return "", nil
} else {
parts := strings.Split(i, "/")
if len(parts) > 1 {
return strings.Join(parts[:len(parts)-1], "/"), nil
}
}
}
return "", fmt.Errorf("failed to find registry from manifests")
Expand Down Expand Up @@ -883,6 +883,12 @@ func (r *CalicoManager) generateManifests() error {
env := os.Environ()
env = append(env, fmt.Sprintf("CALICO_VERSION=%s", r.calicoVersion))
env = append(env, fmt.Sprintf("OPERATOR_VERSION=%s", r.operatorVersion))
// If not using default registries, update the registry in the manifests.
if !reflect.DeepEqual(r.imageRegistries, defaultRegistries) {
env = append(env, fmt.Sprintf("REGISTRY=%s", r.imageRegistries[0]))
}
env = append(env, fmt.Sprintf("OPERATOR_REGISTRY=%s", r.operatorRegistry))
env = append(env, fmt.Sprintf("OPERATOR_IMAGE=%s", r.operatorImage))
if err := r.makeInDirectoryIgnoreOutput(r.repoRoot, "gen-manifests", env...); err != nil {
logrus.WithError(err).Error("Failed to make manifests")
return err
Expand All @@ -891,7 +897,7 @@ func (r *CalicoManager) generateManifests() error {
}

func (r *CalicoManager) resetManifests() {
if _, err := r.runner.RunInDir(r.repoRoot, "git", []string{"checkout", "manifests"}, nil); err != nil {
if _, err := r.runner.RunInDir(r.repoRoot, "git", []string{"checkout", "manifests", "charts"}, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What change happens in the charts diretory? I can't see where we're modifying that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the images in charts/calico/values.yaml have their registies updated by manifests/generate.sh here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I need to think about that one for a moment. I think it's a change in scope of the generate.sh script that I might not be completely comfortable with. That script is meant to deterministically generate manifests based on values.yaml, not be responsible for modifying values.yaml itself.

logrus.WithError(err).Error("Failed to reset manifests")
}
}
Expand Down
Loading