From dbec3990bfcacf14fa18fd6369a6e1d5d15f93b5 Mon Sep 17 00:00:00 2001 From: Yevgeny Shnaidman Date: Tue, 18 Aug 2020 12:11:18 +0300 Subject: [PATCH 1/3] MGMT-1858 - subsystem should use dummy ignition image and not a real one --- Dockerfile.ignition-dummy | 5 ++ Makefile | 23 +++-- dummy-ignition/main.go | 90 ++++++++++++++++++++ pkg/job/job.go | 15 +++- pkg/job/mock_job.go | 3 +- pkg/job/mock_local_job.go | 3 +- pkg/s3wrapper/mock_s3wrapper.go | 3 +- tools/deploy_assisted_installer.py | 1 + tools/deploy_assisted_installer_configmap.py | 6 +- 9 files changed, 134 insertions(+), 15 deletions(-) create mode 100644 Dockerfile.ignition-dummy create mode 100644 dummy-ignition/main.go diff --git a/Dockerfile.ignition-dummy b/Dockerfile.ignition-dummy new file mode 100644 index 00000000000..62f20149a5a --- /dev/null +++ b/Dockerfile.ignition-dummy @@ -0,0 +1,5 @@ +FROM registry.access.redhat.com/ubi8/ubi:latest + +COPY build/dummy-ignition /dummy-ignition +COPY subsystem/test_kubeconfig /kubeconfig-noingress +CMD ["/dummy-ignition"] diff --git a/Makefile b/Makefile index 4b07f99f0c4..0daa7306920 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ endif # TARGET SERVICE := $(or ${SERVICE},quay.io/ocpmetal/assisted-service:latest) ISO_CREATION := $(or ${ISO_CREATION},quay.io/ocpmetal/assisted-iso-create:latest) +DUMMY_IGNITION := $(or ${DUMMY_IGNITION},quay.io/ocpmetal/ignition-dummy:latest) GIT_REVISION := $(shell git rev-parse HEAD) APPLY_NAMESPACE := $(or ${APPLY_NAMESPACE},True) ROUTE53_SECRET := ${ROUTE53_SECRET} @@ -37,8 +38,8 @@ $(BUILD_FOLDER): mkdir -p $(BUILD_FOLDER) format: - goimports -w -l cmd/ internal/ subsystem/ assisted-iso-create/ - gofmt -w -l cmd/ internal/ subsystem/ assisted-iso-create/ + goimports -w -l cmd/ internal/ subsystem/ pkg/ assisted-iso-create/ dummy-ignition/ + gofmt -w -l cmd/ internal/ subsystem/ pkg/ assisted-iso-create/ dummy-ignition/ ############ # Generate # @@ -79,7 +80,7 @@ generate-keys: ################## .PHONY: build -build: lint unit-test build-minimal build-iso-generator generate-keys +build: lint unit-test build-minimal build-iso-generator build-dummy-ignition generate-keys build-minimal: $(BUILD_FOLDER) CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-service cmd/main.go @@ -87,6 +88,9 @@ build-minimal: $(BUILD_FOLDER) build-iso-generator: $(BUILD_FOLDER) CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-iso-create assisted-iso-create/main.go +build-dummy-ignition: $(BUILD_FOLDER) + CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/dummy-ignition dummy-ignition/main.go + build-onprem: build podman build -f Dockerfile.assisted-service-onprem -t ${SERVICE} . @@ -105,10 +109,13 @@ update-minimal: build-minimal GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \ -f Dockerfile.assisted-service . -t $(SERVICE) -update-minikube: build +update-minikube: build build-dummy-ignition-image eval $$(SHELL=$${SHELL:-/bin/sh} minikube -p $(PROFILE) docker-env) && \ GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \ - -f Dockerfile.assisted-service . -t $(SERVICE) + -f Dockerfile.assisted-service . -t $(SERVICE) && docker build --network=host -f Dockerfile.ignition-dummy . -t ${DUMMY_IGNITION} + +build-dummy-ignition-image: build-dummy-ignition + docker build --network=host -f Dockerfile.ignition-dummy . -t ${DUMMY_IGNITION} ########## # Deploy # @@ -149,7 +156,7 @@ deploy-inventory-service-file: deploy-namespace sleep 5; # wait for service to get an address deploy-service-requirements: deploy-namespace deploy-inventory-service-file - python3 ./tools/deploy_assisted_installer_configmap.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --base-dns-domains "$(BASE_DNS_DOMAINS)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" $(DEPLOY_TAG_OPTION) --enable-auth "$(ENABLE_AUTH)" + python3 ./tools/deploy_assisted_installer_configmap.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --base-dns-domains "$(BASE_DNS_DOMAINS)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" $(DEPLOY_TAG_OPTION) --enable-auth "$(ENABLE_AUTH)" $(TEST_FLAGS) deploy-service: deploy-namespace deploy-service-requirements deploy-role python3 ./tools/deploy_assisted_installer.py $(DEPLOY_TAG_OPTION) --namespace "$(NAMESPACE)" --profile "$(PROFILE)" $(TEST_FLAGS) --target "$(TARGET)" @@ -166,7 +173,7 @@ jenkins-deploy-for-subsystem: deploy-test: export SERVICE=minikube-local-registry/assisted-service:minikube-test && export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" \ - && $(MAKE) update-minikube deploy-all + && export DUMMY_IGNITION=minikube-local-registry/ignition-dummy-generator:minikube-test && $(MAKE) update-minikube deploy-all deploy-onprem: podman pod create --name assisted-installer -p 5432,8000,8090,8080 @@ -239,4 +246,4 @@ delete-minikube-profile: minikube delete -p $(PROFILE) delete-all-minikube-profiles: - minikube delete --all \ No newline at end of file + minikube delete --all diff --git a/dummy-ignition/main.go b/dummy-ignition/main.go new file mode 100644 index 00000000000..0c217006806 --- /dev/null +++ b/dummy-ignition/main.go @@ -0,0 +1,90 @@ +package main + +import ( + "context" + "os" + + "github.com/kelseyhightower/envconfig" + "github.com/openshift/assisted-service/pkg/s3wrapper" + "github.com/sirupsen/logrus" +) + +var Options struct { + ClusterID string `envconfig:"CLUSTER_ID"` + S3Config s3wrapper.Config +} + +var dummyFileMap map[string]string = map[string]string{ + "bootstrap.ign": "bootstrap file", + "master.ign": "master file", + "worker.ign": "worker file", + "kubeadmin-password": "kubeadmin-password file", + "kubeconfig-noingress": "kubeconfig-noingress file", + "metadata.json": "metadata file", + "install-config.yaml": "install-config file", +} + +func createDummyFile(name, data string) error { + if name == "kubeconfig-noingress" { + return nil + } + f, err := os.Create(name) + if err != nil { + return err + } + _, err = f.WriteString("data") + f.Close() + return err +} + +func createDummyFiles() error { + for fileName, fileData := range dummyFileMap { + err := createDummyFile(fileName, fileData) + if err != nil { + return err + } + } + return nil +} + +func uploadDummyFiles(s3Client *s3wrapper.S3Client, clusterID string) error { + ctx := context.Background() + for fileName := range dummyFileMap { + err := s3Client.UploadFile(ctx, fileName, clusterID+"/"+fileName) + if err != nil { + return err + } + } + return nil +} + +func main() { + log := logrus.New() + log.SetReportCaller(true) + + log.Println("Starting dummy-ignition") + + err := envconfig.Process("", &Options) + if err != nil { + log.Fatal(err.Error()) + } + + log.Infof("S3 parameters: bucket %s, region %s", Options.S3Config.S3Bucket, Options.S3Config.Region) + + s3Client := s3wrapper.NewS3Client(&Options.S3Config, log) + if s3Client == nil { + log.Fatal("failed to create S3 client, ", err) + } + + err = createDummyFiles() + if err != nil { + log.Fatalf("Failed to create dummy files, err: %s", err) + } + + err = uploadDummyFiles(s3Client, Options.ClusterID) + if err != nil { + log.Fatalf("Failed to upload dummy files, err: %s", err) + } + + log.Println("Dummy ignition finished, Success") +} diff --git a/pkg/job/job.go b/pkg/job/job.go index 588e48a79f8..2172c416794 100644 --- a/pkg/job/job.go +++ b/pkg/job/job.go @@ -64,6 +64,7 @@ type Config struct { ServiceBaseURL string `envconfig:"SERVICE_BASE_URL"` //[TODO] - change the default of Releae image to "", once everyine wll update their environment ReleaseImage string `envconfig:"OPENSHIFT_INSTALL_RELEASE_IMAGE" default:"quay.io/openshift-release-dev/ocp-release@sha256:eab93b4591699a5a4ff50ad3517892653f04fb840127895bb3609b3cc68f98f3"` + SubsystemRun bool `envconfig:"SUBSYSTEM_RUN"` } func New(log logrus.FieldLogger, kube client.Client, cfg Config) *kubeJob { @@ -302,6 +303,10 @@ func (k *kubeJob) GenerateISO(ctx context.Context, cluster common.Cluster, jobNa func (k *kubeJob) createKubeconfigJob(cluster *common.Cluster, jobName string, cfg []byte, encodedDhcpFileContents string) *batch.Job { id := cluster.ID ignitionGeneratorImage := k.Config.IgnitionGenerator + var pullPolicy core.PullPolicy = "Always" + if k.Config.SubsystemRun { + pullPolicy = "Never" + } ret := &batch.Job{ TypeMeta: meta.TypeMeta{ Kind: "Job", @@ -323,7 +328,7 @@ func (k *kubeJob) createKubeconfigJob(cluster *common.Cluster, jobName string, c { Name: ignitionGeneratorPrefix, Image: ignitionGeneratorImage, - ImagePullPolicy: "Always", + ImagePullPolicy: pullPolicy, Env: []core.EnvVar{ { Name: "S3_ENDPOINT_URL", @@ -345,6 +350,10 @@ func (k *kubeJob) createKubeconfigJob(cluster *common.Cluster, jobName string, c Name: "S3_BUCKET", Value: k.Config.S3Bucket, }, + { + Name: "S3_REGION", + Value: k.Config.S3Region, + }, { Name: "CLUSTER_ID", Value: id.String(), @@ -354,11 +363,11 @@ func (k *kubeJob) createKubeconfigJob(cluster *common.Cluster, jobName string, c Value: k.ReleaseImage, //TODO: change this to match the cluster openshift version }, { - Name: "aws_access_key_id", + Name: "AWS_ACCESS_KEY_ID", Value: k.Config.AwsAccessKeyID, }, { - Name: "aws_secret_access_key", + Name: "AWS_SECRET_ACCESS_KEY", Value: k.Config.AwsSecretAccessKey, }, }, diff --git a/pkg/job/mock_job.go b/pkg/job/mock_job.go index b93f23d6a37..a1bfba797c0 100644 --- a/pkg/job/mock_job.go +++ b/pkg/job/mock_job.go @@ -6,11 +6,12 @@ package job import ( context "context" + reflect "reflect" + gomock "github.com/golang/mock/gomock" common "github.com/openshift/assisted-service/internal/common" events "github.com/openshift/assisted-service/internal/events" runtime "k8s.io/apimachinery/pkg/runtime" - reflect "reflect" client "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/pkg/job/mock_local_job.go b/pkg/job/mock_local_job.go index 092e3aab04b..aaa0b8c24d7 100644 --- a/pkg/job/mock_local_job.go +++ b/pkg/job/mock_local_job.go @@ -6,11 +6,12 @@ package job import ( context "context" + reflect "reflect" + gomock "github.com/golang/mock/gomock" common "github.com/openshift/assisted-service/internal/common" events "github.com/openshift/assisted-service/internal/events" logrus "github.com/sirupsen/logrus" - reflect "reflect" ) // MockLocalJob is a mock of LocalJob interface diff --git a/pkg/s3wrapper/mock_s3wrapper.go b/pkg/s3wrapper/mock_s3wrapper.go index d68c263f2df..b442f8f943c 100644 --- a/pkg/s3wrapper/mock_s3wrapper.go +++ b/pkg/s3wrapper/mock_s3wrapper.go @@ -6,10 +6,11 @@ package s3wrapper import ( context "context" - gomock "github.com/golang/mock/gomock" io "io" reflect "reflect" time "time" + + gomock "github.com/golang/mock/gomock" ) // MockAPI is a mock of API interface diff --git a/tools/deploy_assisted_installer.py b/tools/deploy_assisted_installer.py index 5b21545a101..87546b278c2 100644 --- a/tools/deploy_assisted_installer.py +++ b/tools/deploy_assisted_installer.py @@ -46,6 +46,7 @@ def main(): data["spec"]["template"]["spec"]["containers"][0]["env"].append({'name': 'JWKS_CERT', 'value': load_key()}) data["spec"]["template"]["spec"]["containers"][0]["env"].append({'name': 'ENABLE_AUTH_AGENT', 'value': "False"}) data["spec"]["template"]["spec"]["containers"][0]["env"].append({'name': 'ENABLE_AUTHZ', 'value': "False"}) + data["spec"]["template"]["spec"]["containers"][0]["env"].append({'name':'SUBSYSTEM_RUN', 'value': 'True'}) data["spec"]["template"]["spec"]["containers"][0]["imagePullPolicy"] = "Never" else: data["spec"]["template"]["spec"]["containers"][0]["imagePullPolicy"] = "Always" diff --git a/tools/deploy_assisted_installer_configmap.py b/tools/deploy_assisted_installer_configmap.py index 357e2cb477a..5971ac71439 100644 --- a/tools/deploy_assisted_installer_configmap.py +++ b/tools/deploy_assisted_installer_configmap.py @@ -21,6 +21,7 @@ def handle_arguments(): parser = argparse.ArgumentParser() parser.add_argument("--base-dns-domains") parser.add_argument("--enable-auth", default="False") + parser.add_argument("--subsystem-test", action='store_true') parser.add_argument("--jwks-url", default="https://api.openshift.com/.well-known/jwks.json") parser.add_argument("--ocm-url", default="https://api-integration.6943.hive-integration.openshiftapps.com") @@ -50,7 +51,10 @@ def main(): "CONNECTIVITY_CHECK_IMAGE": "assisted-installer-agent", "INVENTORY_IMAGE": "assisted-installer-agent"} for env_var_name, image_short_name in versions.items(): - image_fqdn = deployment_options.get_image_override(deploy_options, image_short_name, env_var_name) + if deploy_options.subsystem_test and env_var_name == "IGNITION_GENERATE_IMAGE": + image_fqdn = deployment_options.get_image_override(deploy_options, image_short_name, "DUMMY_IGNITION") + else: + image_fqdn = deployment_options.get_image_override(deploy_options, image_short_name, env_var_name) versions[env_var_name] = image_fqdn # Edge case for controller image override From f529e07132132a2d341f4c40e25b6e0894edddaa Mon Sep 17 00:00:00 2001 From: Yevgeny Shnaidman Date: Tue, 18 Aug 2020 13:05:23 +0300 Subject: [PATCH 2/3] MGMT-1858 - subsystem should use dummy ignition image and not a real one --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0daa7306920..ee66bfc6f4d 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ generate-keys: ################## .PHONY: build -build: lint unit-test build-minimal build-iso-generator build-dummy-ignition generate-keys +build: lint unit-test build-minimal build-iso-generator generate-keys build-minimal: $(BUILD_FOLDER) CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-service cmd/main.go @@ -109,7 +109,7 @@ update-minimal: build-minimal GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \ -f Dockerfile.assisted-service . -t $(SERVICE) -update-minikube: build build-dummy-ignition-image +update-minikube: build build-dummy-ignition eval $$(SHELL=$${SHELL:-/bin/sh} minikube -p $(PROFILE) docker-env) && \ GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \ -f Dockerfile.assisted-service . -t $(SERVICE) && docker build --network=host -f Dockerfile.ignition-dummy . -t ${DUMMY_IGNITION} @@ -168,8 +168,8 @@ deploy-role: deploy-namespace deploy-postgres: deploy-namespace python3 ./tools/deploy_postgres.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)" -jenkins-deploy-for-subsystem: - export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" && $(MAKE) deploy-all +jenkins-deploy-for-subsystem: build-dummy-ignition-image + export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" && export DUMMY_IGNITION=${DUMMY_IGNITION} && $(MAKE) deploy-all deploy-test: export SERVICE=minikube-local-registry/assisted-service:minikube-test && export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" \ From d34ca91f701c89bd9ed01eb530135d75663c9ee0 Mon Sep 17 00:00:00 2001 From: Yevgeny Shnaidman Date: Tue, 18 Aug 2020 14:29:38 +0300 Subject: [PATCH 3/3] MGMT-1858 - subsystem should use dummy ignition image and not a real one --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ee66bfc6f4d..bd563320075 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ endif # TARGET SERVICE := $(or ${SERVICE},quay.io/ocpmetal/assisted-service:latest) ISO_CREATION := $(or ${ISO_CREATION},quay.io/ocpmetal/assisted-iso-create:latest) -DUMMY_IGNITION := $(or ${DUMMY_IGNITION},quay.io/ocpmetal/ignition-dummy:latest) +DUMMY_IGNITION := $(or ${DUMMY_IGNITION},minikube-local-registry/ignition-dummy-generator:minikube-test) GIT_REVISION := $(shell git rev-parse HEAD) APPLY_NAMESPACE := $(or ${APPLY_NAMESPACE},True) ROUTE53_SECRET := ${ROUTE53_SECRET} @@ -173,7 +173,7 @@ jenkins-deploy-for-subsystem: build-dummy-ignition-image deploy-test: export SERVICE=minikube-local-registry/assisted-service:minikube-test && export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" \ - && export DUMMY_IGNITION=minikube-local-registry/ignition-dummy-generator:minikube-test && $(MAKE) update-minikube deploy-all + && export DUMMY_IGNITION=${DUMMY_IGNITION} && $(MAKE) update-minikube deploy-all deploy-onprem: podman pod create --name assisted-installer -p 5432,8000,8090,8080