Skip to content

Commit 7381f9c

Browse files
committed
Replace BundleDeployment in Unpack APIs
Replace BundleDeployment in the Unpack APIs with a combination of BundleSource and ClusterExtension. It builds... Signed-off-by: Todd Short <[email protected]>
1 parent c41a520 commit 7381f9c

File tree

8 files changed

+375
-79
lines changed

8 files changed

+375
-79
lines changed

internal/controllers/clusterextension_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
4646
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
4747
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
48+
rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api"
4849
)
4950

5051
// ClusterExtensionReconciler reconciles a ClusterExtension object
@@ -171,6 +172,12 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
171172
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
172173
return ctrl.Result{}, err
173174
}
175+
176+
// Create a BundleSource to be passed to the unpackers
177+
_ = r.GenerateExpectedBundleSource(*ext, bundle.Image, bundleProvisioner)
178+
// Now, we'd start to unpack from the return of GenerateExpectedBundleSource
179+
// Probably don't need the code below
180+
174181
// Ensure a BundleDeployment exists with its bundle source from the bundle
175182
// image we just looked up in the solution.
176183
dep := r.GenerateExpectedBundleDeployment(*ext, bundle.Image, bundleProvisioner)
@@ -359,6 +366,15 @@ func (r *ClusterExtensionReconciler) bundleFromSolution(selection []deppy.Variab
359366
return nil, fmt.Errorf("bundle for package %q not found in solution", packageName)
360367
}
361368

369+
func (r *ClusterExtensionReconciler) GenerateExpectedBundleSource(o ocv1alpha1.ClusterExtension, bundlePath string, bundleProvisioner string) *rukpakapi.BundleSource {
370+
return &rukpakapi.BundleSource{
371+
Type: rukpakapi.SourceTypeImage,
372+
Image: &rukpakapi.ImageSource{
373+
Ref: bundlePath,
374+
},
375+
}
376+
}
377+
362378
func (r *ClusterExtensionReconciler) GenerateExpectedBundleDeployment(o ocv1alpha1.ClusterExtension, bundlePath string, bundleProvisioner string) *unstructured.Unstructured {
363379
// We use unstructured here to avoid problems of serializing default values when sending patches to the apiserver.
364380
// If you use a typed object, any default values from that struct get serialized into the JSON patch, which could

internal/rukpak/api/bundle_types.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Copyright 2021.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package rukpakapi
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
)
22+
23+
type SourceType string
24+
25+
const (
26+
SourceTypeImage SourceType = "image"
27+
SourceTypeGit SourceType = "git"
28+
SourceTypeConfigMaps SourceType = "configMaps"
29+
SourceTypeHTTP SourceType = "http"
30+
31+
TypeUnpacked = "Unpacked"
32+
33+
ReasonUnpackPending = "UnpackPending"
34+
ReasonUnpacking = "Unpacking"
35+
ReasonUnpackSuccessful = "UnpackSuccessful"
36+
ReasonUnpackFailed = "UnpackFailed"
37+
ReasonProcessingFinalizerFailed = "ProcessingFinalizerFailed"
38+
39+
PhasePending = "Pending"
40+
PhaseUnpacking = "Unpacking"
41+
PhaseFailing = "Failing"
42+
PhaseUnpacked = "Unpacked"
43+
)
44+
45+
type BundleSource struct {
46+
// Type defines the kind of Bundle content being sourced.
47+
Type SourceType `json:"type"`
48+
// Image is the bundle image that backs the content of this bundle.
49+
Image *ImageSource `json:"image,omitempty"`
50+
// Git is the git repository that backs the content of this Bundle.
51+
Git *GitSource `json:"git,omitempty"`
52+
// ConfigMaps is a list of config map references and their relative
53+
// directory paths that represent a bundle filesystem.
54+
ConfigMaps []ConfigMapSource `json:"configMaps,omitempty"`
55+
// HTTP is the remote location that backs the content of this Bundle.
56+
HTTP *HTTPSource `json:"http,omitempty"`
57+
}
58+
59+
type ImageSource struct {
60+
// Ref contains the reference to a container image containing Bundle contents.
61+
Ref string `json:"ref"`
62+
// ImagePullSecretName contains the name of the image pull secret in the namespace that the provisioner is deployed.
63+
ImagePullSecretName string `json:"pullSecret,omitempty"`
64+
}
65+
66+
type GitSource struct {
67+
// Repository is a URL link to the git repository containing the bundle.
68+
// Repository is required and the URL should be parsable by a standard git tool.
69+
Repository string `json:"repository"`
70+
// Directory refers to the location of the bundle within the git repository.
71+
// Directory is optional and if not set defaults to ./manifests.
72+
Directory string `json:"directory,omitempty"`
73+
// Ref configures the git source to clone a specific branch, tag, or commit
74+
// from the specified repo. Ref is required, and exactly one field within Ref
75+
// is required. Setting more than one field or zero fields will result in an
76+
// error.
77+
Ref GitRef `json:"ref"`
78+
// Auth configures the authorization method if necessary.
79+
Auth Authorization `json:"auth,omitempty"`
80+
}
81+
82+
type ConfigMapSource struct {
83+
// ConfigMap is a reference to a configmap in the rukpak system namespace
84+
ConfigMap corev1.LocalObjectReference `json:"configMap"`
85+
// Path is the relative directory path within the bundle where the files
86+
// from the configmap will be present when the bundle is unpacked.
87+
Path string `json:"path,omitempty"`
88+
}
89+
90+
type HTTPSource struct {
91+
// URL is where the bundle contents is.
92+
URL string `json:"url"`
93+
// Auth configures the authorization method if necessary.
94+
Auth Authorization `json:"auth,omitempty"`
95+
}
96+
97+
type GitRef struct {
98+
// Branch refers to the branch to checkout from the repository.
99+
// The Branch should contain the bundle manifests in the specified directory.
100+
Branch string `json:"branch,omitempty"`
101+
// Tag refers to the tag to checkout from the repository.
102+
// The Tag should contain the bundle manifests in the specified directory.
103+
Tag string `json:"tag,omitempty"`
104+
// Commit refers to the commit to checkout from the repository.
105+
// The Commit should contain the bundle manifests in the specified directory.
106+
Commit string `json:"commit,omitempty"`
107+
}
108+
109+
type Authorization struct {
110+
// Secret contains reference to the secret that has authorization information and is in the namespace that the provisioner is deployed.
111+
// The secret is expected to contain `data.username` and `data.password` for the username and password, respectively for http(s) scheme.
112+
// Refer to https://kubernetes.io/docs/concepts/configuration/secret/#basic-authentication-secret
113+
// For the ssh authorization of the GitSource, the secret is expected to contain `data.ssh-privatekey` and `data.ssh-knownhosts` for the ssh privatekey and the host entry in the known_hosts file respectively.
114+
// Refer to https://kubernetes.io/docs/concepts/configuration/secret/#ssh-authentication-secrets
115+
Secret corev1.LocalObjectReference `json:"secret,omitempty"`
116+
// InsecureSkipVerify controls whether a client verifies the server's certificate chain and host name. If InsecureSkipVerify
117+
// is true, the clone operation will accept any certificate presented by the server and any host name in that
118+
// certificate. In this mode, TLS is susceptible to machine-in-the-middle attacks unless custom verification is
119+
// used. This should be used only for testing.
120+
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
121+
}
122+
123+
type ProvisionerID string

