-
Notifications
You must be signed in to change notification settings - Fork 34
Add imageRef to volume controller #633
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| # Example of creating a bootable volume from an image. | ||
| # The volume can then be used as a boot device for a server. | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Image | ||
| metadata: | ||
| name: ubuntu-2404 | ||
| spec: | ||
| cloudCredentialsRef: | ||
| cloudName: openstack | ||
| secretName: openstack-clouds | ||
| import: | ||
| filter: | ||
| name: ubuntu-24.04-server | ||
| --- | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Volume | ||
| metadata: | ||
| name: bootable-volume-sample | ||
| spec: | ||
| cloudCredentialsRef: | ||
| cloudName: openstack | ||
| secretName: openstack-clouds | ||
| managementPolicy: managed | ||
| resource: | ||
| description: Bootable volume created from Ubuntu image | ||
| size: 50 | ||
| imageRef: ubuntu-2404 | ||
| volumeTypeRef: fast-ssd |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,18 @@ var volumetypeDependency = dependency.NewDeletionGuardDependency[*orcv1alpha1.Vo | |
| finalizer, externalObjectFieldOwner, | ||
| ) | ||
|
|
||
| var imageDependency = dependency.NewDeletionGuardDependency[*orcv1alpha1.VolumeList, *orcv1alpha1.Image]( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most likely we don't want it to be a deletion guard because I expect that OpenStack allows us to delete an image after a volume was created from it (to be verified). See how we did for the server's dependency on flavor. |
||
| "spec.resource.imageRef", | ||
| func(volume *orcv1alpha1.Volume) []string { | ||
| resource := volume.Spec.Resource | ||
| if resource == nil || resource.ImageRef == nil { | ||
| return nil | ||
| } | ||
| return []string{string(*resource.ImageRef)} | ||
| }, | ||
| finalizer, externalObjectFieldOwner, | ||
| ) | ||
|
|
||
| // serverToVolumeMapFunc creates a mapping function that reconciles volumes when: | ||
| // - a volume ID appears in server status but the volume doesn't have attachment info for that server | ||
| // - a volume has attachment info for a server, but the server no longer lists that volume | ||
|
|
@@ -209,18 +221,27 @@ func (c volumeReconcilerConstructor) SetupWithManager(ctx context.Context, mgr c | |
| return err | ||
| } | ||
|
|
||
| imageWatchEventHandler, err := imageDependency.WatchEventHandler(log, k8sClient) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| builder := ctrl.NewControllerManagedBy(mgr). | ||
| WithOptions(options). | ||
| Watches(&orcv1alpha1.VolumeType{}, volumetypeWatchEventHandler, | ||
| builder.WithPredicates(predicates.NewBecameAvailable(log, &orcv1alpha1.VolumeType{})), | ||
| ). | ||
| Watches(&orcv1alpha1.Image{}, imageWatchEventHandler, | ||
| builder.WithPredicates(predicates.NewBecameAvailable(log, &orcv1alpha1.Image{})), | ||
| ). | ||
| Watches(&orcv1alpha1.Server{}, handler.EnqueueRequestsFromMapFunc(serverToVolumeMapFunc(ctx, k8sClient)), | ||
| builder.WithPredicates(predicates.NewServerVolumesChanged(log)), | ||
| ). | ||
| For(&orcv1alpha1.Volume{}) | ||
|
|
||
| if err := errors.Join( | ||
| volumetypeDependency.AddToManager(ctx, mgr), | ||
| imageDependency.AddToManager(ctx, mgr), | ||
| credentialsDependency.AddToManager(ctx, mgr), | ||
| credentials.AddCredentialsWatch(log, mgr.GetClient(), builder, credentialsDependency), | ||
| ); err != nil { | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this test is not necessary because we're already checking the creation of a bootable volume in the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Image | ||
| metadata: | ||
| name: volume-create-bootable-image | ||
| status: | ||
| resource: | ||
| status: active | ||
| --- | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Volume | ||
| metadata: | ||
| name: volume-create-bootable | ||
| status: | ||
| resource: | ||
| name: volume-create-bootable | ||
| size: 1 | ||
| status: available | ||
| bootable: true | ||
| encrypted: false | ||
| multiattach: false | ||
| conditions: | ||
| - type: Available | ||
| status: "True" | ||
| reason: Success | ||
| - type: Progressing | ||
| status: "False" | ||
| reason: Success | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| resourceRefs: | ||
| - apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Volume | ||
| name: volume-create-bootable | ||
| ref: volume | ||
| - apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Image | ||
| name: volume-create-bootable-image | ||
| ref: image | ||
| assertAll: | ||
| - celExpr: "volume.status.id != ''" | ||
| - celExpr: "volume.status.resource.tenantID != ''" | ||
| - celExpr: "volume.status.resource.userID != ''" | ||
| - celExpr: "volume.status.resource.volumeType != ''" | ||
| - celExpr: "volume.status.resource.createdAt != ''" | ||
| - celExpr: "volume.status.resource.updatedAt != ''" | ||
| - celExpr: "volume.status.resource.imageID == image.status.id" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Image | ||
| metadata: | ||
| name: volume-create-bootable-image | ||
| spec: | ||
| cloudCredentialsRef: | ||
| cloudName: openstack | ||
| secretName: openstack-clouds | ||
| managementPolicy: managed | ||
| resource: | ||
| content: | ||
| diskFormat: raw | ||
| download: | ||
| url: https://github.com/k-orc/openstack-resource-controller/raw/690b760f49dfb61b173755e91cb51ed42472c7f3/internal/controllers/image/testdata/raw.img | ||
| --- | ||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Volume | ||
| metadata: | ||
| name: volume-create-bootable | ||
| spec: | ||
| cloudCredentialsRef: | ||
| cloudName: openstack | ||
| secretName: openstack-clouds | ||
| managementPolicy: managed | ||
| resource: | ||
| size: 1 | ||
| imageRef: volume-create-bootable-image |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - command: kubectl create secret generic openstack-clouds --from-file=clouds.yaml=${E2E_KUTTL_OSCLOUDS} ${E2E_KUTTL_CACERT_OPT} | ||
| namespaced: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,16 @@ spec: | |
| managementPolicy: managed | ||
| resource: | ||
| size: 1 | ||
| --- | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should then proceed to create the missing image, and check that the volume was created successfully. We should also check that we can delete the image the volume was created from (assuming it works like server and flavors), to ensure we don't add an unnecessary finalizer. |
||
| apiVersion: openstack.k-orc.cloud/v1alpha1 | ||
| kind: Volume | ||
| metadata: | ||
| name: volume-dependency-no-image | ||
| spec: | ||
| cloudCredentialsRef: | ||
| cloudName: openstack | ||
| secretName: openstack-clouds | ||
| managementPolicy: managed | ||
| resource: | ||
| size: 1 | ||
| imageRef: volume-dependency-missing-image | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will not be in the release artifacts because it's not referenced from the
kustomization.yaml. If you want to document a bootable volume, you should add this example toopenstack_v1alpha1_volume.yaml.