Repository: Azure/ARO-RP
Pull request #2369 (2022-08-31 02:59:54)

Fix autorest client generation
### Which issue this PR addresses:
relates to ADO-15132425

### What this PR does / why we need it:
Minor changes to autorest image and client generation:
- remove superfluous flags when installing autorest
- remove no longer needed sudo commands
- run sed operation inside a container, to eliminate flag differences between BSD/Darwin and GNU/Linux versions of sed

### Test plan for issue:
Tested locally

### Is there any documentation that needs to be updated for this PR?
No, these are just small fixes to scripts



Patch:
diff --git a/Dockerfile.autorest b/Dockerfile.autorest
index ce3512684..fb3c85550 100644
--- a/Dockerfile.autorest
+++ b/Dockerfile.autorest
@@ -18,7 +18,7 @@ USER 1001
 
 # Autorest
 RUN npm install -g autorest@${AUTOREST_VERSION} && \
-    autorest --reset --allow-no-input --csharp --ruby --python --java --go --nodejs --typescript --azure-validator --preview  && \
+    autorest --reset && \
     npm cache clean -f
 
 ENTRYPOINT ["autorest"]
diff --git a/Makefile b/Makefile
index 774238c35..5e00dcba7 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ E2E_FLAGS ?= -test.timeout 180m -test.v -ginkgo.v -ginkgo.noColor
 FLUENTBIT_VERSION = 1.9.4-1
 FLUENTBIT_IMAGE ?= ${RP_IMAGE_ACR}.azurecr.io/fluentbit:$(FLUENTBIT_VERSION)
 AUTOREST_VERSION = 3.6.2
-AUTOREST_IMAGE = "quay.io/openshift-on-azure/autorest:${AUTOREST_VERSION}"
+AUTOREST_IMAGE = quay.io/openshift-on-azure/autorest:${AUTOREST_VERSION}
 
 ifneq ($(shell uname -s),Darwin)
     export CGO_CFLAGS=-Dgpgme_off_t=off_t
