-
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.
(feature): add direct image registry client
Unpacker
implementation (…
…#145) (feat): direct image registry client unpacker Signed-off-by: Bryce Palmer <[email protected]>
- Loading branch information
1 parent
8a90d8d
commit 9f3ba06
Showing
22 changed files
with
2,056 additions
and
327 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,97 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/metadata/fake" | ||
|
||
"github.com/operator-framework/catalogd/api/core/v1alpha1" | ||
) | ||
|
||
func TestUnpackStartupGarbageCollection(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
existCatalogs []*metav1.PartialObjectMetadata | ||
notExistCatalogs []*metav1.PartialObjectMetadata | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "successful garbage collection", | ||
existCatalogs: []*metav1.PartialObjectMetadata{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Catalog", | ||
APIVersion: v1alpha1.GroupVersion.String(), | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "one", | ||
}, | ||
}, | ||
{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Catalog", | ||
APIVersion: v1alpha1.GroupVersion.String(), | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "two", | ||
}, | ||
}, | ||
}, | ||
notExistCatalogs: []*metav1.PartialObjectMetadata{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Catalog", | ||
APIVersion: v1alpha1.GroupVersion.String(), | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "three", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
cachePath := t.TempDir() | ||
scheme := runtime.NewScheme() | ||
require.NoError(t, metav1.AddMetaToScheme(scheme)) | ||
|
||
allCatalogs := append(tt.existCatalogs, tt.notExistCatalogs...) | ||
for _, catalog := range allCatalogs { | ||
require.NoError(t, os.MkdirAll(filepath.Join(cachePath, catalog.Name, "fakedigest"), os.ModePerm)) | ||
} | ||
|
||
runtimeObjs := []runtime.Object{} | ||
for _, catalog := range tt.existCatalogs { | ||
runtimeObjs = append(runtimeObjs, catalog) | ||
} | ||
|
||
metaClient := fake.NewSimpleMetadataClient(scheme, runtimeObjs...) | ||
|
||
err := unpackStartupGarbageCollection(ctx, cachePath, logr.Discard(), metaClient) | ||
if !tt.wantErr { | ||
assert.NoError(t, err) | ||
entries, err := os.ReadDir(cachePath) | ||
require.NoError(t, err) | ||
assert.Len(t, entries, len(tt.existCatalogs)) | ||
for _, catalog := range tt.existCatalogs { | ||
assert.DirExists(t, filepath.Join(cachePath, catalog.Name)) | ||
} | ||
|
||
for _, catalog := range tt.notExistCatalogs { | ||
assert.NoDirExists(t, filepath.Join(cachePath, catalog.Name)) | ||
} | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
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,30 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- ../default | ||
|
||
patches: | ||
- patch: |- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
volumeMounts: | ||
- mountPath: /etc/ssl/certs/ | ||
name: ca-certs | ||
readOnly: true | ||
volumes: | ||
- name: ca-certs | ||
configMap: | ||
name: docker-registry.catalogd-e2e.svc | ||
defaultMode: 0644 | ||
optional: false | ||
items: | ||
- key: ca-certificates.crt | ||
path: ca-certificates.crt |
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.