-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reject pool creation if pool with spec exists
in garm, a pool is uniq on imageName, flavor, provider and scope. This fixes the current implementation where we compared the image.tag name with the name of the image referenc itself. Signed-off-by: Mario Constanti <[email protected]>
- Loading branch information
1 parent
a35bf35
commit fc58124
Showing
5 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func TestPoolList_FilterByFields(t *testing.T) { | ||
type fields struct { | ||
TypeMeta metav1.TypeMeta | ||
ListMeta metav1.ListMeta | ||
Items []Pool | ||
} | ||
type args struct { | ||
predicates []Predicate | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
length int | ||
}{ | ||
{ | ||
name: "pool with spec already exist", | ||
fields: fields{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ListMeta: metav1.ListMeta{}, | ||
Items: []Pool{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2004-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2004", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2204-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2204", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
predicates: []Predicate{ | ||
MatchesImage("ubuntu-2204"), | ||
MatchesFlavour("large"), | ||
MatchesProvider("openstack"), | ||
MatchesGitHubScope("test", "Enterprise"), | ||
}, | ||
}, | ||
length: 1, | ||
}, | ||
{ | ||
name: "pool with spec does not exist", | ||
fields: fields{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ListMeta: metav1.ListMeta{}, | ||
Items: []Pool{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2004-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2004", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2204-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2204", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
predicates: []Predicate{ | ||
MatchesImage("ubuntu-2404"), | ||
MatchesFlavour("large"), | ||
MatchesProvider("openstack"), | ||
MatchesGitHubScope("test", "Enterprise"), | ||
}, | ||
}, | ||
length: 0, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
p := &PoolList{ | ||
TypeMeta: tt.fields.TypeMeta, | ||
ListMeta: tt.fields.ListMeta, | ||
Items: tt.fields.Items, | ||
} | ||
|
||
p.FilterByFields(tt.args.predicates...) | ||
|
||
if len(p.Items) != tt.length { | ||
t.Errorf("FilterByFields() = %v, want %v", len(p.Items), tt.length) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters