Skip to content

Commit 1d5377d

Browse files
author
Nicholas Thomson
committed
Refactor service naming variables
1 parent b6b4012 commit 1d5377d

File tree

12 files changed

+48
-42
lines changed

12 files changed

+48
-42
lines changed

cmd/ack-generate/command/apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func generateAPIs(cmd *cobra.Command, args []string) error {
112112
}
113113
}
114114
model, err := ackmodel.New(
115-
sdkAPI, svcAlias, optGenVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
115+
sdkAPI, svcAlias, optModelName, optGenVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
116116
)
117117
if err != nil {
118118
return err

cmd/ack-generate/command/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func generateController(cmd *cobra.Command, args []string) error {
8282
return err
8383
}
8484
m, err := ackmodel.New(
85-
sdkAPI, svcAlias, latestAPIVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
85+
sdkAPI, svcAlias, optModelName, latestAPIVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
8686
)
8787
if err != nil {
8888
return err

cmd/ack-generate/command/crossplane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func generateCrossplane(_ *cobra.Command, args []string) error {
8080
cfgPath = ""
8181
}
8282
m, err := ackmodel.New(
83-
sdkAPI, svcAlias, optGenVersion, cfgPath, cpgenerate.DefaultConfig,
83+
sdkAPI, svcAlias, optModelName, optGenVersion, cfgPath, cpgenerate.DefaultConfig,
8484
)
8585
if err != nil {
8686
return err

cmd/ack-generate/command/olm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func generateOLMAssets(cmd *cobra.Command, args []string) error {
107107
return err
108108
}
109109
m, err := ackmodel.New(
110-
sdkAPI, svcAlias, latestAPIVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
110+
sdkAPI, svcAlias, optModelName, latestAPIVersion, optGeneratorConfigPath, ackgenerate.DefaultConfig,
111111
)
112112
if err != nil {
113113
return err

cmd/ack-generate/command/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func generateRelease(cmd *cobra.Command, args []string) error {
9090
}
9191
}
9292
m, err := ackmodel.New(
93-
sdkAPI, svcAlias, "", optGeneratorConfigPath, ackgenerate.DefaultConfig,
93+
sdkAPI, svcAlias, optModelName, "", optGeneratorConfigPath, ackgenerate.DefaultConfig,
9494
)
9595
if err != nil {
9696
return err

pkg/generate/crossplane/crossplane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func Crossplane(
145145
for _, path := range apisGenericTemplatesPaths {
146146
outPath := filepath.Join(
147147
"apis",
148-
metaVars.ServiceIDClean,
148+
metaVars.ServiceAliasClean,
149149
metaVars.APIVersion,
150150
"zz_"+strings.TrimSuffix(filepath.Base(path), ".tpl"),
151151
)
@@ -155,7 +155,7 @@ func Crossplane(
155155
}
156156
for _, crd := range crds {
157157
crdFileName := filepath.Join(
158-
"apis", metaVars.ServiceIDClean, metaVars.APIVersion,
158+
"apis", metaVars.ServiceAliasClean, metaVars.APIVersion,
159159
"zz_"+strcase.ToSnake(crd.Kind)+".go",
160160
)
161161
crdVars := &templateCRDVars{
@@ -170,7 +170,7 @@ func Crossplane(
170170
// Next add the controller package for each CRD
171171
for _, crd := range crds {
172172
outPath := filepath.Join(
173-
"pkg", "controller", metaVars.ServiceIDClean, crd.Names.Lower,
173+
"pkg", "controller", metaVars.ServiceAliasClean, crd.Names.Lower,
174174
"zz_controller.go",
175175
)
176176
crdVars := &templateCRDVars{
@@ -181,7 +181,7 @@ func Crossplane(
181181
return nil, err
182182
}
183183
outPath = filepath.Join(
184-
"pkg", "controller", metaVars.ServiceIDClean, crd.Names.Lower,
184+
"pkg", "controller", metaVars.ServiceAliasClean, crd.Names.Lower,
185185
"zz_conversions.go",
186186
)
187187
crdVars = &templateCRDVars{

pkg/generate/olm/olm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func BundleAssets(
7979

8080
csvBaseOutPath := fmt.Sprintf(
8181
"config/manifests/bases/ack-%s-controller.clusterserviceversion.yaml",
82-
m.MetaVars().ServiceIDClean)
82+
m.MetaVars().ServiceAliasClean)
8383
if err := ts.Add(csvBaseOutPath, "config/manifests/bases/clusterserviceversion.yaml.tpl", olmVars); err != nil {
8484
return nil, err
8585
}

pkg/generate/templateset/vars.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ package templateset
1616
// MetaVars contains template variables that most templates need access to
1717
// that describe the service alias, its package name, etc
1818
type MetaVars struct {
19+
// ServiceModelName contains the exact string used to identify the AWS
20+
// service API in the aws-sdk-go's models/apis/ directory. Note that some
21+
// APIs this name does not match the ServiceID. e.g. The AWS Step Functions
22+
// API has a ServiceID of "SFN" and a service model name of "states"...
23+
ServiceModelName string
24+
// ServiceAliasClean is the ServiceAlias lowercased and stripped of any
25+
// non-alphanumeric characters
26+
ServiceAliasClean string
1927
// ServiceAlias contains the exact string used to identify the AWS service
20-
// API in the aws-sdk-go's models/apis/ directory. Note that some APIs this
21-
// alias does not match the ServiceID. e.g. The AWS Step Functions API has
22-
// a ServiceID of "SFN" and a service alias of "states"...
28+
// API in the aws-sdk-go's packages. It is also used as the identifier for
29+
// the ACK controller's name and packages.
2330
ServiceAlias string
24-
// ServiceIDClean is the ServiceID lowercased and stripped of any
25-
// non-alphanumeric characters
26-
ServiceIDClean string
2731
// APIVersion contains the version of the Kubernetes API resources, e.g.
2832
// "v1alpha1"
2933
APIVersion string
3034
// APIGroup contains the normalized name of the Kubernetes APIGroup used
3135
// for custom resources, e.g. "sns.services.k8s.aws" or
3236
// "sfn.services.k8s.aws"
3337
APIGroup string
34-
// AWSSDKModelServiceID is the exact string that appears in the AWS service API's
38+
// ServiceID is the exact string that appears in the AWS service API's
3539
// api-2.json descriptor file under `metadata.serviceId`
36-
AWSSDKModelServiceID string
40+
ServiceID string
3741
// SDKAPIInterfaceTypeName is the name of the interface type used by the
3842
// aws-sdk-go services/$SERVICE/api.go file
3943
SDKAPIInterfaceTypeName string

pkg/model/model.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ var (
3434
// Model contains the ACK model for the generator to process and apply
3535
// templates against.
3636
type Model struct {
37-
SDKAPI *SDKAPI
38-
servicePackage string
39-
serviceAlias string
40-
apiVersion string
41-
crds []*CRD
42-
typeDefs []*TypeDef
43-
typeImports map[string]string
44-
typeRenames map[string]string
37+
SDKAPI *SDKAPI
38+
serviceAlias string
39+
serviceModelName string
40+
apiVersion string
41+
crds []*CRD
42+
typeDefs []*TypeDef
43+
typeImports map[string]string
44+
typeRenames map[string]string
4545
// Instructions to the code generator how to handle the API and its
4646
// resources
4747
cfg *ackgenconfig.Config
@@ -51,11 +51,11 @@ type Model struct {
5151
// service API
5252
func (m *Model) MetaVars() templateset.MetaVars {
5353
return templateset.MetaVars{
54-
ServiceAlias: m.serviceAlias,
55-
ServiceIDClean: m.ServiceIDClean(),
54+
ServiceAliasClean: m.ServiceAliasClean(),
55+
ServiceModelName: m.serviceModelName,
5656
APIGroup: m.APIGroup(),
5757
APIVersion: m.apiVersion,
58-
AWSSDKModelServiceID: m.SDKAPI.AWSSDKModelServiceID(),
58+
ServiceID: m.SDKAPI.ServiceID(),
5959
SDKAPIInterfaceTypeName: m.SDKAPI.SDKAPIInterfaceTypeName(),
6060
CRDNames: m.crdNames(),
6161
}
@@ -695,17 +695,17 @@ func (m *Model) GetConfig() *ackgenconfig.Config {
695695
// APIGroup returns the normalized Kubernetes APIGroup for the AWS service API,
696696
// e.g. "sns.services.k8s.aws"
697697
func (m *Model) APIGroup() string {
698-
serviceID := m.servicePackage
698+
serviceID := m.serviceAlias
699699
suffix := "services.k8s.aws"
700700
if m.SDKAPI.apiGroupSuffix != "" {
701701
suffix = m.SDKAPI.apiGroupSuffix
702702
}
703703
return fmt.Sprintf("%s.%s", serviceID, suffix)
704704
}
705705

706-
// ServiceIDClean returns a lowercased, whitespace-stripped ServiceID
707-
func (m *Model) ServiceIDClean() string {
708-
serviceID := strings.ToLower(m.servicePackage)
706+
// ServiceAliasClean returns a lowercased, whitespace-stripped ServiceID
707+
func (m *Model) ServiceAliasClean() string {
708+
serviceID := strings.ToLower(m.serviceAlias)
709709
return strings.Replace(serviceID, " ", "", -1)
710710
}
711711

@@ -714,7 +714,8 @@ func (m *Model) ServiceIDClean() string {
714714
// instruct the code generator how to handle the API properly
715715
func New(
716716
SDKAPI *SDKAPI,
717-
servicePackage string,
717+
serviceAlias string,
718+
serviceModelName string,
718719
apiVersion string,
719720
configPath string,
720721
defaultConfig ackgenconfig.Config,
@@ -724,11 +725,11 @@ func New(
724725
return nil, err
725726
}
726727
m := &Model{
727-
SDKAPI: SDKAPI,
728-
servicePackage: servicePackage,
729-
serviceAlias: SDKAPI.AWSSDKModelServiceID(),
730-
apiVersion: apiVersion,
731-
cfg: &cfg,
728+
SDKAPI: SDKAPI,
729+
serviceAlias: serviceAlias,
730+
serviceModelName: serviceModelName,
731+
apiVersion: apiVersion,
732+
cfg: &cfg,
732733
}
733734
m.ApplyShapeIgnoreRules()
734735
return m, nil

pkg/model/multiversion/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func NewAPIVersionManager(
103103
i, err := ackmodel.New(
104104
SDKAPI,
105105
serviceAlias,
106+
serviceModelName,
106107
version.APIVersion,
107108
apiInfo.GeneratorConfigPath,
108109
defaultConfig,

0 commit comments

Comments
 (0)