...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package manifest
16
17 import (
18 "context"
19 "fmt"
20
21 corev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/apis/core/v1beta1"
22 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/k8s"
23
24 "k8s.io/apimachinery/pkg/runtime"
25 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
26 )
27
28 type PerNamespaceManifestLoader struct {
29 repo Repository
30 }
31
32
33 var _ declarative.ManifestController = &PerNamespaceManifestLoader{}
34
35 func NewPerNamespaceManifestLoader(repo Repository) *PerNamespaceManifestLoader {
36 return &PerNamespaceManifestLoader{
37 repo: repo,
38 }
39 }
40
41 func (p *PerNamespaceManifestLoader) ResolveManifest(ctx context.Context, o runtime.Object) (map[string]string, error) {
42 _, ok := o.(*corev1beta1.ConfigConnectorContext)
43 if !ok {
44 return nil, fmt.Errorf("expected the resource to be a ConfigConnectorContext, but it was not. Object: %v", o)
45 }
46
47 componentName := k8s.ConfigConnectorComponentName
48 channelName := k8s.StableChannel
49 v, err := ResolveVersion(ctx, p.repo, componentName, channelName)
50 if err != nil {
51 return nil, fmt.Errorf("error resolving the version for %v in %v channel: %v", componentName, channelName, err)
52 }
53
54 return p.repo.LoadNamespacedComponents(ctx, componentName, v)
55 }
56
View as plain text