Skip to content

Commit 966e9a9

Browse files
authored
Use loadModel instead of loadModelWithLatestAPIVersion for crossplane (#240)
getLatestAPIVersion doesn't seem to work correctly with crossplane, and opgGenVersion is already used to find the configuration path for resources, so just use that instead. Issue #, if available: Description of changes: By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent bbae305 commit 966e9a9

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

cmd/ack-generate/command/common.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ func loadModelWithLatestAPIVersion(svcAlias string) (*ackmodel.Model, error) {
221221
if err != nil {
222222
return nil, err
223223
}
224-
return loadModel(svcAlias, latestAPIVersion)
224+
return loadModel(svcAlias, latestAPIVersion, "", ackgenerate.DefaultConfig)
225225
}
226226

227227
// loadModel finds the AWS SDK for a given service alias and creates a new model
228228
// with the given API version.
229-
func loadModel(svcAlias string, apiVersion string) (*ackmodel.Model, error) {
230-
cfg, err := ackgenconfig.New(optGeneratorConfigPath, ackgenerate.DefaultConfig)
229+
func loadModel(svcAlias string, apiVersion string, apiGroup string, defaultCfg ackgenconfig.Config) (*ackmodel.Model, error) {
230+
231+
cfg, err := ackgenconfig.New(optGeneratorConfigPath, defaultCfg)
231232
if err != nil {
232233
return nil, err
233234
}
@@ -250,6 +251,11 @@ func loadModel(svcAlias string, apiVersion string) (*ackmodel.Model, error) {
250251
return nil, fmt.Errorf("service %s not found", svcAlias)
251252
}
252253
}
254+
255+
if apiGroup != "" {
256+
sdkAPI.APIGroupSuffix = apiGroup
257+
}
258+
253259
m, err := ackmodel.New(
254260
sdkAPI, svcAlias, apiVersion, cfg,
255261
)

cmd/ack-generate/command/crossplane.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ func generateCrossplane(_ *cobra.Command, args []string) error {
4242
if len(args) != 1 {
4343
return fmt.Errorf("please specify the service alias for the AWS service API to generate")
4444
}
45+
4546
ctx, cancel := contextWithSigterm(context.Background())
4647
defer cancel()
4748
if err := ensureSDKRepo(ctx, optCacheDir, optRefreshCache); err != nil {
4849
return err
4950
}
5051
svcAlias := strings.ToLower(args[0])
5152
optGeneratorConfigPath = filepath.Join(optOutputPath, "apis", svcAlias, optGenVersion, "generator-config.yaml")
52-
m, err := loadModelWithLatestAPIVersion(
53-
svcAlias,
54-
)
53+
m, err := loadModel(svcAlias, optGenVersion, "aws.crossplane.io", cpgenerate.DefaultConfig)
5554
if err != nil {
5655
return err
5756
}

cmd/ack-generate/command/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func generateRelease(cmd *cobra.Command, args []string) error {
7373
if err := ensureSDKRepo(ctx, optCacheDir, optRefreshCache); err != nil {
7474
return err
7575
}
76-
m, err := loadModel(svcAlias, "")
76+
m, err := loadModel(svcAlias, "", "", ackgenerate.DefaultConfig)
7777
if err != nil {
7878
return err
7979
}

templates/crossplane/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This folder includes the templates to generate AWS Crossplane Provider. Run the
44
following to generate:
55

66
```console
7-
go run -tags codegen cmd/ack-generate/main.go crossplane apis ecr --output <directory for provider>
7+
go run -tags codegen cmd/ack-generate/main.go crossplane <resource name> \
8+
--output <directory for provider>
89
```
910

1011
See [Contributing New Resource Using ACK](https://github.com/crossplane/provider-aws/blob/master/CODE_GENERATION.md)

0 commit comments

Comments
 (0)