Skip to content

feat(images): showing why cannot delete #859

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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
7 changes: 4 additions & 3 deletions api/core/v1alpha2/cluster_virtual_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ type ClusterVirtualImageStatus struct {
// Resource generation last processed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Deprecated. Use `imageUploadURLs` instead.
UploadCommand string `json:"uploadCommand,omitempty"`
ImageUploadURLs *ImageUploadURLs `json:"imageUploadURLs,omitempty"`
Target ClusterVirtualImageStatusTarget `json:"target,omitempty"`
UploadCommand string `json:"uploadCommand,omitempty"`
ImageUploadURLs *ImageUploadURLs `json:"imageUploadURLs,omitempty"`
Target ClusterVirtualImageStatusTarget `json:"target,omitempty"`
UsedInNamespaces []string `json:"usedInNamespaces,omitempty"`
}

type ClusterVirtualImageStatusTarget struct {
Expand Down
10 changes: 10 additions & 0 deletions api/core/v1alpha2/cvicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ const (
DatasourceReadyType Type = "DatasourceReady"
// ReadyType indicates whether the import process succeeded and the `ClusterVirtualImage` is ready for use.
ReadyType Type = "Ready"
// InUse indicates that the `ClusterVirtualImage` is used by other resources and cannot be deleted now.
InUseType Type = "InUse"
)

type (
// DatasourceReadyReason represents the various reasons for the DatasourceReady condition type.
DatasourceReadyReason string
// ReadyReason represents the various reasons for the Ready condition type.
ReadyReason string
// InUseReason represents the various reasons for the InUseType condition type.
InUseReason string
)

func (s DatasourceReadyReason) String() string {
Expand All @@ -45,6 +49,10 @@ func (s ReadyReason) String() string {
return string(s)
}

func (s InUseReason) String() string {
return string(s)
}

const (
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
Expand Down Expand Up @@ -73,4 +81,6 @@ const (
ProvisioningFailed ReadyReason = "ProvisioningFailed"
// Ready indicates that the import process is complete and the `ClusterVirtualImage` is ready for use.
Ready ReadyReason = "Ready"
// InUse indicates that the `ClusterVirtualImage` is used by other resources and cannot be deleted now.
InUse InUseReason = "InUse"
)
12 changes: 11 additions & 1 deletion api/core/v1alpha2/vicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ const (
DatasourceReadyType Type = "DatasourceReady"
// ReadyType indicates whether the import process succeeded and the `VirtualImage` is ready for use.
ReadyType Type = "Ready"
// StorageClassReadyType indicates whether the storageClass ready
// StorageClassReadyType indicates whether the storageClass ready.
StorageClassReadyType Type = "StorageClassReady"
// InUse indicates that the `VirtualImage` is used by other resources and cannot be deleted now.
InUseType Type = "InUse"
)

type (
Expand All @@ -39,6 +41,8 @@ type (
ReadyReason string
// StorageClassReadyReason represents the various reasons for the StorageClassReady condition type.
StorageClassReadyReason string
// InUseReason represents the various reasons for the InUseType condition type.
InUseReason string
)

func (s DatasourceReadyReason) String() string {
Expand All @@ -53,6 +57,10 @@ func (s StorageClassReadyReason) String() string {
return string(s)
}

func (s InUseReason) String() string {
return string(s)
}

const (
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
Expand Down Expand Up @@ -99,4 +107,6 @@ const (
StorageClassNotFound StorageClassReadyReason = "StorageClassNotFound"
// DVCRTypeUsed indicates that the DVCR provisioning chosen.
DVCRTypeUsed StorageClassReadyReason = "DVCRTypeUsed"
// InUse indicates that the `VirtualImage` is used by other resources and cannot be deleted now.
InUse InUseReason = "InUse"
)
5 changes: 5 additions & 0 deletions api/core/v1alpha2/zz_generated.deepcopy.go

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

14 changes: 14 additions & 0 deletions api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

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

6 changes: 6 additions & 0 deletions crds/clustervirtualimages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ spec:
uploadCommand:
description: Deprecated. Use `imageUploadURLs` instead.
type: string
usedInNamespaces:
description: |
Displays the list of namespaces where the image is currently used when attempting to delete it.
items:
type: string
type: array
type: object
required:
- spec
Expand Down
3 changes: 3 additions & 0 deletions crds/doc-ru-clustervirtualimages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ spec:
uploadCommand:
description: |
Устаревшее поле. Используйте `imageUploadURLs`.
usedInNamespaces:
description: |
Список пространств имён, в которых используется образ, отображается при его удалении.
imageUploadURLs:
properties:
external:
Expand Down
50 changes: 50 additions & 0 deletions images/virtualization-artifact/pkg/builder/cvi/cvi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cvi

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

func New(options ...Option) *v1alpha2.ClusterVirtualImage {
cvi := NewEmpty("")
ApplyOptions(cvi, options)
return cvi
}

func ApplyOptions(cvi *v1alpha2.ClusterVirtualImage, opts []Option) {
if cvi == nil {
return
}
for _, opt := range opts {
opt(cvi)
}
}

func NewEmpty(name string) *v1alpha2.ClusterVirtualImage {
return &v1alpha2.ClusterVirtualImage{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.ClusterVirtualImageKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
}
51 changes: 51 additions & 0 deletions images/virtualization-artifact/pkg/builder/cvi/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cvi

import (
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
"github.com/deckhouse/virtualization/api/core/v1alpha2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Option func(cvi *v1alpha2.ClusterVirtualImage)

var (
WithName = meta.WithName[*v1alpha2.ClusterVirtualImage]
WithLabel = meta.WithLabel[*v1alpha2.ClusterVirtualImage]
WithLabels = meta.WithLabels[*v1alpha2.ClusterVirtualImage]
WithAnnotation = meta.WithAnnotation[*v1alpha2.ClusterVirtualImage]
WithAnnotations = meta.WithAnnotations[*v1alpha2.ClusterVirtualImage]
)

func WithDatasource(datasource v1alpha2.ClusterVirtualImageDataSource) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = datasource
}
}

func WithPhase(phase v1alpha2.ImagePhase) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Status.Phase = phase
}
}

func WithCondition(condition metav1.Condition) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Status.Conditions = append(cvi.Status.Conditions, condition)
}
}
39 changes: 39 additions & 0 deletions images/virtualization-artifact/pkg/builder/vd/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vd

import (
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

type Option func(vd *v1alpha2.VirtualDisk)

var (
WithName = meta.WithName[*v1alpha2.VirtualDisk]
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualDisk]
WithLabel = meta.WithLabel[*v1alpha2.VirtualDisk]
WithLabels = meta.WithLabels[*v1alpha2.VirtualDisk]
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualDisk]
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualDisk]
)