diff --git a/hack/build-client.sh b/hack/build-client.sh
index 4d72cce0d..954af7270 100755
--- a/hack/build-client.sh
+++ b/hack/build-client.sh
@@ -24,7 +24,7 @@ function generate_golang() {
   local FOLDER=$3
 
   # Generating Track 1 SDK. Needs work to migrate to Track 2.
-  sudo docker run \
+  docker run \
     --platform=linux/amd64 \
     --rm \
     -v $PWD/pkg/client:/github.com/Azure/ARO-RP/pkg/client:z \
@@ -39,8 +39,17 @@ function generate_golang() {
     --input-file=/swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/"$FOLDER"/"$API_VERSION"/redhatopenshift.json \
     --output-folder=/github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/"$API_VERSION"/redhatopenshift
 
-  sudo chown -R $(id -un):$(id -gn) pkg/client
-  sed -i -e 's|azure/aro-rp|Azure/ARO-RP|g' pkg/client/services/redhatopenshift/mgmt/"$API_VERSION"/redhatopenshift/models.go pkg/client/services/redhatopenshift/mgmt/"$API_VERSION"/redhatopenshift/redhatopenshiftapi/interfaces.go
+  docker run \
+    --platform=linux/amd64 \
+    --rm \
+    -v $PWD/pkg/client:/github.com/Azure/ARO-RP/pkg/client:z \
+    --entrypoint sed \
+    "${AUTOREST_IMAGE}" \
+    --in-place \
+    --expression='s|azure/aro-rp|Azure/ARO-RP|g' \
+    "/github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/${API_VERSION}/redhatopenshift/models.go" \
+    "/github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/${API_VERSION}/redhatopenshift/redhatopenshiftapi/interfaces.go"
+
   go run ./vendor/golang.org/x/tools/cmd/goimports -w -local=github.com/Azure/ARO-RP pkg/client
 }
 
@@ -50,15 +59,15 @@ function generate_python() {
   local FOLDER=$3
 
   # Generating Track 2 SDK
-  sudo docker run \
+  docker run \
     --platform=linux/amd64 \
     --rm \
     -v $PWD/python/client:/python/client:z \
     -v $PWD/swagger:/swagger:z \
     "${AUTOREST_IMAGE}" \
-    --version=3.6.1 \
     --use=@autorest/python@~5.12.0 \
     --use=@autorest/modelerfour@~4.20.0 \
+    --version=~3.6.2 \
     --python \
     --azure-arm \
     --license-header=MICROSOFT_APACHE_NO_VERSION \
@@ -66,12 +75,13 @@ function generate_python() {
     --input-file=/swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/"$FOLDER"/"$API_VERSION"/redhatopenshift.json \
     --output-folder=/python/client
 
-  sudo chown -R $(id -un):$(id -gn) python/client
   rm -rf python/client/azure/mgmt/redhatopenshift/v"${API_VERSION//-/_}"/aio
   >python/client/__init__.py
 }
 
-rm -f .sha256sum
+if [ -f .sha256sum ]; then
+  rm .sha256sum
+fi
 
 AUTOREST_IMAGE=$1
 


Test patch:
diff --git a/.pipelines/e2e.yml b/.pipelines/e2e.yml
index c1167206b..0a6cb5963 100644
--- a/.pipelines/e2e.yml
+++ b/.pipelines/e2e.yml
@@ -38,7 +38,6 @@ jobs:
       set -o pipefail
 
       . secrets/env
-      export HIVEKUBECONFIGPATH="secrets/e2e-aks-kubeconfig"
 
       az account set -s $AZURE_SUBSCRIPTION_ID
 
diff --git a/test/e2e/adminapi_drainnode.go b/test/e2e/adminapi_drainnode.go
index 8e568fded..7190669ec 100644
--- a/test/e2e/adminapi_drainnode.go
+++ b/test/e2e/adminapi_drainnode.go
@@ -14,6 +14,7 @@ import (
 
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/fields"
 	"k8s.io/kubectl/pkg/drain"
 )
 
@@ -93,11 +94,34 @@ func testUncordonNodeOK(nodeName string) {
 }
 
 func testDrainNodeOK(nodeName string, drainer *drain.Helper) {
+	By("counting the number of pods on the node via Kubernetes API")
+	podsListPreDrain, err := clients.Kubernetes.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
+		FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": nodeName}).String(),
+	})
+	Expect(err).NotTo(HaveOccurred())
+	Expect(len(podsListPreDrain.Items)).Should(BeNumerically(">", 0))
+
+	By("counting the number of pods to be deleted/evicted via Kubernetes API")
+	podsForDeletion, errs := drainer.GetPodsForDeletion(nodeName)
+	Expect(errs).To(BeNil())
+	Expect(len(podsForDeletion.Pods())).Should(BeNumerically(">", 0))
+
 	By("draining the node via RP admin API")
 	params := url.Values{
-		"vmName": []string{nodeName},
+		"shouldCordon": []string{"true"},
+		"vmName":       []string{nodeName},
 	}
 	resp, err := adminRequest(context.Background(), http.MethodPost, "/admin"+resourceIDFromEnv()+"/drainnode", params, nil, nil)
 	Expect(err).NotTo(HaveOccurred())
 	Expect(resp.StatusCode).To(Equal(http.StatusOK))
+
+	By("counting the number of pods on the drained node via Kubernetes API")
+	podsListPostDrain, err := clients.Kubernetes.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
+		FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": nodeName}).String(),
+	})
+	Expect(err).NotTo(HaveOccurred())
+	Expect(len(podsListPostDrain.Items)).Should(BeNumerically(">", 0))
+
+	By("checking that the expected number of pods exist on the drained node")
+	Expect(len(podsListPostDrain.Items)).Should(BeNumerically("<=", len(podsListPreDrain.Items)-len(podsForDeletion.Pods())))
 }