model

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 13 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",
	)
)

Functions

func ReplacePkgName added in v0.0.2

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/aws-controllers-k8s/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 CRD

type CRD struct {
	Names  names.Names
	Kind   string
	Plural string
	// Ops are the CRUD operations controlling this resource
	Ops Ops
	// AdditionalPrinterColumns is an array of PrinterColumn objects
	// representing the printer column settings for the CRD
	// AdditionalPrinterColumns field.
	AdditionalPrinterColumns []*PrinterColumn
	// 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
	// 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) AddPrintableColumn added in v0.0.2

func (r *CRD) AddPrintableColumn(
	field *Field,
	jsonPath string,
) *PrinterColumn

AddPrintableColumn adds an entry to the list of additional printer columns using the given path and field types.

func (*CRD) AddSpecField

func (r *CRD) AddSpecField(
	memberNames names.Names,
	shapeRef *awssdkmodel.ShapeRef,
) *Field

AddSpecField adds a new Field of a given name and shape into the Spec field of a CRD

func (*CRD) AddSpecPrintableColumn added in v0.0.2

func (r *CRD) AddSpecPrintableColumn(
	field *Field,
) *PrinterColumn

AddSpecPrintableColumn adds an entry to the list of additional printer columns using the path of the given spec field.

func (*CRD) AddStatusField

func (r *CRD) AddStatusField(
	memberNames names.Names,
	shapeRef *awssdkmodel.ShapeRef,
) *Field

AddStatusField adds a new Field of a given name and shape into the Status field of a CRD

func (*CRD) AddStatusPrintableColumn added in v0.0.2

func (r *CRD) AddStatusPrintableColumn(
	field *Field,
) *PrinterColumn

AddStatusPrintableColumn adds an entry to the list of additional printer columns using the path of the given status field.

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) CompareIgnoredFields

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

CompareIgnoredFields returns the list of fields compare logic should ignore

func (*CRD) Config added in v0.0.2

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) 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) 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) 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) 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) ListOpMatchFieldNames added in v0.0.2

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) NameField

func (r *CRD) NameField() string

NameField returns the name of the "Name" or string identifier field in the Spec

func (*CRD) SDKAPIPackageName added in v0.0.2

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) TerminalExceptionCodes

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

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

func (*CRD) TypeRenames added in v0.0.2

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 added in v0.0.2

type Field struct {
	CRD               *CRD
	Names             names.Names
	GoType            string
	GoTypeElem        string
	GoTypeWithPkgName string
	ShapeRef          *awssdkmodel.ShapeRef
	FieldConfig       *ackgenconfig.FieldConfig
}

Field represents a single field in the CRD's Spec or Status objects

func (*Field) IsRequired added in v0.0.2

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 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 added in v0.0.2

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 added in v0.0.2

func (ops Ops) IterOps() []*awssdkmodel.Operation

IterOps returns a slice of Operations for a resource

type PrinterColumn added in v0.0.2

type PrinterColumn struct {
	CRD      *CRD
	Name     string
	Type     string
	JSONPath string
}

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 added in v0.0.2

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 added in v0.0.2

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) APIVersion

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

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

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

type TypeDef

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

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

Jump to

Keyboard shortcuts

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