Skip to content

Commit b8e4d33

Browse files
committed
updates based on PR comments
1 parent 9fe38ec commit b8e4d33

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

doc/design/milestone-0.2.0/csv-generation.md

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ The `operator-sdk generate olm-catalog` command currently produces a generic CSV
1414

1515
## Proposed Solution
1616

17-
Functionality of `operator-sdk generate olm-catalog` is now a branch in `operator-sdk build`, specifically when called with the `--gen-csv` flag; the former command no longer exists. `operator-sdk build quay.io/example/operator:v0.0.1 --gen-csv"` writes a CSV yaml file using the operators' current version to the `deploy/olm-catalog` directory by default. `deploy` is the standard location for all manifests and scripts required to deploy an operator. The SDK can use data from manifests in `deploy` to write a CSV. Users may have different requirements for what should (not) be included in a CSV, and can configure CSV composition via `deploy/olm-catalog/csv-config.yaml`, described below.
17+
Functionality of `operator-sdk generate olm-catalog` is now in `operator-sdk build --gen-csv`; the former command no longer exists. `operator-sdk build quay.io/example/operator:v0.0.1 --gen-csv` writes a CSV yaml file using the operators' current version to the `deploy/olm-catalog` directory by default. Version is parsed from the image name argument, ex. `0.0.1` from `quay.io/example/operator:v0.0.1`.
18+
19+
`deploy` is the standard location for all manifests required to deploy an operator. The SDK can use data from manifests in `deploy` to write a CSV. Exactly three types of manifests are required to generate a CSV: `operator.yaml`, `*_{crd,cr}.yaml`, and RBAC role files, ex. `role.yaml`. Users may have different versioning requirements for these files and can configure CSV which specific files are included in `deploy/olm-catalog/csv-config.yaml`, described below.
1820

1921
Assuming all configuration defaults are used, `operator-sdk build` will call `scaffold.Execute()`, which will either:
2022

