...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf/mutableunreadable.go

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

     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 krmtotf
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
    21  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/text"
    22  )
    23  
    24  func MutableButUnreadableFieldsAnnotationFor(r *Resource) (string, error) {
    25  	paths := getMutableButUnreadablePaths(r)
    26  	return k8s.GenerateMutableButUnreadableFieldsAnnotation(&r.Resource, paths)
    27  }
    28  
    29  // getMutableButUnreadablePaths returns the list of fields supported by the
    30  // resource that are mutable but unreadable. Each field is broken down into its
    31  // path elements (i.e. ["spec", "fooBar"] instead of "spec.fooBar").
    32  func getMutableButUnreadablePaths(r *Resource) [][]string {
    33  	tfFields := r.ResourceConfig.MutableButUnreadableFields
    34  	lowerCamelCasePaths := make([][]string, 0)
    35  	for _, tfField := range tfFields {
    36  		tfPath := strings.Split(tfField, ".")
    37  		lowerCamelCasePaths = append(lowerCamelCasePaths, text.SnakeCaseStrsToLowerCamelCaseStrs(tfPath))
    38  	}
    39  	return lowerCamelCasePaths
    40  }
    41  
    42  func getMutableButUnreadableFieldsFromAnnotations(r *Resource) (map[string]interface{}, error) {
    43  	paths := getMutableButUnreadablePaths(r)
    44  	return k8s.GetMutableButUnreadableFieldsFromAnnotations(&r.Resource, paths)
    45  }
    46  

View as plain text