-
Notifications
You must be signed in to change notification settings - Fork 204
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
Create pipeline stage to generate list of supported resources #1791
Merged
+280
−3
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a5ee176
Create pipeline stage to generate list of supported resources
theunrepentantgeek 97dace8
Generate resource summary for ARM
theunrepentantgeek 66c1a0c
Code gardening
theunrepentantgeek 6446fa0
Update pipeline docs
theunrepentantgeek cc98e7d
Add header
theunrepentantgeek a483989
Merge branch 'master' into feature/resources-report
theunrepentantgeek 2762a68
Remove unused function
theunrepentantgeek 0adb8d3
Add resourses.md for crossplane
theunrepentantgeek eb27783
Remove reporting stage for crossplane tests
theunrepentantgeek 2105685
Merge branch 'master' into feature/resources-report
Porges a0a8ae5
Fix merge
theunrepentantgeek c647c04
Merge branch 'master' into feature/resources-report
theunrepentantgeek 6f9e5d5
Code gardening
theunrepentantgeek 6f733b0
Merge branch 'master' into feature/resources-report
theunrepentantgeek 3799969
Merge branch 'master' into feature/resources-report
theunrepentantgeek b30efd1
Merge branch 'master' into feature/resources-report
theunrepentantgeek 24483b3
Update resources.md
theunrepentantgeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### microsoft.cache | ||
|
||
v1alpha1api20200601 | ||
|
||
- Redis | ||
|
||
### microsoft.sql | ||
|
||
v1alpha1api20201101preview | ||
|
||
- Server | ||
- ServersDatabase | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
### microsoft.batch | ||
|
||
v1alpha1api20210101 | ||
|
||
- BatchAccount | ||
|
||
### microsoft.compute | ||
|
||
v1alpha1api20200930 | ||
|
||
- Disk | ||
|
||
v1alpha1api20201201 | ||
|
||
- VirtualMachineScaleSet | ||
|
||
### microsoft.containerservice | ||
|
||
v1alpha1api20210501 | ||
|
||
- ManagedCluster | ||
- ManagedClustersAgentPool | ||
|
||
### microsoft.documentdb | ||
|
||
v1alpha1api20210515 | ||
|
||
- DatabaseAccount | ||
|
||
### microsoft.managedidentity | ||
|
||
v1alpha1api20181130 | ||
|
||
- UserAssignedIdentity | ||
|
||
### microsoft.network | ||
|
||
v1alpha1api20201101 | ||
|
||
- LoadBalancer | ||
- NetworkSecurityGroup | ||
- NetworkSecurityGroupsSecurityRule | ||
- PublicIPAddress | ||
- VirtualNetwork | ||
- VirtualNetworkGateway | ||
- VirtualNetworkTap | ||
- VirtualNetworksSubnet | ||
- VirtualNetworksVirtualNetworkPeering | ||
|
||
### microsoft.servicebus | ||
|
||
v1alpha1api20210101preview | ||
|
||
- Namespace | ||
- NamespacesQueue | ||
- NamespacesTopic | ||
|
||
### microsoft.storage | ||
|
||
v1alpha1api20210401 | ||
|
||
- StorageAccount | ||
- StorageAccountsBlobService | ||
- StorageAccountsBlobServicesContainer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
hack/generator/pkg/codegen/pipeline/report_resource_versions.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" | ||
"github.com/Azure/azure-service-operator/hack/generator/pkg/config" | ||
) | ||
|
||
// ReportResourceVersionsStageID is the unique identifier of this stage | ||
const ReportResourceVersionsStageID = "reportResourceVersions" | ||
|
||
// ReportResourceVersions creates a pipeline stage that generates a report listing all generated resources. | ||
func ReportResourceVersions(configuration *config.Configuration) Stage { | ||
|
||
return MakeStage( | ||
ReportResourceVersionsStageID, | ||
"Generate a report listing all the resources generated", | ||
func(ctx context.Context, state *State) (*State, error) { | ||
report := NewResourceVersionsReport(state.Types()) | ||
err := report.WriteTo(configuration.FullTypesOutputPath()) | ||
return state, err | ||
}) | ||
} | ||
|
||
type ResourceVersionsReport struct { | ||
// A separate list of resources for each package | ||
lists map[astmodel.PackageReference][]string | ||
} | ||
|
||
func NewResourceVersionsReport(types astmodel.Types) *ResourceVersionsReport { | ||
result := &ResourceVersionsReport{ | ||
lists: make(map[astmodel.PackageReference][]string), | ||
} | ||
|
||
result.summarize(types) | ||
return result | ||
} | ||
|
||
// summarize collates a list of all resources, grouped by package | ||
func (r *ResourceVersionsReport) summarize(types astmodel.Types) { | ||
resources := astmodel.FindResourceTypes(types) | ||
for _, rsrc := range resources { | ||
name := rsrc.Name() | ||
pkg := name.PackageReference | ||
r.lists[pkg] = append(r.lists[pkg], name.Name()) | ||
} | ||
} | ||
|
||
// WriteTo creates a file containing the generated report | ||
func (r *ResourceVersionsReport) WriteTo(outputPath string) error { | ||
var buffer strings.Builder | ||
r.WriteToBuffer(&buffer) | ||
|
||
if _, err := os.Stat(outputPath); os.IsNotExist(err) { | ||
err = os.MkdirAll(outputPath, 0700) | ||
if err != nil { | ||
return errors.Wrapf(err, "Unable to create directory %q", outputPath) | ||
} | ||
} | ||
|
||
destination := path.Join(outputPath, "resources.md") | ||
return ioutil.WriteFile(destination, []byte(buffer.String()), 0600) | ||
} | ||
|
||
// WriteToBuffer creates the report in the provided buffer | ||
func (r *ResourceVersionsReport) WriteToBuffer(buffer *strings.Builder) { | ||
// Sort packages into increasing order | ||
// Skip storage versions | ||
var packages []astmodel.PackageReference | ||
for pkg := range r.lists { | ||
if !astmodel.IsStoragePackageReference(pkg) { | ||
packages = append(packages, pkg) | ||
} | ||
} | ||
|
||
astmodel.SortPackageReferencesByPathAndVersion(packages) | ||
|
||
lastService := "" | ||
for _, pkg := range packages { | ||
|
||
// Write a header for each service | ||
svc := r.serviceName(pkg) | ||
if lastService != svc { | ||
buffer.WriteString(fmt.Sprintf("### %s\n\n", svc)) | ||
lastService = svc | ||
} | ||
|
||
// For each version, write an alphabetical list of resources | ||
buffer.WriteString(fmt.Sprintf("%s\n\n", pkg.PackageName())) | ||
|
||
resources := r.lists[pkg] | ||
sort.Strings(resources) | ||
|
||
for _, rsrc := range resources { | ||
buffer.WriteString(fmt.Sprintf("- %s\n", rsrc)) | ||
} | ||
|
||
buffer.WriteString("\n") | ||
} | ||
} | ||
|
||
func (r *ResourceVersionsReport) serviceName(ref astmodel.PackageReference) string { | ||
pathBits := strings.Split(ref.PackagePath(), "/") | ||
index := len(pathBits) - 1 | ||
if index > 0 { | ||
index-- | ||
} | ||
|
||
return pathBits[index] | ||
} |
54 changes: 54 additions & 0 deletions
54
hack/generator/pkg/codegen/pipeline/report_resource_versions_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/sebdah/goldie/v2" | ||
|
||
"github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" | ||
"github.com/Azure/azure-service-operator/hack/generator/pkg/test" | ||
) | ||
|
||
func TestGolden_ReportResourceVersions(t *testing.T) { | ||
g := goldie.New(t) | ||
|
||
person2020 := test.CreateResource( | ||
test.Pkg2020, | ||
"Person", | ||
test.CreateSpec(test.Pkg2020, "Person"), | ||
test.CreateStatus(test.Pkg2020, "Person")) | ||
|
||
address2020 := test.CreateResource( | ||
test.Pkg2020, | ||
"Address", | ||
test.CreateSpec(test.Pkg2020, "Address"), | ||
test.CreateStatus(test.Pkg2020, "Address")) | ||
|
||
person2021 := test.CreateResource( | ||
test.Pkg2021, | ||
"Person", | ||
test.CreateSpec(test.Pkg2021, "Person"), | ||
test.CreateStatus(test.Pkg2021, "Person")) | ||
|
||
address2021 := test.CreateResource( | ||
test.Pkg2021, | ||
"Address", | ||
test.CreateSpec(test.Pkg2021, "Address"), | ||
test.CreateStatus(test.Pkg2021, "Address")) | ||
|
||
types := make(astmodel.Types) | ||
types.AddAll(person2020, address2020, person2021, address2021) | ||
|
||
report := NewResourceVersionsReport(types) | ||
|
||
var buffer strings.Builder | ||
report.WriteToBuffer(&buffer) | ||
|
||
g.Assert(t, t.Name(), []byte(buffer.String())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
hack/generator/pkg/codegen/pipeline/testdata/TestGolden_ReportResourceVersions.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### microsoft.person | ||
|
||
v20200101 | ||
|
||
- Address | ||
- Person | ||
|
||
v20211231 | ||
|
||
- Address | ||
- Person | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider bolding this for emphasis?
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.
It's the only thing on the line, and it's followed by a bullet list, so I don't think it needs further emphasis.