@@ -28,15 +30,17 @@ Assuming all configuration defaults are used, `operator-sdk build` will call `sc
2830
1. Update an existing CSV at the currently pre-defined location, using available data in yaml manifests and source files.
2931

3032
1. The update mechanism will check for an existing CSV in `deploy`. Upon finding one, the CSV yaml file contents will be marshalled into a `ClusterServiceVersion` cache.
31-
1. Same as above.
32-
1. Same as above.
33+
1. The update mechanism will search `deploy` for manifests that contain data a CSV uses, such as a `Deployment` Kubernetes API resource, and set the appropriate CSV fields in the cache with this data.
34+
1. Once the search completes, every cache field populated will be written back to a CSV yaml file.
35+
- **Note:** individual yaml fields are overwritten and not the entire file, as descriptions and other non-generated parts of a CSV should be preserved.
3336

3437
### Configuration
3538

3639
Users can configure CSV composition by populating several fields in the file `deploy/olm-catalog/csv-config.yaml`:
3740

38-
- `search-directory`: (string) the directory to search for yaml manifest files. Defaults to `deploy`.
39-
- `exclude-files`: ([string[, string]*]) files that match any string in the list are not included in the CSV search; glob matching allowed. Defaults to empty.
41+
- `operator-path`: (string) the operator resource manifest file path. Defaults to `deploy/operator.yaml`.
42+
- `crd-cr-path-list`: ([string[, string]\*]) a list of CRD and CR manifest file paths. Defaults to `[deploy/crds/*_{crd,cr}.yaml]`.
43+
- `rbac-path-list`: ([string[, string]\*]) a list of RBAC role manifest file paths. Defaults to `[deploy/role.yaml]`.
4044

4145
### Extensible `CSVUpdater` CSV update mechanism
4246

@@ -46,7 +50,7 @@ The CSV spec will likely change over time as new Kubernetes and OLM features are
4650
import "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
4751

4852
type CSVUpdater interface {
49-
Apply(*v1alpha1.ClusterServiceVersion) error
53+
Apply(*v1alpha1.ClusterServiceVersion) error
5054
}
5155
```
5256

@@ -58,7 +62,6 @@ The following is an example implementation of an [install strategy][olm_csv_inst
5862

5963
```Go
6064
import (
61-
...
6265
appsv1 "k8s.io/api/apps/v1"
6366
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
6467
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
@@ -67,65 +70,65 @@ import (
6770

6871
// CSVInstallStrategyUpdate embeds the OLM's install strategy spec.
6972
type CSVInstallStrategyUpdate struct {
70-
*install.StrategyDetailsDeployment
71-
72-
// Future utility fields go here.
73+
*install.StrategyDetailsDeployment
74+
75+
// Future fields go here.
7376
}
7477

7578
// getLocalInstallStrategyCache retrieves the local cache singleton and returns the install strategy cache.
7679
func getLocalInstallStrategyCache() *CSVInstallStrategyUpdate {
77-
factory := getLocalCacheFactory()
78-
return factory.InstallStrategyCache
80+
factory := getLocalCacheFactory()
81+
return factory.InstallStrategyCache
7982
}
8083

8184
// AddDeploymentSpecToCSVInstallStrategyUpdate adds an RBAC Role to the local cache singletons' permissions.
8285
func AddRoleToCSVInstallStrategyUpdate(yamlDoc []byte) error {
83-
localInstallStrategyUpdate := getLocalInstallStrategyCache()
86+
localInstallStrategyUpdate := getLocalInstallStrategyCache()
8487

85-
newRBACRole := new(rbacv1beta1.Role)
86-
_ = yaml.Unmarshal(yamlDoc, newRBACRole)
88+
newRBACRole := new(rbacv1beta1.Role)
89+
_ = yaml.Unmarshal(yamlDoc, newRBACRole)
8790

88-
newPermissions := install.StrategyDeploymentPermissions{
89-
ServiceAccountName: newRole.ObjectMeta.Name,
90-
Rules: newRole.Rules,
91-
}
92-
localInstallStrategyUpdate.Permissions = append(localInstallStrategyUpdate.Permissions, newPermissions)
91+
newPermissions := install.StrategyDeploymentPermissions{
92+
ServiceAccountName: newRole.ObjectMeta.Name,
93+
Rules: newRole.Rules,
94+
}
95+
localInstallStrategyUpdate.Permissions = append(localInstallStrategyUpdate.Permissions, newPermissions)
9396

94-
return nil
97+
return nil
9598
}
9699

97100
// AddDeploymentSpecToCSVInstallStrategyUpdate adds a Deployment to the local cache singletons' install strategy.
98101
func AddDeploymentSpecToCSVInstallStrategyUpdate(yamlDoc []byte) error {
99-
localInstallStrategyUpdate := getLocalInstallStrategyCache()
100-
101-
newDeployment := new(appsv1.Deployment)
102-
_ = yaml.Unmarshal(yamlDoc, newDeployment)
103-
104-
newDeploymentSpec := install.StrategyDeploymentSpec{
105-
Name: newDeployment.ObjectMeta.Name,
106-
Spec: newDeployment.Spec,
107-
}
108-
localInstallStrategyUpdate.DeploymentSpecs = append(localInstallStrategyUpdate.DeploymentSpecs, newDeploymentSpec)
109-
110-
return nil
102+
localInstallStrategyUpdate := getLocalInstallStrategyCache()
103+
104+
newDeployment := new(appsv1.Deployment)
105+
_ = yaml.Unmarshal(yamlDoc, newDeployment)
106+
107+
newDeploymentSpec := install.StrategyDeploymentSpec{
108+
Name: newDeployment.ObjectMeta.Name,
109+
Spec: newDeployment.Spec,
110+
}
111+
localInstallStrategyUpdate.DeploymentSpecs = append(localInstallStrategyUpdate.DeploymentSpecs, newDeploymentSpec)
112+
113+
return nil
111114
}
112115

113116
// Apply applies cached updates in CSVInstallStrategyUpdate to the appropriate csv fields.
114117
func (us *CSVInstallStrategyUpdate) Apply(csv *v1alpha1.ClusterServiceVersion) error {
115-
// Get install strategy from csv.
116-
var resolver *install.StrategyResolver
117-
strat, _ := resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
118-
installStrat, _ := strat.(*install.StrategyDetailsDeployment)
118+
// Get install strategy from csv.
119+
var resolver *install.StrategyResolver
120+
strat, _ := resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
121+
installStrat, _ := strat.(*install.StrategyDetailsDeployment)
119122

120-
// Update permissions and deployments with custom field update methods.
121-
us.updatePermissions(installStrat)
122-
us.updateDeploymentSpecs(installStrat)
123+
// Update permissions and deployments with custom field update methods.
124+
us.updatePermissions(installStrat)
125+
us.updateDeploymentSpecs(installStrat)
123126

124-
// Re-serialize permissions into csv install strategy.
125-
updatedStrat, _ := json.Marshal(installStrat)
126-
csv.Spec.InstallStrategy.StrategySpecRaw = updatedStrat
127+
// Re-serialize permissions into csv install strategy.
128+
updatedStrat, _ := json.Marshal(installStrat)
129+
csv.Spec.InstallStrategy.StrategySpecRaw = updatedStrat
127130

128-
return nil
131+
return nil
129132
}
130133
```
131134

@@ -143,7 +146,7 @@ Required:
143146
- `spec.provider`: the operators' provider, with a `name`; usually an organization.
144147
- `spec.labels`: 1..N `key`:`value` pairs to be used by operator internals.
145148
- `spec.version`: semantic version of the operator, ex. `0.1.1`.
146-
- `spec.customresourcedefinitions`: any CRD's the operator uses. This field will be populated automatically by the SDK if any CRD yaml files are present in `deploy`; however, several fields require user input (more details in the [CSV CRD spec section][olm_csv_crd_doc]):
149+
- `spec.customresourcedefinitions`: any CRD's the operator uses. This field will be populated automatically by the SDK if any CRD yaml files are present in `deploy`; however, several fields not in the CRD manifest spec that require user input (more details in the [CSV CRD spec section][olm_csv_crd_doc]):
147150
- `description`: description of the CRD.
148151
- `resources`: any Kubernetes resources leveraged by the CRD, ex. `Pod`'s, `StatefulSet`'s.
149152
- `specDescriptors`: UI hints for inputs and outputs of the operator.
@@ -173,4 +176,4 @@ The CSV version is the same as the operators', and should be included somewhere
173176
[olm_csv_spec_code]:https://github.com/operator-framework/operator-lifecycle-manager/blob/8799f39ef342dc1ff7430eba7a88c1c3c70cbdcc/pkg/api/apis/operators/v1alpha1/clusterserviceversion_types.go
174177
[olm_csv_spec_doc]:https://github.com/operator-framework/operator-lifecycle-manager/blob/16ff8f983b50503c4d8b8015bd0c14b5c7d6786a/Documentation/design/building-your-csv.md#building-a-cluster-service-version-csv-for-the-operator-framework
175178
[olm_csv_install_strat_doc]:https://github.com/operator-framework/operator-lifecycle-manager/blob/16ff8f983b50503c4d8b8015bd0c14b5c7d6786a/Documentation/design/building-your-csv.md#operator-install
176-
[olm_csv_crd_doc]:https://github.com/operator-framework/operator-lifecycle-manager/blob/16ff8f983b50503c4d8b8015bd0c14b5c7d6786a/Documentation/design/building-your-csv.md#owned-crds
179+
[olm_csv_crd_doc]:https://github.com/operator-framework/operator-lifecycle-manager/blob/16ff8f983b50503c4d8b8015bd0c14b5c7d6786a/Documentation/design/building-your-csv.md#owned-crds

0 commit comments

Comments
 (0)