Documentation ¶
Index ¶
- Constants
- Variables
- func ParentFieldPath(path string) string
- func ReplacePkgName(subject string, apiPkgName string, replacePkgAlias string, keepPointer bool) string
- type Attr
- type By
- type CRD
- func (r *CRD) AddSpecField(memberNames names.Names, shapeRef *awssdkmodel.ShapeRef)
- func (r *CRD) AddStatusField(memberNames names.Names, shapeRef *awssdkmodel.ShapeRef)
- func (r *CRD) AddTypeImport(packagePath string, alias string)
- func (r *CRD) AdditionalPrinterColumns() []*PrinterColumn
- func (r *CRD) CompareIgnoredFields() []string
- func (r *CRD) Config() *ackgenconfig.Config
- func (r *CRD) CustomUpdateMethodName() string
- func (r *CRD) Documentation() string
- func (r *CRD) ExceptionCode(httpStatusCode int) string
- func (r *CRD) GetAllRenames(op OpType) (map[string]string, error)
- func (r *CRD) GetCustomCheckRequiredFieldsMissingMethod(op *awssdkmodel.Operation) string
- func (r *CRD) GetCustomImplementation(op *awssdkmodel.Operation) string
- func (r *CRD) GetImmutableFieldPaths() []string
- func (r *CRD) GetOutputShape(op *awssdkmodel.Operation) (*awssdkmodel.Shape, error)
- func (r *CRD) GetOutputShapeGoType(op *awssdkmodel.Operation) string
- func (r *CRD) GetOutputWrapperFieldPath(op *awssdkmodel.Operation) *string
- func (r *CRD) GetResourcePrintOrderByName() string
- func (r *CRD) GetWrapperOutputShape(shape *awssdkmodel.Shape, fieldPath string) (*awssdkmodel.Shape, error)
- func (r *CRD) HasImmutableFieldChanges() bool
- func (r *CRD) HasShapeAsMember(toFind string) bool
- func (r *CRD) InputFieldRename(opID string, origFieldName string) (string, bool)
- func (r *CRD) IsAdoptable() bool
- func (r *CRD) IsPrimaryARNField(fieldName string) bool
- func (r *CRD) IsSecretField(path string) bool
- func (r *CRD) ListOpMatchFieldNames() []string
- func (r *CRD) PrintAgeColumn() bool
- func (r *CRD) ReconcileRequeuOnSuccessSeconds() int
- func (r *CRD) SDKAPIPackageName() string
- func (r *CRD) SetAttributesSingleAttribute() bool
- func (r *CRD) SetOutputCustomMethodName(op *awssdkmodel.Operation) *string
- func (r *CRD) SpecFieldNames() []string
- func (r *CRD) SpecIdentifierField() *string
- func (r *CRD) TerminalExceptionCodes() []string
- func (r *CRD) TypeRenames() map[string]string
- func (r *CRD) UnpackAttributes()
- func (r *CRD) UnpacksAttributesMap() bool
- func (r *CRD) UpdateConditionsCustomMethodName() string
- type EnumDef
- type EnumValue
- type Field
- type Model
- func (m *Model) ApplyShapeIgnoreRules()
- func (m *Model) GetCRDs() ([]*CRD, error)
- func (m *Model) GetConfig() *ackgenconfig.Config
- func (m *Model) GetEnumDefs() ([]*EnumDef, error)
- func (m *Model) GetTypeDefs() ([]*TypeDef, error)
- func (m *Model) IsShapeUsedInCRDs(shapeName string) bool
- func (m *Model) MetaVars() templateset.MetaVars
- func (m *Model) RemoveIgnoredOperations(ops *Ops)
- type OpType
- type OperationMap
- type Ops
- type PrinterColumn
- type SDKAPI
- func (a *SDKAPI) APIGroup() string
- func (a *SDKAPI) CRDNames(cfg *ackgenconfig.Config) []names.Names
- func (a *SDKAPI) GetInputShapeRef(opID string, path string) (*awssdkmodel.ShapeRef, bool)
- func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap
- func (a *SDKAPI) GetOutputShapeRef(opID string, path string) (*awssdkmodel.ShapeRef, bool)
- func (a *SDKAPI) GetPayloads() []string
- func (a *SDKAPI) GetServiceFullName() string
- func (a *SDKAPI) GetTypeRenames(cfg *ackgenconfig.Config) map[string]string
- func (a *SDKAPI) HasConflictingTypeName(typeName string, cfg *ackgenconfig.Config) bool
- func (a *SDKAPI) SDKAPIInterfaceTypeName() string
- func (a *SDKAPI) ServiceID() string
- func (a *SDKAPI) ServiceIDClean() string
- type SDKHelper
- func (h *SDKHelper) API(serviceAlias string) (*SDKAPI, error)
- func (h *SDKHelper) FirstAPIVersion(serviceAlias string) (string, error)
- func (h *SDKHelper) GetAPIVersions(serviceAlias string) ([]string, error)
- func (h *SDKHelper) ModelAndDocsPath(serviceAlias string) (string, string, error)
- func (h *SDKHelper) WithAPIVersion(apiVersion string)
- func (h *SDKHelper) WithSDKVersion(version string) error
- type TypeDef
Constants ¶
const ( // ConflictingNameSuffix is appended to type names when they overlap with // well-known common struct names for things like a CRD itself, or its // Spec/Status subfield struct type name. ConflictingNameSuffix = "_SDK" )
Variables ¶
var ( ErrInvalidVersionDirectory = errors.New( "expected to find only directories in api model directory but found non-directory", ) ErrNoValidVersionDirectory = errors.New( "no valid version directories found", ) ErrServiceNotFound = errors.New( "no such service", ) ErrAPIVersionNotFound = errors.New( "no such api version", ) )
var ( // ErrNilShapePointer indicates an unexpected nil Shape pointer ErrNilShapePointer = errors.New("found nil Shape pointer") )
Functions ¶
func ParentFieldPath ¶ added in v0.2.0
ParentFieldPath takes a field path and returns the field path of the containing "parent" field. For example, if the field path `Users..Credentials.Login` is passed in, this function returns `Users..Credentials`. If `Users..Password` is supplied, this function returns `Users`, etc.
func ReplacePkgName ¶
func ReplacePkgName( subject string, apiPkgName string, replacePkgAlias string, keepPointer bool, ) string
ReplacePkgName accepts a type string (`subject`), as returned by `aws-sdk-go/private/model/api:Shape.GoTypeWithPkgName()` and replaces the package name of the aws-sdk-go SDK API (e.g. "ecr" for the ECR API) with a different package alias, typically the string "svcsdk" which is the alias we use in our Go code generating functions that get placed into files like `services/$SERVICE/pkg/resource/$RESOURCE/sdk.go`.
As an example, if ReplacePkgName() is called with the following parameters:
subject: "*ecr.Repository" apiPkgName: "ecr" replacePkgAlias: "svcsdk" keepPointer: true
the returned string would be "*svcsdk.Repository"
Why do we need to do this? Well, the Go code-generating functions return strings of Go code that construct various aws-sdk-go "service API shapes".
For example, the `github.com/aws/aws-sdk-go/services/ecr.DescribeRepositoriesResponse` struct returns a slice of `github.com/aws/aws-sdk-go/services/ecr.Repository` structs. The `aws-sdk-go/private/model/api.Shape` object that represents these `Repository` structs has a `GoTypeWithPkgName()` method that returns the string "*ecr.Repository". But because in our `templates/pkg/resource/sdk.go.tpl` file [0], you will note that we always alias the aws-sdk-go "service api" package as "svcsdk". So, we need a way to replace the "ecr." in the type string with "svcsdk.".
Types ¶
type By ¶ added in v0.0.6
type By func(a, b *PrinterColumn) bool
By can sort two PrinterColumns
func (By) Sort ¶ added in v0.0.6
func (by By) Sort(subject []*PrinterColumn)
Sort does an in-place sort of the supplied printer columns
type CRD ¶
type CRD struct { Names names.Names Kind string Plural string // Ops are the CRUD operations controlling this resource Ops Ops // SpecFields is a map, keyed by the **original SDK member name** of // Field objects representing those fields in the CRD's Spec struct // field. SpecFields map[string]*Field // StatusFields is a map, keyed by the **original SDK member name** of // Field objects representing those fields in the CRD's Status struct // field. Note that there are no fields in StatusFields that are also in // SpecFields. StatusFields map[string]*Field // Fields is a map, keyed by the **renamed/normalized field path**, of // Field objects representing a field in the CRD's Spec or Status objects. Fields map[string]*Field // TypeImports is a map, keyed by an import string, with the map value // being the import alias TypeImports map[string]string // ShortNames represent the CRD list of aliases. Short names allow shorter // strings to match a CR on the CLI. ShortNames []string // contains filtered or unexported fields }
CRD describes a single top-level resource in an AWS service API
func NewCRD ¶
NewCRD returns a pointer to a new `ackmodel.CRD` struct that describes a single top-level resource in an AWS service API
func (*CRD) AddSpecField ¶
func (r *CRD) AddSpecField( memberNames names.Names, shapeRef *awssdkmodel.ShapeRef, )
AddSpecField adds a new Field of a given name and shape into the Spec field of a CRD
func (*CRD) AddStatusField ¶
func (r *CRD) AddStatusField( memberNames names.Names, shapeRef *awssdkmodel.ShapeRef, )
AddStatusField adds a new Field of a given name and shape into the Status field of a CRD
func (*CRD) AddTypeImport ¶
AddTypeImport adds an entry in the CRD's TypeImports map for an import line and optional alias
func (*CRD) AdditionalPrinterColumns ¶
func (r *CRD) AdditionalPrinterColumns() []*PrinterColumn
AdditionalPrinterColumns returns a sorted list of PrinterColumn structs for the resource
func (*CRD) CompareIgnoredFields ¶
CompareIgnoredFields returns the list of fields compare logic should ignore
func (*CRD) Config ¶
func (r *CRD) Config() *ackgenconfig.Config
Config returns a pointer to the generator config
func (*CRD) CustomUpdateMethodName ¶
CustomUpdateMethodName returns the name of the custom resourceManager method for updating the resource state, if any has been specified in the generator config
func (*CRD) Documentation ¶ added in v0.2.3
Documentation returns the base documentation string for the API formatted as a Go code comment block
func (*CRD) ExceptionCode ¶
ExceptionCode returns the name of the resource's Exception code for the Exception having the exception code. If the generator config has instructions for overriding the name of an exception code for a resource for a particular HTTP status code, we return that, otherwise we look through the API model definitions looking for a match
func (*CRD) GetAllRenames ¶ added in v0.6.0
GetAllRenames returns all the field renames observed in the generator config for a given OpType.
func (*CRD) GetCustomCheckRequiredFieldsMissingMethod ¶ added in v0.5.0
func (r *CRD) GetCustomCheckRequiredFieldsMissingMethod( op *awssdkmodel.Operation, ) string
GetCustomCheckRequiredFieldsMissingMethod returns custom check required fields missing method as string for custom resource, if specified in generator config
func (*CRD) GetCustomImplementation ¶
func (r *CRD) GetCustomImplementation( op *awssdkmodel.Operation, ) string
GetCustomImplementation returns custom implementation method name for the supplied operation as specified in generator config
func (*CRD) GetImmutableFieldPaths ¶ added in v0.2.2
GetImmutableFieldPaths returns list of immutable field paths present in CRD
func (*CRD) GetOutputShape ¶ added in v0.3.0
func (r *CRD) GetOutputShape( op *awssdkmodel.Operation, ) (*awssdkmodel.Shape, error)
GetOutputShape returns the Output shape for given operation.
func (*CRD) GetOutputShapeGoType ¶ added in v0.3.0
func (r *CRD) GetOutputShapeGoType( op *awssdkmodel.Operation, ) string
GetOutputShapeGoType returns the Go type of the supplied operation's Output shape, renamed to use the standardized svcsdk alias.
func (*CRD) GetOutputWrapperFieldPath ¶ added in v0.2.3
func (r *CRD) GetOutputWrapperFieldPath( op *awssdkmodel.Operation, ) *string
GetOutputWrapperFieldPath returns the JSON-Path of the output wrapper field as *string for a given operation, if specified in generator config.
func (*CRD) GetResourcePrintOrderByName ¶ added in v0.2.3
GetResourcePrintOrderByName returns the Printer Column order-by field name
func (*CRD) GetWrapperOutputShape ¶ added in v0.3.0
func (r *CRD) GetWrapperOutputShape( shape *awssdkmodel.Shape, fieldPath string, ) (*awssdkmodel.Shape, error)
GetWrapperOutputShape returns the shape of the last element of a given field Path. It carefully unwraps the output shape and verifies that every element of the field path exists in their correspanding parent shape and that they are structures.
func (*CRD) HasImmutableFieldChanges ¶ added in v0.2.2
HasImmutableFieldChanges helper function that return true if there are any immutable field changes
func (*CRD) HasShapeAsMember ¶
HasShapeAsMember returns true if the supplied Shape name appears in *any* payload shape of *any* Operation for the resource. It recurses down through the resource's Operation Input and Output shapes and their member shapes looking for a shape with the supplied name
func (*CRD) InputFieldRename ¶
InputFieldRename returns the renamed field for a supplied Operation ID and original field name and whether or not a renamed override field name was found
func (*CRD) IsAdoptable ¶ added in v0.1.0
IsAdoptable returns true if the resource can be adopted
func (*CRD) IsPrimaryARNField ¶
IsPrimaryARNField returns true if the supplied field name is likely the resource's ARN identifier field.
func (*CRD) IsSecretField ¶ added in v0.2.0
IsSecretField returns true if the supplied field *path* refers to a Field that is a SecretKeyReference
func (*CRD) ListOpMatchFieldNames ¶
ListOpMatchFieldNames returns a slice of strings representing the field names in the List operation's Output shape's element Shape that we should check a corresponding value in the target Spec exists.
func (*CRD) PrintAgeColumn ¶ added in v0.2.3
PrintAgeColumn returns whether the code generator should append 'Age' kubebuilder:printcolumn comment marker
func (*CRD) ReconcileRequeuOnSuccessSeconds ¶ added in v0.3.1
ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue the custom resource as int, if specified in generator config.
func (*CRD) SDKAPIPackageName ¶
SDKAPIPackageName returns the aws-sdk-go package name used for this resource's API
func (*CRD) SetAttributesSingleAttribute ¶
SetAttributesSingleAttribute returns true if the supplied resource name has a SetAttributes operation that only actually changes a single attribute at a time. See: SNS SetTopicAttributes API call, which is entirely different from the SNS SetPlatformApplicationAttributes API call, which sets multiple attributes at once. :shrug:
func (*CRD) SetOutputCustomMethodName ¶
func (r *CRD) SetOutputCustomMethodName( op *awssdkmodel.Operation, ) *string
SetOutputCustomMethodName returns custom set output operation as *string for given operation on custom resource, if specified in generator config
func (*CRD) SpecFieldNames ¶
SpecFieldNames returns a sorted slice of field names for the Spec fields
func (*CRD) SpecIdentifierField ¶ added in v0.1.0
SpecIdentifierField returns the name of the "Name" or string identifier field in the Spec. This method does not guarantee that the identifier field returned is the primary identifier used in any of the `Read*` operations.
func (*CRD) TerminalExceptionCodes ¶
TerminalExceptionCodes returns terminal exception codes as []string for custom resource, if specified in generator config
func (*CRD) TypeRenames ¶
TypeRenames returns a map of original type name to renamed name (some type definition names conflict with generated names)
func (*CRD) UnpackAttributes ¶
func (r *CRD) UnpackAttributes()
UnpackAttributes grabs instructions about fields that are represented in the AWS API as a `map[string]*string` but are actually real, schema'd fields and adds Field definitions for those fields.
func (*CRD) UnpacksAttributesMap ¶
UnpacksAttributesMap returns true if the underlying API has Get{Resource}Attributes/Set{Resource}Attributes API calls that map real, schema'd fields to a raw `map[string]*string` for this resource (see SNS and SQS APIs)
func (*CRD) UpdateConditionsCustomMethodName ¶
UpdateConditionsCustomMethodName returns custom update conditions operation as *string for custom resource, if specified in generator config
type EnumDef ¶
EnumDef is the definition of an enumeration type for a field present in either a CRD or a TypeDef
type Field ¶
type Field struct { // CRD is the a pointer to the top-level custom resource definition // descriptor for the field or field's parent (if a nested field) CRD *CRD // Names is a set of normalized names for the field Names names.Names // Path is a "field path" that indicates where the field is within the CRD. // For example "Spec.Name" or "Status.BrokerInstances..Endpoint". Note for // the latter example, the field path indicates that the field `Endpoint` // is an attribute of the `Status.BrokerInstances` top-level field and the // double dot (`..` indicates that BrokerInstances is a list type). Path string // GoType is a string containing the Go data type for the field GoType string // GoTypeElem indicates the Go data type for the type of list element if // the field is a list type GoTypeElem string GoTypeWithPkgName string ShapeRef *awssdkmodel.ShapeRef FieldConfig *ackgenconfig.FieldConfig }
Field represents a single field in the CRD's Spec or Status objects. The field may be a direct field of the Spec or Status object or may be a field of a list or struct-type field of the Spec or Status object. We call these latter fields "nested fields" and they are identified by the Field.Path attribute.
func NewField ¶ added in v0.2.0
func NewField( crd *CRD, path string, fieldNames names.Names, shapeRef *awssdkmodel.ShapeRef, cfg *ackgenconfig.FieldConfig, ) *Field
NewField returns a pointer to a new Field object
func (*Field) IsRequired ¶
IsRequired checks the FieldConfig for Field and returns if the field is marked as required or not.A
If there is no required override present for this field in FieldConfig, IsRequired will return if the shape is marked as required in AWS SDK Private model We use this to append kubebuilder:validation:Required markers to validate using the CRD validation schema
type Model ¶ added in v0.5.0
type Model struct { SDKAPI *SDKAPI // contains filtered or unexported fields }
Model contains the ACK model for the generator to process and apply templates against.
func New ¶ added in v0.5.0
func New( SDKAPI *SDKAPI, apiVersion string, configPath string, defaultConfig ackgenconfig.Config, ) (*Model, error)
New returns a new Model struct for a supplied API model. Optionally, pass a file path to a generator config file that can be used to instruct the code generator how to handle the API properly
func (*Model) ApplyShapeIgnoreRules ¶ added in v0.5.0
func (m *Model) ApplyShapeIgnoreRules()
ApplyShapeIgnoreRules removes the ignored shapes and fields from the API object so that they are not considered in any of the calculations of code generator.
func (*Model) GetCRDs ¶ added in v0.5.0
GetCRDs returns a slice of `CRD` structs that describe the top-level resources discovered by the code generator for an AWS service API
func (*Model) GetConfig ¶ added in v0.5.0
func (m *Model) GetConfig() *ackgenconfig.Config
GetConfig returns the configuration option used to define the current generator.
func (*Model) GetEnumDefs ¶ added in v0.5.0
GetEnumDefs returns a slice of pointers to `EnumDef` structs which represent string fields whose value is constrained to one or more specific string values.
func (*Model) GetTypeDefs ¶ added in v0.5.0
GetTypeDefs returns a slice of `TypeDef` pointers
func (*Model) IsShapeUsedInCRDs ¶ added in v0.5.0
IsShapeUsedInCRDs returns true if the supplied shape name is a member of amy CRD's payloads or those payloads sub-member shapes
func (*Model) MetaVars ¶ added in v0.5.0
func (m *Model) MetaVars() templateset.MetaVars
MetaVars returns a MetaVars struct populated with metadata about the AWS service API
func (*Model) RemoveIgnoredOperations ¶ added in v0.5.0
RemoveIgnoredOperations updates Ops argument by setting those operations to nil that are configured to be ignored in generator config for the AWS service
type OpType ¶
type OpType int
func GetOpTypeAndResourceNameFromOpID ¶
GetOpTypeAndResourceNameFromOpID guesses the resource name and type of operation from the OperationID
func OpTypeFromString ¶
type OperationMap ¶
type OperationMap map[OpType]map[string]*awssdkmodel.Operation
type Ops ¶
type Ops struct { Create *awssdkmodel.Operation ReadOne *awssdkmodel.Operation ReadMany *awssdkmodel.Operation Update *awssdkmodel.Operation Delete *awssdkmodel.Operation GetAttributes *awssdkmodel.Operation SetAttributes *awssdkmodel.Operation }
Ops are the CRUD operations controlling a particular resource
func (Ops) IterOps ¶
func (ops Ops) IterOps() []*awssdkmodel.Operation
IterOps returns a slice of Operations for a resource
type PrinterColumn ¶
type PrinterColumn struct { CRD *CRD Name string Type string Priority int JSONPath string Index int }
PrinterColumn represents a single field in the CRD's Spec or Status objects
type SDKAPI ¶
type SDKAPI struct { API *awssdkmodel.API // contains filtered or unexported fields }
SDKAPI contains an API model for a single AWS service API
func (*SDKAPI) APIGroup ¶
APIGroup returns the normalized Kubernetes APIGroup for the AWS service API, e.g. "sns.services.k8s.aws"
func (*SDKAPI) CRDNames ¶
func (a *SDKAPI) CRDNames(cfg *ackgenconfig.Config) []names.Names
CRDNames returns a slice of names structs for all top-level resources in the API
func (*SDKAPI) GetInputShapeRef ¶
GetInputShapeRef finds a ShapeRef for a supplied member path (dot-notation) for given API operation
func (*SDKAPI) GetOperationMap ¶
func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap
GetOperationMap returns a map, keyed by the operation type and operation ID/name, of aws-sdk-go private/model/api.Operation struct pointers
func (*SDKAPI) GetOutputShapeRef ¶
GetOutputShapeRef finds a ShapeRef for a supplied member path (dot-notation) for given API operation
func (*SDKAPI) GetPayloads ¶
GetPayloads returns a slice of strings of Shape names representing input and output request/response payloads
func (*SDKAPI) GetServiceFullName ¶
func (*SDKAPI) GetTypeRenames ¶
func (a *SDKAPI) GetTypeRenames(cfg *ackgenconfig.Config) map[string]string
GetTypeRenames returns a map of original type name to renamed name (some type definition names conflict with generated names)
func (*SDKAPI) HasConflictingTypeName ¶
func (a *SDKAPI) HasConflictingTypeName(typeName string, cfg *ackgenconfig.Config) bool
HasConflictingTypeName returns true if the supplied type name will conflict with any generated type in the service's API package
func (*SDKAPI) SDKAPIInterfaceTypeName ¶
SDKAPIInterfaceTypeName returns the name of the aws-sdk-go primary API interface type name.
func (*SDKAPI) ServiceID ¶
ServiceID returns the exact `metadata.serviceId` attribute for the AWS service APi's api-2.json file
func (*SDKAPI) ServiceIDClean ¶
ServiceIDClean returns a lowercased, whitespace-stripped ServiceID
type SDKHelper ¶
type SDKHelper struct { // Default is "services.k8s.aws" APIGroupSuffix string // contains filtered or unexported fields }
SDKHelper is a helper struct that helps work with the aws-sdk-go models and API model loader
func NewSDKHelper ¶
NewSDKHelper returns a new SDKHelper object
func (*SDKHelper) FirstAPIVersion ¶ added in v0.6.0
FirstAPIVersion returns the first found API version for a service API. (e.h. "2012-10-03")
func (*SDKHelper) GetAPIVersions ¶ added in v0.6.0
GetAPIVersions returns the list of API Versions found in a service directory.
func (*SDKHelper) ModelAndDocsPath ¶
ModelAndDocsPath returns two string paths to the supplied service alias' model and doc JSON files
func (*SDKHelper) WithAPIVersion ¶ added in v0.6.0
WithAPIVersion sets the `apiVersion` field.
func (*SDKHelper) WithSDKVersion ¶ added in v0.6.0
WithSDKVersion checks out the sdk git repository to the provided version. To use this function h.basePath should point to a git repository.