model

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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",
	)
)
View Source
var (
	// ErrNilShapePointer indicates an unexpected nil Shape pointer
	ErrNilShapePointer = errors.New("found nil Shape pointer")
)

Functions

func ParentFieldPath added in v0.2.0

func ParentFieldPath(path string) string

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.".

[0] https://github.com/aws-controllers-k8s/code-generator/blob/e2970c8ec5a68a831081d22d82509a428aa5fe00/templates/pkg/resource/sdk.go.tpl#L20

Types

type Attr

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

func NewAttr

func NewAttr(
	names names.Names,
	goType string,
	shape *awssdkmodel.Shape,
) *Attr

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

func NewCRD(
	sdkAPI *SDKAPI,
	cfg *ackgenconfig.Config,
	crdNames names.Names,
	ops Ops,
) *CRD

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

func (r *CRD) AddTypeImport(
	packagePath string,
	alias string,
)

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

func (r *CRD) CompareIgnoredFields() []string

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

func (r *CRD) CustomUpdateMethodName() string

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

func (r *CRD) Documentation() string

Documentation returns the base documentation string for the API formatted as a Go code comment block

func (*CRD) ExceptionCode

func (r *CRD) ExceptionCode(httpStatusCode int) string

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

func (r *CRD) GetAllRenames(op OpType) (map[string]string, error)

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

func (r *CRD) GetImmutableFieldPaths() []string

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

func (r *CRD) GetResourcePrintOrderByName() string

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

func (r *CRD) HasImmutableFieldChanges() bool

HasImmutableFieldChanges helper function that return true if there are any immutable field changes

func (*CRD) HasShapeAsMember

func (r *CRD) HasShapeAsMember(toFind string) bool

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

func (r *CRD) InputFieldRename(
	opID string,
	origFieldName string,
) (string, bool)

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

func (r *CRD) IsAdoptable() bool

IsAdoptable returns true if the resource can be adopted

func (*CRD) IsPrimaryARNField

func (r *CRD) IsPrimaryARNField(fieldName string) bool

IsPrimaryARNField returns true if the supplied field name is likely the resource's ARN identifier field.

func (*CRD) IsSecretField added in v0.2.0

func (r *CRD) IsSecretField(path string) bool

IsSecretField returns true if the supplied field *path* refers to a Field that is a SecretKeyReference

func (*CRD) ListOpMatchFieldNames

func (r *CRD) ListOpMatchFieldNames() []string

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

func (r *CRD) PrintAgeColumn() bool

PrintAgeColumn returns whether the code generator should append 'Age' kubebuilder:printcolumn comment marker

func (*CRD) ReconcileRequeuOnSuccessSeconds added in v0.3.1

func (r *CRD) ReconcileRequeuOnSuccessSeconds() int

ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue the custom resource as int, if specified in generator config.

func (*CRD) SDKAPIPackageName

func (r *CRD) SDKAPIPackageName() string

SDKAPIPackageName returns the aws-sdk-go package name used for this resource's API

func (*CRD) SetAttributesSingleAttribute

func (r *CRD) SetAttributesSingleAttribute() bool

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

func (r *CRD) SpecFieldNames() []string

SpecFieldNames returns a sorted slice of field names for the Spec fields

func (*CRD) SpecIdentifierField added in v0.1.0

func (r *CRD) SpecIdentifierField() *string

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

func (r *CRD) TerminalExceptionCodes() []string

TerminalExceptionCodes returns terminal exception codes as []string for custom resource, if specified in generator config

func (*CRD) TypeRenames

func (r *CRD) TypeRenames() map[string]string

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

func (r *CRD) UnpacksAttributesMap() bool

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

func (r *CRD) UpdateConditionsCustomMethodName() string

UpdateConditionsCustomMethodName returns custom update conditions operation as *string for custom resource, if specified in generator config

type EnumDef

type EnumDef struct {
	Names  names.Names
	Values []EnumValue
}

EnumDef is the definition of an enumeration type for a field present in either a CRD or a TypeDef

func NewEnumDef

func NewEnumDef(names names.Names, values []string) (*EnumDef, error)

NewEnumDef returns a pointer to an `ackmodel.EnumDef` struct representing a constrained string value field

type EnumValue

