Documentation
¶
Index ¶
- Variables
- func APIToProto(in any, out proto.Message) error
- func AddLabelManagedByCNRM(labels map[string]string) map[string]string
- func CompareProtoMessage(a, b proto.Message, compareDiff CompareDiff) (sets.Set[string], error)
- func CompareProtoMessageStructuredDiff(a, b proto.Message, compareDiff CompareDiff) (sets.Set[string], *structuredreporting.Diff, error)
- func ComputeGCPLabels(labels map[string]string) map[string]string
- func ExtractProjectID(resourceName string) string
- func IsFieldBehavior(field protoreflect.FieldDescriptor, fieldBehavior annotations.FieldBehavior) bool
- func NormalizeReferences(ctx context.Context, reader client.Reader, obj client.Object, ...) error
- func NormalizeStringToTimestamp(ts string) *timestamppb.Timestamp
- func ProtoToAPI[T any](in proto.Message, out *T) error
- func RemoveByPrefixes(a map[string]string, prefixes ...string)
- func VisitFields(obj any, visitor Visitor) error
- func WaitForDoneOrTimeout(ctx context.Context, pollInterval time.Duration, doneFunc func() (bool, error)) error
- type CompareDiff
- type LegacyCookie
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var BasicDiff = func(fieldName protoreflect.Name, a, b proto.Message) (bool, error) { aField := a.ProtoReflect().Descriptor().Fields().ByName(fieldName) bField := b.ProtoReflect().Descriptor().Fields().ByName(fieldName) if IsFieldBehavior(aField, annotations.FieldBehavior_OUTPUT_ONLY) { return false, nil } if bField == nil { return true, nil } if !aField.Kind().IsValid() { return false, fmt.Errorf("unimplemented kind: %s", aField.Kind().String()) } diff := false aVal := a.ProtoReflect().Get(aField) bVal := b.ProtoReflect().Get(bField) switch aField.Kind() { case protoreflect.MessageKind: if aField.IsList() || aField.IsMap() { if !aVal.Equal(bVal) { diff = true } } else { m := aVal.Message().Interface() switch m.(type) { case *timestamppb.Timestamp: if !aVal.Equal(bVal) { diff = true } case *durationpb.Duration: if !aVal.Equal(bVal) { diff = true } default: return false, fmt.Errorf("field %s not recursed", fieldName) } } default: if !aVal.Equal(bVal) { diff = true } } if diff && IsFieldBehavior(aField, annotations.FieldBehavior_IMMUTABLE) { return false, fmt.Errorf("change to immutable field %s", fieldName) } return diff, nil }
Functions ¶
func APIToProto ¶ added in v1.145.0
APIToProto maps a typed-go struct to a proto Message, assuming they have the same json schema
func AddLabelManagedByCNRM ¶ added in v1.126.0
func CompareProtoMessage ¶ added in v1.125.0
func CompareProtoMessageStructuredDiff ¶ added in v1.145.0
func CompareProtoMessageStructuredDiff(a, b proto.Message, compareDiff CompareDiff) (sets.Set[string], *structuredreporting.Diff, error)
CompareProtoMessageStructuredDiff computes the diff between two proto messages and returns both the set of changed field paths and a structured Diff object.
func ExtractProjectID ¶ added in v1.149.1
ExtractProjectID extracts the project ID (or number) from a GCP resource name or URL. Supported formats: - https://[hostname]/[version]/projects/[projectID]/... - //compute.googleapis.com/projects/[projectID]/... - projects/[projectID]/...
func IsFieldBehavior ¶ added in v1.125.0
func IsFieldBehavior(field protoreflect.FieldDescriptor, fieldBehavior annotations.FieldBehavior) bool
func NormalizeReferences ¶ added in v1.126.0
func NormalizeStringToTimestamp ¶
func NormalizeStringToTimestamp(ts string) *timestamppb.Timestamp
func ProtoToAPI ¶ added in v1.145.0
ProtoToAPI maps a proto Message to a typed-go struct, assuming they have the same json schema
func RemoveByPrefixes ¶
func VisitFields ¶ added in v1.126.0
Types ¶
type CompareDiff ¶ added in v1.125.0
type LegacyCookie ¶ added in v1.145.0
LegacyCookie is used for stateful reconciliation. It is stored in the status of the KCC resource.
func NewLegacyCookie ¶ added in v1.145.0
func NewLegacyCookie(spec, gcp proto.Message) (*LegacyCookie, error)
func (*LegacyCookie) Equal ¶ added in v1.145.0
func (c *LegacyCookie) Equal(lastModifiedCookie *string) bool
func (*LegacyCookie) String ¶ added in v1.145.0
func (c *LegacyCookie) String() string
ComposeCookie creates a cookie string from the spec and gcp hashes.