func WithDatasource(datasource *v1alpha2.VirtualDiskDataSource) func(vd *v1alpha2.VirtualDisk) {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = datasource
}
}
51 changes: 51 additions & 0 deletions images/virtualization-artifact/pkg/builder/vd/vd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vd

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

func New(options ...Option) *v1alpha2.VirtualDisk {
vd := NewEmpty("", "")
ApplyOptions(vd, options)
return vd
}

func ApplyOptions(vd *v1alpha2.VirtualDisk, opts []Option) {
if vd == nil {
return
}
for _, opt := range opts {
opt(vd)
}
}

func NewEmpty(name, namespace string) *v1alpha2.VirtualDisk {
return &v1alpha2.VirtualDisk{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.VirtualDiskKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
}
39 changes: 39 additions & 0 deletions images/virtualization-artifact/pkg/builder/vi/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vi

import (
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

type Option func(vi *v1alpha2.VirtualImage)

var (
WithName = meta.WithName[*v1alpha2.VirtualImage]
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualImage]
WithLabel = meta.WithLabel[*v1alpha2.VirtualImage]
WithLabels = meta.WithLabels[*v1alpha2.VirtualImage]
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualImage]
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualImage]
)

func WithDatasource(datasource v1alpha2.VirtualImageDataSource) func(vi *v1alpha2.VirtualImage) {
return func(vi *v1alpha2.VirtualImage) {
vi.Spec.DataSource = datasource
}
}
Loading
Loading