type EnumValue struct {
	Original string
	Clean    string
}

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

func (f *Field) IsRequired() bool

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

func (m *Model) GetCRDs() ([]*CRD, error)

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

func (m *Model) GetEnumDefs() ([]*EnumDef, error)

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

func (m *Model) GetTypeDefs() ([]*TypeDef, error)

GetTypeDefs returns a slice of `TypeDef` pointers

func (*Model) IsShapeUsedInCRDs added in v0.5.0

func (m *Model) IsShapeUsedInCRDs(shapeName string) bool

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

func (m *Model) RemoveIgnoredOperations(ops *Ops)

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
const (
	OpTypeUnknown OpType = iota
	OpTypeCreate
	OpTypeCreateBatch
	OpTypeDelete
	OpTypeReplace
	OpTypeUpdate
	OpTypeAddChild
	OpTypeAddChildren
	OpTypeRemoveChild
	OpTypeRemoveChildren
	OpTypeGet
	OpTypeList
	OpTypeGetAttributes
	OpTypeSetAttributes
)

func GetOpTypeAndResourceNameFromOpID

func GetOpTypeAndResourceNameFromOpID(opID string) (OpType, string)

GetOpTypeAndResourceNameFromOpID guesses the resource name and type of operation from the OperationID

func OpTypeFromString

func OpTypeFromString(s string) OpType

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

func (a *SDKAPI) APIGroup() string

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

func (a *SDKAPI) GetInputShapeRef(
	opID string,
	path string,
) (*awssdkmodel.ShapeRef, bool)

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

func (a *SDKAPI) GetOutputShapeRef(
	opID string,
	path string,
) (*awssdkmodel.ShapeRef, bool)

GetOutputShapeRef finds a ShapeRef for a supplied member path (dot-notation) for given API operation

func (*SDKAPI) GetPayloads

func (a *SDKAPI) GetPayloads() []string

GetPayloads returns a slice of strings of Shape names representing input and output request/response payloads

func (*SDKAPI) GetServiceFullName

func (a *SDKAPI) GetServiceFullName() string

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

func (a *SDKAPI) SDKAPIInterfaceTypeName() string

SDKAPIInterfaceTypeName returns the name of the aws-sdk-go primary API interface type name.

func (*SDKAPI) ServiceID

func (a *SDKAPI) ServiceID() string

ServiceID returns the exact `metadata.serviceId` attribute for the AWS service APi's api-2.json file

func (*SDKAPI) ServiceIDClean

func (a *SDKAPI) ServiceIDClean() string

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

func NewSDKHelper(basePath string) *SDKHelper

NewSDKHelper returns a new SDKHelper object

func (*SDKHelper) API

func (h *SDKHelper) API(serviceAlias string) (*SDKAPI, error)

API returns the aws-sdk-go API model for a supplied service alias

func (*SDKHelper) FirstAPIVersion added in v0.6.0

func (h *SDKHelper) FirstAPIVersion(serviceAlias string) (string, error)

FirstAPIVersion returns the first found API version for a service API. (e.h. "2012-10-03")

func (*SDKHelper) GetAPIVersions added in v0.6.0

func (h *SDKHelper) GetAPIVersions(serviceAlias string) ([]string, error)

GetAPIVersions returns the list of API Versions found in a service directory.

func (*SDKHelper) ModelAndDocsPath

func (h *SDKHelper) ModelAndDocsPath(
	serviceAlias string,
) (string, string, error)

ModelAndDocsPath returns two string paths to the supplied service alias' model and doc JSON files

func (*SDKHelper) WithAPIVersion added in v0.6.0

func (h *SDKHelper) WithAPIVersion(apiVersion string)

WithAPIVersion sets the `apiVersion` field.

func (*SDKHelper) WithSDKVersion added in v0.6.0

func (h *SDKHelper) WithSDKVersion(version string) error

WithSDKVersion checks out the sdk git repository to the provided version. To use this function h.basePath should point to a git repository.

type TypeDef

type TypeDef struct {
	Names names.Names
	Attrs map[string]*Attr
	Shape *awssdkmodel.Shape
}

TypeDef is a Go type definition for structs that are member fields of the Spec or Status structs in Custom Resource Definitions (CRDs).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL