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

MGMT-1858 - subsystem should use dummy ignition image and not a real one #154

Merged
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
5 changes: 5 additions & 0 deletions Dockerfile.ignition-dummy
Original file line number Diff line number Diff line change
@@ -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"]
25 changes: 16 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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},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}
Expand All @@ -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 #
Expand Down Expand Up @@ -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} .

Expand All @@ -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
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 #
Expand Down Expand Up @@ -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)"
Expand All @@ -161,12 +168,12 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

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

export DUMMY_IGNITION=minikube-local-registry/ignition-dummy-generator:minikube-test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ronniel1 kubernetes will still treat it as external and will try to connect


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=${DUMMY_IGNITION} && $(MAKE) update-minikube deploy-all

deploy-onprem:
podman pod create --name assisted-installer -p 5432,8000,8090,8080
Expand Down Expand Up @@ -239,4 +246,4 @@ delete-minikube-profile:
minikube delete -p $(PROFILE)

delete-all-minikube-profiles:
minikube delete --all
minikube delete --all
90 changes: 90 additions & 0 deletions dummy-ignition/main.go
Original file line number Diff line number Diff line change
@@ -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")
}
15 changes: 12 additions & 3 deletions pkg/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not making the policy as a flag?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have the always flag?
Since (see my comment on the default name of the image) will never be in external repo, always should work, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ronniel1 always flag means that kuberenetes will try to pull the image from external repo every time, that's why we need to set never on subsystem

Copy link
Contributor

Choose a reason for hiding this comment

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

but in this case there will not be an external repo

pullPolicy = "Never"
}
ret := &batch.Job{
TypeMeta: meta.TypeMeta{
Kind: "Job",
Expand All @@ -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",
Expand All @@ -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(),
Expand All @@ -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,
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/job/mock_job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/job/mock_local_job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/s3wrapper/mock_s3wrapper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/deploy_assisted_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion tools/deploy_assisted_installer_configmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down