internal/rukpak/api/zz_generated.deepcopy.go

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/rukpak/source/configmaps.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ import (
1111
"k8s.io/apimachinery/pkg/util/sets"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
1313

14-
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
14+
clusterextension "github.com/operator-framework/operator-controller/api/v1alpha1"
15+
rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api"
1516
)
1617

1718
type ConfigMaps struct {
1819
Reader client.Reader
1920
ConfigMapNamespace string
2021
}
2122

22-
func (o *ConfigMaps) Unpack(ctx context.Context, bundle *rukpakv1alpha2.BundleDeployment) (*Result, error) {
23-
if bundle.Spec.Source.Type != rukpakv1alpha2.SourceTypeConfigMaps {
24-
return nil, fmt.Errorf("bundle source type %q not supported", bundle.Spec.Source.Type)
23+
func (o *ConfigMaps) Unpack(ctx context.Context, bs *rukpakapi.BundleSource, ce *clusterextension.ClusterExtension) (*Result, error) {
24+
if bs.Type != rukpakapi.SourceTypeConfigMaps {
25+
return nil, fmt.Errorf("bundle source type %q not supported", bs.Type)
2526
}
26-
if bundle.Spec.Source.ConfigMaps == nil {
27+
if bs.ConfigMaps == nil {
2728
return nil, fmt.Errorf("bundle source configmaps configuration is unset")
2829
}
2930

30-
configMapSources := bundle.Spec.Source.ConfigMaps
31+
configMapSources := bs.ConfigMaps
3132

3233
bundleFS := fstest.MapFS{}
3334
seenFilepaths := map[string]sets.Set[string]{}
@@ -74,9 +75,9 @@ func (o *ConfigMaps) Unpack(ctx context.Context, bundle *rukpakv1alpha2.BundleDe
7475
return nil, utilerrors.NewAggregate(errs)
7576
}
7677

77-
resolvedSource := &rukpakv1alpha2.BundleSource{
78-
Type: rukpakv1alpha2.SourceTypeConfigMaps,
79-
ConfigMaps: bundle.Spec.Source.DeepCopy().ConfigMaps,
78+
resolvedSource := &rukpakapi.BundleSource{
79+
Type: rukpakapi.SourceTypeConfigMaps,
80+
ConfigMaps: bs.DeepCopy().ConfigMaps,
8081
}
8182

8283
message := generateMessage("configMaps")

0 commit comments

Comments
 (0)