@@ -20,10 +20,23 @@ import (
20
20
"github.com/google/go-containerregistry/pkg/v1/remote"
21
21
apimacherrors "k8s.io/apimachinery/pkg/util/errors"
22
22
"sigs.k8s.io/controller-runtime/pkg/log"
23
-
24
- bd "github.com/operator-framework/operator-controller/internal/rukpak/bundledeployment"
25
23
)
26
24
25
+ // SourceTypeImage is the identifier for image-type bundle sources
26
+ const SourceTypeImage SourceType = "image"
27
+
28
+ type ImageSource struct {
29
+ // Ref contains the reference to a container image containing Bundle contents.
30
+ Ref string
31
+ // ImagePullSecretName contains the name of the image pull secret in the namespace that the provisioner is deployed.
32
+ ImagePullSecretName string
33
+ // InsecureSkipTLSVerify indicates that TLS certificate validation should be skipped.
34
+ // If this option is specified, the HTTPS protocol will still be used to
35
+ // fetch the specified image reference.
36
+ // This should not be used in a production environment.
37
+ InsecureSkipTLSVerify bool
38
+ }
39
+
27
40
// Unrecoverable represents an error that can not be recovered
28
41
// from without user intervention. When this error is returned
29
42
// the request should not be requeued.
@@ -43,25 +56,25 @@ type ImageRegistry struct {
43
56
CaCertPool * x509.CertPool
44
57
}
45
58
46
- func (i * ImageRegistry ) Unpack (ctx context.Context , bundle * bd. BundleDeployment ) (* Result , error ) {
59
+ func (i * ImageRegistry ) Unpack (ctx context.Context , bundle * BundleSource ) (* Result , error ) {
47
60
l := log .FromContext (ctx )
48
- if bundle .Spec . Source . Type != bd . SourceTypeImage {
49
- panic (fmt .Sprintf ("programmer error: source type %q is unable to handle specified bundle source type %q" , bd . SourceTypeImage , bundle . Spec . Source .Type ))
61
+ if bundle .Type != SourceTypeImage {
62
+ panic (fmt .Sprintf ("programmer error: source type %q is unable to handle specified bundle source type %q" , SourceTypeImage , bundle .Type ))
50
63
}
51
64
52
- if bundle .Spec . Source . Image == nil {
65
+ if bundle .Image == nil {
53
66
return nil , NewUnrecoverable (fmt .Errorf ("error parsing bundle, bundle %s has a nil image source" , bundle .Name ))
54
67
}
55
68
56
- imgRef , err := name .ParseReference (bundle .Spec . Source . Image .Ref )
69
+ imgRef , err := name .ParseReference (bundle .Image .Ref )
57
70
if err != nil {
58
71
return nil , NewUnrecoverable (fmt .Errorf ("error parsing image reference: %w" , err ))
59
72
}
60
73
61
74
remoteOpts := []remote.Option {}
62
- if bundle .Spec . Source . Image .ImagePullSecretName != "" {
75
+ if bundle .Image .ImagePullSecretName != "" {
63
76
chainOpts := k8schain.Options {
64
- ImagePullSecrets : []string {bundle .Spec . Source . Image .ImagePullSecretName },
77
+ ImagePullSecrets : []string {bundle .Image .ImagePullSecretName },
65
78
Namespace : i .AuthNamespace ,
66
79
// TODO: Do we want to use any secrets that are included in the rukpak service account?
67
80
// If so, we will need to add the permission to get service accounts and specify
@@ -83,7 +96,7 @@ func (i *ImageRegistry) Unpack(ctx context.Context, bundle *bd.BundleDeployment)
83
96
MinVersion : tls .VersionTLS12 ,
84
97
} // nolint:gosec
85
98
}
86
- if bundle .Spec . Source . Image .InsecureSkipTLSVerify {
99
+ if bundle .Image .InsecureSkipTLSVerify {
87
100
transport .TLSClientConfig .InsecureSkipVerify = true // nolint:gosec
88
101
}
89
102
if i .CaCertPool != nil {
@@ -146,19 +159,19 @@ func wrapUnrecoverable(err error, isUnrecoverable bool) error {
146
159
return err
147
160
}
148
161
149
- func (i * ImageRegistry ) Cleanup (_ context.Context , bundle * bd. BundleDeployment ) error {
162
+ func (i * ImageRegistry ) Cleanup (_ context.Context , bundle * BundleSource ) error {
150
163
return os .RemoveAll (filepath .Join (i .BaseCachePath , bundle .Name ))
151
164
}
152
165
153
- func unpackedResult (fsys fs.FS , bundle * bd. BundleDeployment , ref string ) * Result {
166
+ func unpackedResult (fsys fs.FS , bundle * BundleSource , ref string ) * Result {
154
167
return & Result {
155
168
Bundle : fsys ,
156
- ResolvedSource : & bd. BundleSource {
157
- Type : bd . SourceTypeImage ,
158
- Image : & bd. ImageSource {
169
+ ResolvedSource : & BundleSource {
170
+ Type : SourceTypeImage ,
171
+ Image : & ImageSource {
159
172
Ref : ref ,
160
- ImagePullSecretName : bundle .Spec . Source . Image .ImagePullSecretName ,
161
- InsecureSkipTLSVerify : bundle .Spec . Source . Image .InsecureSkipTLSVerify ,
173
+ ImagePullSecretName : bundle .Image .ImagePullSecretName ,
174
+ InsecureSkipTLSVerify : bundle .Image .InsecureSkipTLSVerify ,
162
175
},
163
176
},
164
177
State : StateUnpacked ,
0 commit comments