diff --git a/operator/config/crd/bases/core.cnrm.cloud.google.com_configconnectorcontexts.yaml b/operator/config/crd/bases/core.cnrm.cloud.google.com_configconnectorcontexts.yaml index 6ba76a9c37..6f7cb5536a 100644 --- a/operator/config/crd/bases/core.cnrm.cloud.google.com_configconnectorcontexts.yaml +++ b/operator/config/crd/bases/core.cnrm.cloud.google.com_configconnectorcontexts.yaml @@ -97,6 +97,12 @@ spec: - Absent - Merge type: string + version: + description: |- + Version specifies the exact addon version to be deployed, eg 1.2.3 + Only limited versions are supported; currently we are only supporting + the operator version and the previous minor version. + type: string required: - googleServiceAccount type: object diff --git a/operator/pkg/apis/core/v1beta1/configconnectorcontext_types.go b/operator/pkg/apis/core/v1beta1/configconnectorcontext_types.go index 019c31450d..79ee74d5d4 100644 --- a/operator/pkg/apis/core/v1beta1/configconnectorcontext_types.go +++ b/operator/pkg/apis/core/v1beta1/configconnectorcontext_types.go @@ -25,6 +25,11 @@ import ( // ConfigConnectorContextSpec defines the desired state of ConfigConnectorContext type ConfigConnectorContextSpec struct { + // Version specifies the exact addon version to be deployed, eg 1.2.3 + // Only limited versions are supported; currently we are only supporting + // the operator version and the previous minor version. + Version string `json:"version,omitempty"` + // The Google Service Account to be used by Config Connector to // authenticate with Google Cloud APIs in the associated namespace. GoogleServiceAccount string `json:"googleServiceAccount"` diff --git a/operator/pkg/manifest/per_namespace_manifest_loader.go b/operator/pkg/manifest/per_namespace_manifest_loader.go index 6b04e7c039..3ab4c35f23 100644 --- a/operator/pkg/manifest/per_namespace_manifest_loader.go +++ b/operator/pkg/manifest/per_namespace_manifest_loader.go @@ -39,17 +39,27 @@ func NewPerNamespaceManifestLoader(repo Repository) *PerNamespaceManifestLoader } func (p *PerNamespaceManifestLoader) ResolveManifest(ctx context.Context, o runtime.Object) (map[string]string, error) { - _, ok := o.(*corev1beta1.ConfigConnectorContext) + ccc, ok := o.(*corev1beta1.ConfigConnectorContext) if !ok { return nil, fmt.Errorf("expected the resource to be a ConfigConnectorContext, but it was not. Object: %v", o) } componentName := k8s.ConfigConnectorComponentName channelName := k8s.StableChannel - v, err := ResolveVersion(ctx, p.repo, componentName, channelName) + + version := ccc.Spec.Version + if version == "" { + v, err := ResolveVersion(ctx, p.repo, componentName, channelName) + if err != nil { + return nil, fmt.Errorf("error resolving the version for %v in %v channel: %w", componentName, channelName, err) + } + version = v + } + + files, err := p.repo.LoadNamespacedComponents(ctx, componentName, version) if err != nil { - return nil, fmt.Errorf("error resolving the version for %v in %v channel: %w", componentName, channelName, err) + return nil, fmt.Errorf("version %q could not be loaded: %w", version, err) } - return p.repo.LoadNamespacedComponents(ctx, componentName, v) + return files, nil }