-
Notifications
You must be signed in to change notification settings - Fork 80
/
store.go
57 lines (46 loc) · 1.92 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package metadata
import (
"context"
"fmt"
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"github.com/openshift/oc-mirror/pkg/config"
"github.com/openshift/oc-mirror/pkg/config/v1alpha1"
"github.com/openshift/oc-mirror/pkg/image"
"github.com/openshift/oc-mirror/pkg/metadata/storage"
)
// UpdateMetadata runs some reconciliation functions on Metadata to ensure its state is consistent
// then uses the Backend to update the metadata's storage medium.
func UpdateMetadata(ctx context.Context, backend storage.Backend, meta *v1alpha1.Metadata, insecure bool) error {
var operatorErrs []error
for mi, mirror := range meta.PastMirrors {
for _, operator := range mirror.Mirror.Operators {
operatorMeta, err := resolveOperatorMetadata(ctx, operator, backend, insecure)
if err != nil {
operatorErrs = append(operatorErrs, err)
continue
}
meta.PastMirrors[mi].Operators = append(meta.PastMirrors[mi].Operators, operatorMeta)
}
}
if len(operatorErrs) != 0 {
return utilerrors.NewAggregate(operatorErrs)
}
// Add mirror as a new PastMirror
if err := backend.WriteMetadata(ctx, meta, config.MetadataBasePath); err != nil {
return fmt.Errorf("error writing metadata: %v", err)
}
return nil
}
func resolveOperatorMetadata(ctx context.Context, operator v1alpha1.Operator, backend storage.Backend, insecure bool) (operatorMeta v1alpha1.OperatorMetadata, err error) {
operatorMeta.Catalog = operator.Catalog
resolver, err := containerdregistry.NewResolver(operator.PullSecret, insecure, nil)
if err != nil {
return v1alpha1.OperatorMetadata{}, fmt.Errorf("error creating image resolver: %v", err)
}
operatorMeta.ImagePin, err = image.ResolveToPin(ctx, resolver, operator.Catalog)
if err != nil {
return v1alpha1.OperatorMetadata{}, fmt.Errorf("error resolving catalog image %q: %v", operator.Catalog, err)
}
return operatorMeta, nil
}