-
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.
Fixes a bug, where two pools crs could reference two differently named image crs with the same image tag specified. Both pools would get the same ID, as garm would only create one pool internally which caused an unexpected behaviour of the whole pool reconciliation logic / spinning of runners. NOTE: This should be absolote for garm v0.1.5 as garm allows multiple pools with same image, github-scope, flavor and provider
- Loading branch information
1 parent
208a6d0
commit a59562d
Showing
29 changed files
with
504 additions
and
167 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
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,86 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/mercedes-benz/garm-operator/pkg/filter" | ||
) | ||
|
||
func (p *Pool) CheckDuplicate(ctx context.Context, client client.Client, poolImage *Image) (bool, string, error) { | ||
poolList := &PoolList{} | ||
err := client.List(ctx, poolList) | ||
if err != nil { | ||
return false, "", err | ||
} | ||
|
||
// only get other pools | ||
filteredPoolList := filter.Match(poolList.Items, | ||
MatchesFlavor(p.Spec.Flavor), | ||
MatchesProvider(p.Spec.ProviderName), | ||
MatchesGitHubScope(p.Spec.GitHubScopeRef.Name, p.Spec.GitHubScopeRef.Kind), | ||
NotMatchingName(p.Name), | ||
) | ||
|
||
for _, p := range filteredPoolList { | ||
image, err := p.GetImageCR(ctx, client) | ||
if err != nil { | ||
continue | ||
} | ||
if image.Spec.Tag == poolImage.Spec.Tag { | ||
return true, fmt.Sprintf("%s/%s", p.Namespace, p.Name), nil | ||
} | ||
} | ||
return false, "", nil | ||
} | ||
|
||
func (p *Pool) GetImageCR(ctx context.Context, client client.Client) (*Image, error) { | ||
image := &Image{} | ||
if p.Spec.ImageName != "" { | ||
if err := client.Get(ctx, types.NamespacedName{Name: p.Spec.ImageName, Namespace: p.Namespace}, image); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return image, nil | ||
} | ||
|
||
func MatchesImage(image string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Spec.ImageName == image | ||
} | ||
} | ||
|
||
func MatchesFlavor(flavor string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Spec.Flavor == flavor | ||
} | ||
} | ||
|
||
func MatchesProvider(provider string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Spec.ProviderName == provider | ||
} | ||
} | ||
|
||
func MatchesGitHubScope(name, kind string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Spec.GitHubScopeRef.Name == name && p.Spec.GitHubScopeRef.Kind == kind | ||
} | ||
} | ||
|
||
func MatchesID(id string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Status.ID == id | ||
} | ||
} | ||
|
||
func NotMatchingName(name string) filter.Predicate[Pool] { | ||
return func(p Pool) bool { | ||
return p.Name != name | ||
} | ||
} |
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
Oops, something went wrong.