...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/manifest/per_namespace_manifest_loader.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/manifest

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    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  // Ensure that PerNamespaceManifestLoader implements declarative.ManifestController.
    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