...
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 ctrl "sigs.k8s.io/controller-runtime"
26 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
27 )
28
29 var (
30 mlog = ctrl.Log.WithName("ManifestLoader")
31 rlog = ctrl.Log.WithName("LocalRepository")
32 )
33
34 const (
35 crdFileName = "crds.yaml"
36 cnrmSystemFileName = "0-cnrm-system.yaml"
37 perNamespaceComponentsFileName = "per-namespace-components.yaml"
38 )
39
40 type ManifestLoader struct {
41 repo Repository
42 }
43
44 func NewManifestLoader(repo Repository) *ManifestLoader {
45 return &ManifestLoader{
46 repo: repo,
47 }
48 }
49
50
51 var _ declarative.ManifestController = &ManifestLoader{}
52
53 func (c *ManifestLoader) ResolveManifest(ctx context.Context, o runtime.Object) (map[string]string, error) {
54 cc, ok := o.(*corev1beta1.ConfigConnector)
55 if !ok {
56 return nil, fmt.Errorf("expected the resource to be a ConfigConnector, but it was not. Object: %v", o)
57 }
58 mlog.Info("resolving manifest", "name", cc.Name)
59
60 componentName := cc.ComponentName()
61 channelName := k8s.StableChannel
62 version, err := ResolveVersion(ctx, c.repo, componentName, channelName)
63 if err != nil {
64 return nil, fmt.Errorf("error resolving the version for %v in %v channel: %v", componentName, channelName, err)
65 }
66 mlog.Info("resolved version from channel", "channel", channelName, "version", version)
67 return c.repo.LoadManifest(ctx, componentName, version, cc)
68 }
69
View as plain text