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-15405: Add a URL to infraenv to show download link from static network config #5638

Merged
merged 1 commit into from
Nov 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1beta1/infraenv_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ type InfraEnvDebugInfo struct {
// EventsURL specifies an HTTP/S URL that contains InfraEnv events
// +optional
EventsURL string `json:"eventsURL"`
// StaticNetworkDownloadURL specifies an HTTP/S URL that contains the static network config
StaticNetworkDownloadURL string `json:"staticNetworkDownloadURL,omitempty"`
}

type BootArtifacts struct {
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/agent-install.openshift.io_infraenvs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ spec:
description: EventsURL specifies an HTTP/S URL that contains InfraEnv
events
type: string
staticNetworkDownloadURL:
description: StaticNetworkDownloadURL specifies an HTTP/S URL
that contains the static network config
type: string
type: object
isoDownloadURL:
description: ISODownloadURL specifies an HTTP/S URL that contains
Expand Down
4 changes: 4 additions & 0 deletions config/crd/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,10 @@ spec:
description: EventsURL specifies an HTTP/S URL that contains InfraEnv
events
type: string
staticNetworkDownloadURL:
description: StaticNetworkDownloadURL specifies an HTTP/S URL
that contains the static network config
type: string
type: object
isoDownloadURL:
description: ISODownloadURL specifies an HTTP/S URL that contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ spec:
description: EventsURL specifies an HTTP/S URL that contains InfraEnv
events
type: string
staticNetworkDownloadURL:
description: StaticNetworkDownloadURL specifies an HTTP/S URL
that contains the static network config
type: string
type: object
isoDownloadURL:
description: ISODownloadURL specifies an HTTP/S URL that contains
Expand Down
30 changes: 30 additions & 0 deletions internal/controller/controllers/infraenv_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,29 @@ func (r *InfraEnvReconciler) initrdSchemeChanged(initrdURL string) (bool, error)
return u.Scheme != desiredScheme, nil
}

func generateStaticNetworkConfigDownloadURL(baseURL string, infraEnvId string, authType auth.AuthType) (string, error) {
builder := &installer.V2DownloadInfraEnvFilesURL{
InfraEnvID: strfmt.UUID(infraEnvId),
FileName: "static-network-config",
}
u, err := builder.Build()
if err != nil {
return "", err
}

downloadURL := fmt.Sprintf("%s%s", baseURL, u.RequestURI())
if authType != auth.TypeLocal {
return downloadURL, nil
}

downloadURL, err = gencrypto.SignURL(downloadURL, infraEnvId, gencrypto.ClusterKey)
if err != nil {
return "", errors.Wrapf(err, "failed to sign static network config download URL for infraenv %s", infraEnvId)
}

return downloadURL, nil
}

func (r *InfraEnvReconciler) updateInfraEnvStatus(
ctx context.Context, log logrus.FieldLogger, infraEnv *aiv1beta1.InfraEnv, internalInfraEnv *common.InfraEnv) (ctrl.Result, error) {

Expand All @@ -660,6 +683,13 @@ func (r *InfraEnvReconciler) updateInfraEnvStatus(
isoUpdated = true
}

if infraEnv.Status.InfraEnvDebugInfo.StaticNetworkDownloadURL == "" && internalInfraEnv.StaticNetworkConfig != "" {
infraEnv.Status.InfraEnvDebugInfo.StaticNetworkDownloadURL, err = generateStaticNetworkConfigDownloadURL(r.ServiceBaseURL, internalInfraEnv.ID.String(), r.AuthType)
if err != nil {
r.Log.Errorf("Unable to generate static network config download URL for infraenv with ID %s", internalInfraEnv.ID.String())
}
}

// update boot artifacts URL if IPXE insecure setting was changed or if the ISO was updated
schemeUpdated, err := r.initrdSchemeChanged(infraEnv.Status.BootArtifacts.InitrdURL)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/controllers/infraenv_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var _ = Describe("infraEnv reconcile", func() {
Expect(params.InfraEnvID).To(Equal(*backendInfraEnv.ID))
Expect(params.InfraEnvUpdateParams.ImageType).To(Equal(models.ImageTypeMinimalIso))
}).Return(
&common.InfraEnv{InfraEnv: models.InfraEnv{ClusterID: sId, ID: &sId, DownloadURL: downloadURL, CPUArchitecture: infraEnvArch}, GeneratedAt: strfmt.DateTime(time.Now())}, nil).Times(1)
&common.InfraEnv{InfraEnv: models.InfraEnv{ClusterID: sId, ID: &sId, DownloadURL: downloadURL, CPUArchitecture: infraEnvArch, StaticNetworkConfig: "foobar"}, GeneratedAt: strfmt.DateTime(time.Now())}, nil).Times(1)
infraEnvImage := newInfraEnvImage("infraEnvImage", testNamespace, aiv1beta1.InfraEnvSpec{
ClusterRef: &aiv1beta1.ClusterReference{Name: "clusterDeployment", Namespace: testNamespace},
PullSecretRef: &corev1.LocalObjectReference{Name: "pull-secret"},
Expand All @@ -165,6 +165,7 @@ var _ = Describe("infraEnv reconcile", func() {
}
Expect(c.Get(ctx, key, infraEnvImage)).To(BeNil())
Expect(infraEnvImage.Status.ISODownloadURL).To(Equal(imageInfo.DownloadURL))
Expect(infraEnvImage.Status.InfraEnvDebugInfo.StaticNetworkDownloadURL).To(Equal(fmt.Sprintf("https://www.acme.com/api/assisted-install/v2/infra-envs/%s/downloads/files?file_name=static-network-config", &sId)))
Expect(infraEnvImage.Status.CreatedTime).ToNot(BeNil())
Expect(conditionsv1.FindStatusCondition(infraEnvImage.Status.Conditions, aiv1beta1.ImageCreatedCondition).Message).To(Equal(aiv1beta1.ImageStateCreated))
Expect(conditionsv1.FindStatusCondition(infraEnvImage.Status.Conditions, aiv1beta1.ImageCreatedCondition).Reason).To(Equal(aiv1beta1.ImageCreatedReason))
Expand Down

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