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

ci: Parameterize CNS image repository #2280

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
18 changes: 7 additions & 11 deletions .pipelines/cni/cilium/cilium-overlay-load-test-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ stages:
- stage: ${{ parameters.name }}
variables:
commitID: $[ stagedependencies.setup.env.outputs['SetEnvVars.commitID'] ]
cnsVersion: $[ stagedependencies.setup.env.outputs['SetEnvVars.cnsVersion'] ]
dropgzVersion: $[ stagedependencies.setup.env.outputs['SetEnvVars.dropgzVersion'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT)"
dependsOn:
Expand All @@ -54,24 +56,18 @@ stages:
pwd
kubectl cluster-info
kubectl get po -owide -A
echo "Deploy Azure-CNS"
kubectl apply -f test/integration/manifests/cilium/cns-write-ovly.yaml

echo "deploy Cilium ConfigMap"
kubectl apply -f cilium/configmap.yaml
kubectl apply -f test/integration/manifests/cilium/cilium-config.yaml
echo "install Cilium onto Overlay Cluster"
kubectl apply -f test/integration/manifests/cilium/cilium-agent
kubectl apply -f test/integration/manifests/cilium/cilium-operator
echo "install Cilium ${CILIUM_VERSION_TAG} onto Overlay Cluster"
# Passes Cilium image to daemonset and deployment
envsubst '${CILIUM_VERSION_TAG},${CILIUM_IMAGE_REGISTRY}' < test/integration/manifests/cilium/daemonset.yaml | kubectl apply -f -
envsubst '${CILIUM_VERSION_TAG},${CILIUM_IMAGE_REGISTRY}' < test/integration/manifests/cilium/deployment.yaml | kubectl apply -f -
kubectl get po -owide -A
echo "deploy ip-masq-agent for overlay"
kubectl create -f test/integration/manifests/ip-masq-agent/ip-masq-agent.yaml --validate=false
cd test/integration/manifests/ip-masq-agent/
kubectl create configmap config-custom.yaml
kubectl create configmap config-reconcile.yaml
cd ../../../..

echo "Deploy Azure-CNS"
sudo -E env "PATH=$PATH" make test-integration CNS_VERSION=$(cnsVersion) CNI_DROPGZ_VERSION=$(dropgzVersion) INSTALL_CNS=true INSTALL_OVERLAY=true TEST_DROPGZ=${{ parameters.testDropgz }} CNS_IMAGE_REPO=$(CNS_IMAGE_REPO)
kubectl get po -owide -A
- job: deploy_pods
displayName: "Scale Test"
Expand Down
4 changes: 2 additions & 2 deletions .pipelines/cni/singletenancy/linux-cniv2-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ stages:
make -C ./hack/aks set-kubeconf AZCLI=az CLUSTER=${{ parameters.clusterName }}-$(commitID)
kubectl cluster-info
kubectl get po -owide -A
sudo -E env "PATH=$PATH" make test-integration CNS_VERSION=$(cnsVersion) CNI_DROPGZ_VERSION=$(dropgzVersion) INSTALL_CNS=true INSTALL_AZURE_CNI_OVERLAY=true TEST_DROPGZ=${{ parameters.testDropgz }}
sudo -E env "PATH=$PATH" make test-integration CNS_VERSION=$(cnsVersion) CNI_DROPGZ_VERSION=$(dropgzVersion) INSTALL_CNS=true INSTALL_AZURE_CNI_OVERLAY=true TEST_DROPGZ=${{ parameters.testDropgz }} CNS_IMAGE_REPO=$(CNS_IMAGE_REPO)
name: "overlaye2e"
displayName: "Overlay Integration"
- ${{ if contains(parameters.clusterType, 'swift') }}:
Expand All @@ -81,7 +81,7 @@ stages:
make -C ./hack/aks set-kubeconf AZCLI=az CLUSTER=${{ parameters.clusterName }}-$(commitID)
kubectl cluster-info
kubectl get po -owide -A
sudo -E env "PATH=$PATH" make test-integration CNS_VERSION=$(cnsVersion) CNI_DROPGZ_VERSION=$(dropgzVersion) INSTALL_CNS=true INSTALL_AZURE_VNET=true TEST_DROPGZ=${{ parameters.testDropgz }}
sudo -E env "PATH=$PATH" make test-integration CNS_VERSION=$(cnsVersion) CNI_DROPGZ_VERSION=$(dropgzVersion) INSTALL_CNS=true INSTALL_AZURE_VNET=true TEST_DROPGZ=${{ parameters.testDropgz }} CNS_IMAGE_REPO=$(CNS_IMAGE_REPO)
name: "swifte2e"
displayName: "Swift Integration"
- template: ../../npm/npm-cni-integration-test.yaml
Expand Down
13 changes: 8 additions & 5 deletions test/internal/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,16 @@ func MustSetupConfigMap(ctx context.Context, clientset *kubernetes.Clientset, co

func Int32ToPtr(i int32) *int32 { return &i }

func ParseImageString(s string) (image, version string) {
sl := strings.Split(s, ":")
return sl[0], sl[1]
func ParseImageString(s string) (url, image, version string) {
s1 := strings.Split(s, ":")
s2 := s1[0]
index := strings.LastIndex(s2, "/") // Returns byte location

return s2[:index], s2[index:], s1[1]
}

func GetImageString(image, version string) string {
return image + ":" + version
func GetImageString(url, image, version string) string {
return url + image + ":" + version
}

func WaitForPodsRunning(ctx context.Context, clientset *kubernetes.Clientset, namespace, labelselector string) error {
Expand Down
25 changes: 19 additions & 6 deletions test/internal/kubernetes/utils_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ const (
envTestDropgz = "TEST_DROPGZ"
envCNIDropgzVersion = "CNI_DROPGZ_VERSION"
envCNSVersion = "CNS_VERSION"
envCNSImageRepo = "CNS_IMAGE_REPO"
EnvInstallCNS = "INSTALL_CNS"
cnsLinuxLabelSelector = "k8s-app=azure-cns"
cnsWindowsLabelSelector = "k8s-app=azure-cns-win"
acnImageRepoURL = "acnpublic.azurecr.io"
mcrImageRepoURL = "mcr.microsoft.com/containernetworking"
)

var imageRepoURL = map[string]string{
"ACN": acnImageRepoURL,
"MCR": mcrImageRepoURL,
}

var (
ErrUnsupportedCNSScenario = errors.New("unsupported CNS scenario")
ErrPathNotFound = errors.New("failed to get the absolute path to directory")
Expand Down Expand Up @@ -517,9 +525,14 @@ func parseCNSDaemonset(cnsVersion, cniDropgzVersion string,
}

cns := MustParseDaemonSet(cnsScenarioDetails.daemonsetPath)
_, image, _ := ParseImageString(cns.Spec.Template.Spec.Containers[0].Image)
url, key := imageRepoURL[os.Getenv(string(envCNSImageRepo))]
if !key {
log.Printf("%s not set to expected value \"ACN\", \"MCR\". Default to %s", envCNSImageRepo, imageRepoURL["ACN"])
url = imageRepoURL["ACN"]
}

image, _ := ParseImageString(cns.Spec.Template.Spec.Containers[0].Image)
cns.Spec.Template.Spec.Containers[0].Image = GetImageString(image, cnsVersion)
cns.Spec.Template.Spec.Containers[0].Image = GetImageString(url, image, cnsVersion)

log.Printf("Checking environment scenario")
cns = loadDropgzImage(cns, cniDropgzVersion)
Expand All @@ -546,12 +559,12 @@ func loadDropgzImage(cns appsv1.DaemonSet, dropgzVersion string) appsv1.DaemonSe
installFlag := os.Getenv(envTestDropgz)
if testDropgzScenario, err := strconv.ParseBool(installFlag); err == nil && testDropgzScenario {
log.Printf("Env %v set to true, deploy cniTest.Dockerfile", envTestDropgz)
initImage, _ := ParseImageString("acnpublic.azurecr.io/cni-dropgz-test:latest")
cns.Spec.Template.Spec.InitContainers[0].Image = GetImageString(initImage, dropgzVersion)
url, initImage, _ := ParseImageString("acnpublic.azurecr.io/cni-dropgz-test:latest")
cns.Spec.Template.Spec.InitContainers[0].Image = GetImageString(url, initImage, dropgzVersion)
} else {
log.Printf("Env %v not set to true, deploying cni.Dockerfile", envTestDropgz)
initImage, _ := ParseImageString(cns.Spec.Template.Spec.InitContainers[0].Image)
cns.Spec.Template.Spec.InitContainers[0].Image = GetImageString(initImage, dropgzVersion)
url, initImage, _ := ParseImageString(cns.Spec.Template.Spec.InitContainers[0].Image)
cns.Spec.Template.Spec.InitContainers[0].Image = GetImageString(url, initImage, dropgzVersion)
}
return cns
}
Expand Down