Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/model/attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
)

type Attr struct {
Names names.Names
GoType string
Shape *awssdkmodel.Shape
GoTag string
Names names.Names
GoType string
Shape *awssdkmodel.Shape
GoTag string
IsImmutable bool
}

func NewAttr(
Expand Down
12 changes: 12 additions & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ func (m *Model) processNestedFieldTypeDefs(
if field.FieldConfig.GoTag != nil {
setTypeDefAttributeGoTag(crd, fieldPath, field, tdefs)
}
if field.IsImmutable() {
setTypeDefAttributeImmutable(crd, fieldPath, tdefs)
}
}
}
}
Expand Down Expand Up @@ -674,6 +677,15 @@ func setTypeDefAttributeGoTag(crd *CRD, fieldPath string, f *Field, tdefs []*Typ
}
}

// setTypeDefAttributeImmutable sets the IsImmutable flag for the corresponding
// attribute represented by fieldPath of nested field.
func setTypeDefAttributeImmutable(crd *CRD, fieldPath string, tdefs []*TypeDef) {
_, fieldAttr := getAttributeFromPath(crd, fieldPath, tdefs)
if fieldAttr != nil {
fieldAttr.IsImmutable = true
}
}

// updateTypeDefAttributeWithReference adds a new AWSResourceReference attribute
// for the corresponding attribute represented by fieldPath of nested field
func updateTypeDefAttributeWithReference(crd *CRD, fieldPath string, tdefs []*TypeDef) {
Expand Down
3 changes: 3 additions & 0 deletions templates/apis/type_def.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type {{ .Names.Camel }} struct {
{{- if $attr.Shape.Documentation }}
{{ $attr.Shape.Documentation }}
{{- end }}
{{- if $attr.IsImmutable }}
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable once set"
{{- end }}
{{ $attr.Names.Camel }} {{ $attr.GoType }} {{ $attr.GetGoTag }}
{{- end }}
}
Expand Down