Skip to content

Commit

Permalink
Set ImageContent.Download as required
Browse files Browse the repository at this point in the history
Fixes: #261
  • Loading branch information
itzikb-redhat committed Feb 25, 2025
1 parent bb636ca commit fc29baf
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ type ImageContent struct {

// download describes how to obtain image data by downloading it from a URL.
// Must be set when creating a managed image.
// +optional
Download *ImageContentSourceDownload `json:"download,omitempty"`
// +required
Download *ImageContentSourceDownload `json:"download"`
}

type ImageContentSourceDownload struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/models-schema/zz_generated.openapi.go

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

1 change: 1 addition & 0 deletions config/crd/bases/openstack.k-orc.cloud_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ spec:
type: object
required:
- diskFormat
- download
type: object
x-kubernetes-validations:
- message: content is immutable
Expand Down
5 changes: 0 additions & 5 deletions internal/controllers/image/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func (r *orcImageReconciler) uploadImageContent(ctx context.Context, orcImage *o
}

download := content.Download
if download == nil {
// Should have been caught by validation
return orcerrors.Terminal(orcv1alpha1.ConditionReasonInvalidConfiguration, "image source type URL has no url entry")
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, download.URL, http.NoBody)
if err != nil {
return fmt.Errorf("error creating request for %s: %w", download.URL, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/image/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var _ = Describe("Upload tests", Ordered, func() {
Content: &orcv1alpha1.ImageContent{
ContainerFormat: orcv1alpha1.ImageContainerFormatBare,
DiskFormat: orcv1alpha1.ImageDiskFormatRaw,
Download: &orcv1alpha1.ImageContentSourceDownload{
Download: orcv1alpha1.ImageContentSourceDownload{

Check failure on line 194 in internal/controllers/image/upload_test.go

View workflow job for this annotation

GitHub Actions / go-lint

cannot use orcv1alpha1.ImageContentSourceDownload{…} (value of type "github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload) as *"github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload value in struct literal (typecheck)

Check failure on line 194 in internal/controllers/image/upload_test.go

View workflow job for this annotation

GitHub Actions / unit (1)

cannot use orcv1alpha1.ImageContentSourceDownload{…} (value of type "github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload) as *"github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload value in struct literal
URL: "http://" + fileServeAddr + "/" + imageName,
Decompress: opts.compression,
Hash: opts.downloadHash,
Expand Down
5 changes: 0 additions & 5 deletions internal/controllers/image/webdownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func (r *orcImageReconciler) canWebDownload(ctx context.Context, orcImage *orcv1
}

download := content.Download
if download == nil {
debugLog("not type URL")
return false, nil
}

// web-download does not deterministically support decompression.
// Glance can be configured to do automatic decompression of imported
// images, but there's no way to determine if it is enabled so it can't
Expand Down
2 changes: 1 addition & 1 deletion test/apivalidations/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var _ = Describe("ORC Image API validations", func() {
image.Spec.Resource = &orcv1alpha1.ImageResourceSpec{
Content: &orcv1alpha1.ImageContent{
DiskFormat: orcv1alpha1.ImageDiskFormatQCOW2,
Download: &orcv1alpha1.ImageContentSourceDownload{
Download: orcv1alpha1.ImageContentSourceDownload{

Check failure on line 121 in test/apivalidations/image_test.go

View workflow job for this annotation

GitHub Actions / go-lint

cannot use orcv1alpha1.ImageContentSourceDownload{…} (value of type "github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload) as *"github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload value in struct literal (typecheck)

Check failure on line 121 in test/apivalidations/image_test.go

View workflow job for this annotation

GitHub Actions / unit (1)

cannot use orcv1alpha1.ImageContentSourceDownload{…} (value of type "github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload) as *"github.com/k-orc/openstack-resource-controller/api/v1alpha1".ImageContentSourceDownload value in struct literal
URL: "https://example.com/example.img",
},
},
Expand Down

0 comments on commit fc29baf

Please sign in to comment.