-
Notifications
You must be signed in to change notification settings - Fork 226
Add service metadata configuration file #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
bc244b1
3fe7227
94b8b7b
312504d
ecd2144
21380e1
1dad7ad
f5c9d83
5f5a820
7967740
0e4c103
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,19 +11,16 @@ | |
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package multiversion | ||
|
|
||
| // TODO(a-hilaly) move this file outside of pkg/model/multiversion. Idealy we | ||
| // Should be able to access APIStatus and APIInfo to prevent regenerating removed or | ||
| // deprecated APIs. | ||
| package metadata | ||
|
|
||
| type APIStatus string | ||
|
|
||
| const ( | ||
| APIStatusUnknown APIStatus = "unknown" | ||
| APIStatusAvailable = "available" | ||
| APIStatusRemoved = "removed" | ||
| APIStatusDeprecated = "deprecated" | ||
| APIStatusUnknown APIStatus = "unknown" | ||
| APIStatusInDevelopment = "in_development" | ||
|
||
| APIStatusAvailable = "available" | ||
| APIStatusRemoved = "removed" | ||
| APIStatusDeprecated = "deprecated" | ||
| ) | ||
|
|
||
| // APIInfo contains information related a specific apiVersion. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package metadata | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
|
|
||
| "github.com/ghodss/yaml" | ||
| ) | ||
|
|
||
| // ServiceMetadata consists of information about the service and relative links as well | ||
| // as a list of supported/deprecated versions | ||
| type ServiceMetadata struct { | ||
| Service ServiceDetails `json:"service"` | ||
| // CRDs to ignore. ACK generator would skip these resources. | ||
RedbackThomson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Versions []ServiceVersion `json:"versions"` | ||
RedbackThomson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // ServiceDetails contains string identifiers and relevant links for the | ||
| // service | ||
| type ServiceDetails struct { | ||
| // The full display name for the service. eg. Amazon Elastic Kubernetes | ||
| // Service | ||
| FullName string `json:"full_name"` | ||
| // The short name (abbreviation) for the service. eg. S3 | ||
| ShortName string `json:"short_name"` | ||
| // The URL of the service's homepage | ||
| Link string `json:"link"` | ||
| // The URL of the service's main documentation/user guide | ||
| Documentation string `json:"documentation"` | ||
| } | ||
|
|
||
| // ServiceVersion describes the status of all existing version of the controller | ||
| type ServiceVersion struct { | ||
| APIVersion string `json:"api_version"` | ||
| Status APIStatus `json:"status"` | ||
| } | ||
|
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also add a boolean field called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am quite averse to the idea of the hub being anything other than the latest generated version - we rely on it being the latest for the common runtime elements to match. |
||
|
|
||
| func (m *ServiceMetadata) GetLatestAPIVersion() (string, error) { | ||
| availableVersions := m.GetAvailableAPIVersions() | ||
|
|
||
| if len(availableVersions) == 0 { | ||
| return "", fmt.Errorf("service metadata contains no available versions") | ||
RedbackThomson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return availableVersions[len(availableVersions)-1], nil | ||
| } | ||
|
|
||
| func (m *ServiceMetadata) GetDeprecatedAPIVersions() []string { | ||
| return m.getVersionsByStatus(APIStatusDeprecated) | ||
| } | ||
|
|
||
| func (m *ServiceMetadata) GetRemoveAPIVersions() []string { | ||
RedbackThomson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return m.getVersionsByStatus(APIStatusRemoved) | ||
| } | ||
|
|
||
| func (m *ServiceMetadata) GetAvailableAPIVersions() []string { | ||
| return m.getVersionsByStatus(APIStatusAvailable) | ||
| } | ||
|
|
||
| func (m *ServiceMetadata) GetDevelopmentAPIVersion() (string, error) { | ||
| devVersions := m.getVersionsByStatus(APIStatusInDevelopment) | ||
|
|
||
| if len(devVersions) == 0 { | ||
| return "", fmt.Errorf("service metadata contains no development versions") | ||
| } | ||
|
|
||
| if len(devVersions) > 1 { | ||
| return "", fmt.Errorf("service metadata contains multiple development versions") | ||
| } | ||
|
|
||
| return devVersions[0], nil | ||
| } | ||
|
|
||
| func (m *ServiceMetadata) getVersionsByStatus(status APIStatus) []string { | ||
| if len(m.Versions) == 0 { | ||
| return []string{} | ||
| } | ||
|
|
||
| versions := []string{} | ||
| for _, v := range m.Versions { | ||
| if v.Status == status { | ||
| versions = append(versions, v.APIVersion) | ||
| } | ||
| } | ||
| return versions | ||
| } | ||
|
|
||
| // NewServiceMetadata returns a new Metadata object given a supplied | ||
| // path to a metadata file | ||
| func NewServiceMetadata( | ||
| metadataPath string, | ||
| ) (ServiceMetadata, error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can return a |
||
| if metadataPath == "" { | ||
| return ServiceMetadata{}, fmt.Errorf("expected metadata file path, none provided") | ||
| } | ||
| content, err := ioutil.ReadFile(metadataPath) | ||
| if err != nil { | ||
| return ServiceMetadata{}, err | ||
| } | ||
| gc := ServiceMetadata{} | ||
| if err = yaml.Unmarshal(content, &gc); err != nil { | ||
| return ServiceMetadata{}, err | ||
| } | ||
| return gc, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
|
|
||
| ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset" | ||
| ackmetadata "github.com/aws-controllers-k8s/code-generator/pkg/metadata" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/names" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/util" | ||
| ) | ||
|
|
@@ -40,6 +41,8 @@ type Model struct { | |
| typeDefs []*TypeDef | ||
| typeImports map[string]string | ||
| typeRenames map[string]string | ||
| // Metadata for the service | ||
| meta *ackmetadata.ServiceMetadata | ||
|
||
| // Instructions to the code generator how to handle the API and its | ||
| // resources | ||
| cfg *ackgenconfig.Config | ||
|
|
@@ -699,9 +702,15 @@ func (m *Model) GetConfig() *ackgenconfig.Config { | |
| func New( | ||
| SDKAPI *SDKAPI, | ||
| apiVersion string, | ||
| metadataPath string, | ||
| configPath string, | ||
| defaultConfig ackgenconfig.Config, | ||
| ) (*Model, error) { | ||
| metadata, err := ackmetadata.NewServiceMetadata(metadataPath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| cfg, err := ackgenconfig.New(configPath, defaultConfig) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -713,6 +722,7 @@ func New( | |
| serviceAlias: SDKAPI.ServiceID(), | ||
| apiVersion: apiVersion, | ||
| cfg: &cfg, | ||
| meta: &metadata, | ||
| } | ||
| m.ApplyShapeIgnoreRules() | ||
| return m, nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where'd this come from? maybe remove it with
go mod tidy?