...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/manifest/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  	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  // Ensure that ManifestController implements declarative.ManifestController.
    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