Skip to content

Commit 3bbfdaa

Browse files
committed
use upstream csv structs instead of local representations
1 parent 764bd1b commit 3bbfdaa

File tree

7 files changed

+598
-187
lines changed

7 files changed

+598
-187
lines changed

cmd/ack-generate/command/olm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ func generateOLMAssets(cmd *cobra.Command, args []string) error {
121121

122122
// set the base metadata and then override values as
123123
// defined by the service config.
124-
svcMeta := ackmodel.NewOLMMetadata() // TODO this can take in variables
125-
if err = yaml.Unmarshal(svcConfigYAML, &svcMeta); err != nil {
124+
svcConf := olmgenerate.DefaultServiceConfig()
125+
if err = yaml.Unmarshal(svcConfigYAML, &svcConf); err != nil {
126126
fmt.Println("unable to convert olm configuration file to data instance")
127127
return err
128128
}
129129

130130
// prepare the common metadata
131-
commonMeta := ackmodel.OLMCommonMetadata{}
131+
commonMeta := olmgenerate.CommonMetadata{}
132132
if !optDisableCommonLinks {
133-
commonMeta.Links = ackmodel.CommonLinks
133+
commonMeta.Links = olmgenerate.CommonLinks
134134
}
135135

136136
if !optDisableCommonKeywords {
137-
commonMeta.Keywords = ackmodel.CommonKeywords
137+
commonMeta.Keywords = olmgenerate.CommonKeywords
138138
}
139139

140140
// generate templates
141-
ts, err := olmgenerate.BundleAssets(g, commonMeta, svcMeta, version, optTemplatesDir)
141+
ts, err := olmgenerate.BundleAssets(g, commonMeta, svcConf, version, optTemplatesDir)
142142
if err != nil {
143143
return err
144144
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/ghodss/yaml v1.0.0
1212
github.com/iancoleman/strcase v0.1.3
1313
github.com/mitchellh/go-homedir v1.1.0
14+
github.com/operator-framework/api v0.6.0
1415
github.com/pkg/errors v0.9.1
1516
github.com/spf13/cobra v1.1.1
1617
github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 464 additions & 0 deletions
Large diffs are not rendered by default.

pkg/generate/olm/olm.go

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/aws-controllers-k8s/code-generator/pkg/generate"
1010
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset"
1111
ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model"
12+
opsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1213
)
1314

1415
var (
@@ -39,14 +40,12 @@ var (
3940
// a bundle used for deploying a service via OLM.
4041
func BundleAssets(
4142
g *generate.Generator,
42-
commonMeta ackmodel.OLMCommonMetadata,
43-
serviceMeta ackmodel.OLMMetadata,
43+
commonMeta CommonMetadata,
44+
serviceConfig ServiceConfig,
4445
vers string,
4546
templateBasePath string,
4647
) (*templateset.TemplateSet, error) {
4748

48-
createdAt := time.Now().Format("2006-01-02 15:04:05")
49-
5049
ts := templateset.New(
5150
templateBasePath,
5251
csvIncludePaths,
@@ -61,10 +60,10 @@ func BundleAssets(
6160

6261
olmVars := templateOLMVars{
6362
vers,
64-
createdAt,
63+
time.Now().Format("2006-01-02 15:04:05"),
6564
g.MetaVars(),
6665
commonMeta,
67-
serviceMeta,
66+
serviceConfig,
6867
crds,
6968
}
7069

@@ -93,7 +92,45 @@ type templateOLMVars struct {
9392
Version string
9493
CreatedAt string
9594
templateset.MetaVars
96-
Common ackmodel.OLMCommonMetadata
97-
ackmodel.OLMMetadata
95+
Common CommonMetadata
96+
ServiceConfig
9897
CRDs []*ackmodel.CRD
9998
}
99+
100+
// DefaultServiceConfig returns a default representation of ServiceConfig to be
101+
// used as a base. The various values are expected to be overridden (if
102+
// needed) by an input YAML manifest for the given service controller.
103+
func DefaultServiceConfig() ServiceConfig {
104+
return ServiceConfig{
105+
Annotations{
106+
Repository: "https://github.com/aws-controllers-k8s",
107+
SuggestedNamespace: "ack-system",
108+
ShortDescription: "This is the placeholder short description for the default configuration",
109+
IsCertified: false,
110+
ContainerImage: "public.ecr.aws/aws-controllers-k8s/controller",
111+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LDExMy41LTIzLjJDMjc0LjIsMTMzLjYsMjc4LjksMTM5LjcsMjczLjUsMTQzLjd6Ii8+CgkJPHBhdGggY2xhc3M9InN0MSIgZD0iTTI4Ny4yLDEyOC4xYy00LjItNS40LTI3LjgtMi42LTM4LjUtMS4zYy0zLjIsMC40LTMuNy0yLjQtMC44LTQuNWMxOC44LTEzLjIsNDkuNy05LjQsNTMuMy01ICAgIGMzLjYsNC41LTEsMzUuNC0xOC42LDUwLjJjLTIuNywyLjMtNS4zLDEuMS00LjEtMS45QzI4Mi41LDE1NS43LDI5MS40LDEzMy40LDI4Ny4yLDEyOC4xeiIvPgoJPC9nPgo8L2c+Cjwvc3ZnPg==",
120+
MediaType: mediatypeSVG,
121+
},
122+
},
123+
Provider: opsv1alpha1.AppLink{
124+
Name: "Amazon, Inc.",
125+
URL: "https://aws.amazon.com",
126+
},
127+
128+
InstallModes: []opsv1alpha1.InstallMode{
129+
{
130+
Type: opsv1alpha1.InstallModeTypeAllNamespaces,
131+
Supported: true,
132+
},
133+
},
134+
},
135+
}
136+
}

pkg/generate/olm/types.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package olm
2+
3+
import opsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
4+
5+
var (
6+
capabilityBasicInstall = "basic install"
7+
capabilitySeamlessUpgrades = "seamless upgrades"
8+
capabilityFullLifecucle = "full lifecycle"
9+
capabilityDeepInsights = "deep insights"
10+
capabilityAutoPilot = "auto pilot"
11+
12+
mediatypeGIF = "image/gif"
13+
mediatypeJPG = "image/jpeg"
14+
mediatypePNG = "image/png"
15+
mediatypeSVG = "image/svg+xml"
16+
)
17+
18+
// ServiceConfig represents a service controller's OLM configuration
19+
// input.
20+
type ServiceConfig struct {
21+
Annotations Annotations `json:"annotations"`
22+
Samples []Sample `json:"samples"`
23+
opsv1alpha1.ClusterServiceVersionSpec
24+
}
25+
26+
// CommonMetadata represents common metadata for all service controllers
27+
// generated by this project.
28+
type CommonMetadata struct {
29+
Links []opsv1alpha1.AppLink `json:"links"`
30+
Keywords []string `json:"keywords"`
31+
}
32+
33+
// CommonLinks are links that are likely to be common across service
34+
// controllers.
35+
var CommonLinks = []opsv1alpha1.AppLink{
36+
{
37+
Name: "AWS Controllers for Kubernetes",
38+
URL: "https://github.com/aws-controllers-k8s/community",
39+
},
40+
{
41+
Name: "Documentation",
42+
URL: "https://aws-controllers-k8s.github.io/community/",
43+
},
44+
}
45+
46+
// CommonKeywords are keywords that are likely to be common across
47+
// service controllers.
48+
var CommonKeywords = []string{
49+
"aws",
50+
"amazon",
51+
"ack",
52+
}
53+
54+
// Annotations represent metadata that is added to the ClusterServiceVersion
55+
// yaml. These keys inform the OLM graphical user interface.
56+
type Annotations struct {
57+
CapabilityLevel string `json:"capabilityLevel"`
58+
SuggestedNamespace string `json:"suggestedNamespace"`
59+
Repository string `json:"repository"`
60+
ContainerImage string `json:"containerImage"`
61+
ShortDescription string `json:"shortDescription"`
62+
Support string `json:"support"`
63+
IsCertified bool `json:"isCertified"`
64+
}
65+
66+
// Sample is a basic representation of an instance of custom resource
67+
// managed by a given service controller.
68+
type Sample struct {
69+
Kind string `json:"kind"`
70+
Spec string `json:"spec"`
71+
DisplayName string `json:"displayName"`
72+
Description string `json:"description"`
73+
}

0 commit comments

Comments
 (0)