Repository: Azure/ARO-RP
Pull request #1702 (2021-08-26 14:24:47)

Ensure build tag "aro" is present
### Which issue this PR addresses:

Fixes https://msazure.visualstudio.com/AzureRedHatOpenShift/_workitems/edit/9778719/

### What this PR does / why we need it:

ARO-RP must be built with `-tags aro` which will filter down to the vendor directory and disable certain functionality from the openshift/installer. 

This PR is trying to block ARO-RP from being built/tested/run without the required tag.
 
### Test plan for issue:

The code should automatically fail unit tests and execution tests if executed without `-tags aro`.

### Is there any documentation that needs to be updated for this PR?

Development docs may need updating.

drewandersonnz: Reason for the `ensureagotag.go` and `ensurearotagconst.go`, these files are temporary, and used as a proxy to fake the expected structure once the `openshift/installer@release-4.9-azure` is available. 

Discussions with @m1kola lead us down this path due to the release cycle requirements of `openshift/installer`.
drewandersonnz: /azp run ci
azure-pipelines[bot]: <samp>
Azure Pipelines successfully started running 1 pipeline(s).<br>

</samp>
m1kola: @rogbas could you or/and someone who will be working on 4.9 vendoring review this? It will be required for 4.9 installer for to work properly.
troy0820: @rogbas @m1kola 4.9 vendoring is supposed to be done by @mbarnes. 
troy0820: Upon approval, could you squash these commits @drewandersonnz to help with the git history. 
rogbas: @drewandersonnz 
Overall the changes are looking good. Shouldn't we also update the following docs adding `-tags aro` to whenever we do `go run ./cmd/aro rp`?

- docs/deploy-development-rp.md
- docs/deploy-full-rp-service-in-dev.md
- docs/deploy-upgrade-rp.md

drewandersonnz: fixed the nit, docs updated, squashed, all as requested. 

Patch:
diff --git a/Makefile b/Makefile
index b2f2ee2f6..70344d802 100644
--- a/Makefile
+++ b/Makefile
@@ -12,10 +12,13 @@ ifneq ($(shell uname -s),Darwin)
 endif
 
 build-all:
-	go build -tags containers_image_openpgp ./...
+	go build -tags aro,containers_image_openpgp ./...
 
 aro: generate
-	go build -tags containers_image_openpgp,codec.safe -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=$(COMMIT)" ./cmd/aro
+	go build -tags aro,containers_image_openpgp,codec.safe -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=$(COMMIT)" ./cmd/aro
+
+runlocal-rp:
+	go run -tags aro ./cmd/aro rp
 
 az: pyenv
 	. pyenv/bin/activate && \
@@ -143,7 +146,7 @@ validate-go:
 	go test -tags e2e -run ^$$ ./test/e2e/...
 
 unit-test-go:
-	go run ./vendor/gotest.tools/gotestsum/main.go --format pkgname --junitfile report.xml -- -coverprofile=cover.out ./...
+	go run ./vendor/gotest.tools/gotestsum/main.go --format pkgname --junitfile report.xml -- -tags=aro -coverprofile=cover.out ./...
 
 lint-go:
 	go run ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint run
@@ -161,4 +164,4 @@ vendor:
 	# See comments in the script for background on why we need it
 	hack/update-go-module-dependencies.sh
 
-.PHONY: admin.kubeconfig aro az clean client deploy dev-config.yaml discoverycache generate image-aro image-aro-multistage image-fluentbit image-proxy lint-go proxy publish-image-aro publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go  unit-test-go coverage-go
+.PHONY: admin.kubeconfig aro az clean client deploy dev-config.yaml discoverycache generate image-aro image-aro-multistage image-fluentbit image-proxy lint-go runlocal-rp proxy publish-image-aro publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go  unit-test-go coverage-go
diff --git a/cmd/aro/ensurebuildtag.go b/cmd/aro/ensurebuildtag.go
new file mode 100644
index 000000000..265710d09
--- /dev/null
+++ b/cmd/aro/ensurebuildtag.go
@@ -0,0 +1,6 @@
+package main
+
+// Copyright (c) Microsoft Corporation.
+// Licensed under the Apache License 2.0.
+
+var platformIsAro bool
diff --git a/cmd/aro/ensurebuildtag_aro.go b/cmd/aro/ensurebuildtag_aro.go
new file mode 100644
index 000000000..584d85f95
--- /dev/null
+++ b/cmd/aro/ensurebuildtag_aro.go
@@ -0,0 +1,10 @@
+// +build aro
+
+package main
+
+// Copyright (c) Microsoft Corporation.
+// Licensed under the Apache License 2.0.
+
+func init() {
+	platformIsAro = true
+}
diff --git a/cmd/aro/main.go b/cmd/aro/main.go
index 57e6b28f7..1fc73b251 100644
--- a/cmd/aro/main.go
+++ b/cmd/aro/main.go
@@ -42,6 +42,11 @@ func main() {
 	audit := utillog.GetAuditEntry()
 	log := utillog.GetLogger()
 
+	// TODO: Use `azuretypes.Platform.IsARO()` from github.com/openshift/installer/pkg/types/azure
+	if !platformIsAro {
+		log.Fatal("ARO-RP must be built, run, and tested with '-tags aro' to support github.com/openshift/installer, see https://github.com/openshift/installer/pull/4843/files")
+	}
+
 	go func() {
 		log.Warn(http.ListenAndServe("localhost:6060", nil))
 	}()
diff --git a/docs/deploy-development-rp.md b/docs/deploy-development-rp.md
index f02a9d558..f3de4ce9c 100644
--- a/docs/deploy-development-rp.md
+++ b/docs/deploy-development-rp.md
@@ -88,7 +88,7 @@
 1. Run the RP
 
    ```bash
-   go run ./cmd/aro rp
+   make runlocal-rp
    ```
 
 1. To create a cluster, EITHER follow the instructions in [Create, access, and


Test patch:
diff --git a/cmd/aro/ensurebuildtag_test.go b/cmd/aro/ensurebuildtag_test.go
new file mode 100644
index 000000000..39b1141bc
--- /dev/null
+++ b/cmd/aro/ensurebuildtag_test.go
@@ -0,0 +1,21 @@
+package main
+
+// Copyright (c) Microsoft Corporation.
+// Licensed under the Apache License 2.0.
+
+import (
+	"testing"
+)
+
+func TestEnsureAroTag(t *testing.T) {
+	/*
+		This file should always fail this test when "+build !aro".
+		The 'aro' tag is required for the openshift/installer to disable certain
+		functionality which are valid for OpenShift on Azure, but not valid for ARO deployments.
+		Related: https://github.com/openshift/installer/pull/4843
+	*/
+	// TODO: Use `azuretypes.Platform.IsARO()` from github.com/openshift/installer/pkg/types/azure
+	if !platformIsAro {
+		t.Fatalf("ARO-RP must be built, run, and tested with '-tags aro' to support github.com/openshift/installer, see https://github.com/openshift/installer/pull/4843/files")
+	}
+}