-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator: image bundle < 1000 references test
- Loading branch information
1 parent
833a39d
commit 7e57fde
Showing
13 changed files
with
217 additions
and
11 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,81 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"strings" | ||
|
||
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder" | ||
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/stringhelper" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type CatalogSource struct { | ||
*olmv1Alpha.CatalogSource | ||
} | ||
|
||
func NewCatalogSource(cs *olmv1Alpha.CatalogSource) *CatalogSource { | ||
return &CatalogSource{ | ||
CatalogSource: cs, | ||
} | ||
} | ||
|
||
func (cs *CatalogSource) GetBundleCount(env *TestEnvironment) (int, error) { | ||
const ( | ||
grpCurlVersion = "1.8.5" | ||
grpCurlFileName = "grpcurl_" + grpCurlVersion + "_linux_x86_64.tar.gz" | ||
) | ||
|
||
// List of images that are allowlisted to be skipped. | ||
allowlistedBundleImages := []string{ | ||
"registry.redhat.io/redhat/", | ||
// TODO: Add more images to the allowlist if needed | ||
} | ||
|
||
o := clientsholder.GetClientsHolder() | ||
|
||
// The index image needs to be queried to get the bundle count. | ||
// We accomplish this by exec'ing into the running pod. | ||
|
||
// Get all pods in the cluster wide | ||
allPods, err := o.K8sClient.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
return -1, err | ||
} | ||
|
||
// Look through all of the pods to find the find the pod that is running the index image | ||
// If the pod is running an image that is allowlisted, then we can skip it | ||
|
||
// First find the pod that is running the index image | ||
for p := range allPods.Items { | ||
for c := range allPods.Items[p].Spec.Containers { | ||
if allPods.Items[p].Spec.Containers[c].Image != cs.Spec.Image || | ||
stringhelper.StringInSlice(allowlistedBundleImages, | ||
allPods.Items[p].Spec.Containers[c].Image, true) { | ||
continue | ||
} | ||
|
||
// Found the pod that is running the index image | ||
// Now exec into the pod and run the command to get the bundle count | ||
|
||
ctx := clientsholder.NewContext(allPods.Items[p].Namespace, | ||
allPods.Items[p].Name, allPods.Items[p].Spec.Containers[c].Name) | ||
|
||
grpCurlURL := "https://github.com/fullstorydev/grpcurl/releases/download/v" + grpCurlVersion + "/" + grpCurlFileName | ||
|
||
createBundlesCommand := "curl -s -L0 " + grpCurlURL + " -o " + grpCurlFileName + "; tar -xf " + grpCurlFileName + | ||
"; " + "./grpcurl -plaintext localhost:50051 api.Registry.ListBundles > bundles.txt; cat bundles.txt | grep bundlePath | wc -l" | ||
|
||
// exec into the pod and run the commands | ||
cmdValue, errStr, err := o.ExecCommandContainer(ctx, createBundlesCommand) | ||
if err != nil || errStr != "" { | ||
return -1, err | ||
} | ||
|
||
return strconv.Atoi(strings.TrimSpace(cmdValue)) | ||
} | ||
} | ||
|
||
return -1, nil | ||
} |
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 @@ | ||
package provider |
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
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