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

Fix checkup inconsistencies #42

Merged
merged 5 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 13 additions & 3 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type kubeVirtStorageClient interface {
ListDataImportCrons(ctx context.Context, namespace string) (*cdiv1.DataImportCronList, error)
ListVirtualMachinesInstances(ctx context.Context, namespace string) (*kvcorev1.VirtualMachineInstanceList, error)
ListCDIs(ctx context.Context) (*cdiv1.CDIList, error)
GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error)
GetPersistentVolumeClaim(ctx context.Context, namespace, name string) (*corev1.PersistentVolumeClaim, error)
GetPersistentVolume(ctx context.Context, name string) (*corev1.PersistentVolume, error)
GetVolumeSnapshot(ctx context.Context, namespace, name string) (*snapshotv1.VolumeSnapshot, error)
Expand Down Expand Up @@ -247,14 +248,23 @@ func (c *Checkup) checkVersions(ctx context.Context) error {
func (c *Checkup) checkGoldenImages(ctx context.Context, namespaces *corev1.NamespaceList, errStr *string) error {
log.Print("checkGoldenImages")

const defaultGoldenImagesNamespace = "openshift-virtualization-os-images"
var cs goldenImagesCheckState
for i := range namespaces.Items {
ns := namespaces.Items[i].Name
if err := c.checkDataImportCrons(ctx, ns, &cs); err != nil {

if ns, err := c.client.GetNamespace(ctx, defaultGoldenImagesNamespace); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

question, dont you get in the namespaces list also "openshift-virtualization-os-images"? if so why do you need this commit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to prefer it over other namespaces if we have DataImportCrons there, but use DICs from the other namespaces if not. It can be written as a single loop but it will be a bit more clumsy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see that inside checkDataImportCrons you eventually update some values so now I understand

if err := c.checkDataImportCrons(ctx, ns.Name, &cs); err != nil {
return err
}
}

for i := range namespaces.Items {
if ns := namespaces.Items[i].Name; ns != defaultGoldenImagesNamespace {
if err := c.checkDataImportCrons(ctx, ns, &cs); err != nil {
return err
}
}
}

if c.goldenImagePvc == nil {
if cs.fallbackPvcDefaultSC != nil {
c.goldenImagePvc = cs.fallbackPvcDefaultSC
Expand Down
9 changes: 9 additions & 0 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ func (cs *clientStub) ListVirtualMachinesInstances(ctx context.Context, namespac
return vmiList, nil
}

func (cs *clientStub) GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error) {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
return ns, nil
}

func (cs *clientStub) GetPersistentVolumeClaim(ctx context.Context, namespace, name string) (*corev1.PersistentVolumeClaim, error) {
blockMode := corev1.PersistentVolumeBlock
pvc := &corev1.PersistentVolumeClaim{
Expand Down
4 changes: 4 additions & 0 deletions pkg/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (c *Client) ListCDIs(ctx context.Context) (*cdiv1.CDIList, error) {
return c.CdiClient().CdiV1beta1().CDIs().List(ctx, metav1.ListOptions{})
}

func (c *Client) GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error) {
return c.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
}

func (c *Client) GetPersistentVolumeClaim(ctx context.Context, namespace, name string) (*corev1.PersistentVolumeClaim, error) {
return c.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, name, metav1.GetOptions{})
}
Expand Down