Skip to content

Commit 160151b

Browse files
authored
generate/internal/manifests.go: add all supported kinds to manifests (#4137)
* generate/internal/manifests.go: add all supported kinds to manifests * filter out webhook ports/services * add all services to manifests
1 parent 273f4a8 commit 160151b

11 files changed

+141
-14
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
entries:
2+
- description: When generating bundles and packagemanifests, add all resources supported by OLM.
3+
kind: change

internal/cmd/operator-sdk/generate/internal/manifests.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package genutil
1616

1717
import (
18+
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1819
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1920

2021
"github.com/operator-framework/operator-sdk/internal/generate/collector"
@@ -35,6 +36,19 @@ func GetManifestObjects(c *collector.Manifests) (objs []controllerutil.Object) {
3536
objs = append(objs, &c.ServiceAccounts[i])
3637
}
3738

39+
// All Services passed in should be written.
40+
for i := range c.Services {
41+
objs = append(objs, &c.Services[i])
42+
}
43+
44+
// Add all other supported kinds
45+
for i := range c.Others {
46+
obj := &c.Others[i]
47+
if supported, _ := bundle.IsSupported(obj.GroupVersionKind().Kind); supported {
48+
objs = append(objs, obj)
49+
}
50+
}
51+
3852
// RBAC objects that are not a part of the CSV should be written.
3953
_, roleObjs := c.SplitCSVPermissionsObjects()
4054
objs = append(objs, roleObjs...)

internal/olm/operator/uninstall.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
v1 "github.com/operator-framework/api/pkg/operators/v1"
2424
"github.com/operator-framework/api/pkg/operators/v1alpha1"
25+
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
2526
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2728
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -211,13 +212,12 @@ func (u *Uninstall) getInstallPlanResources(ctx context.Context, installPlanKey
211212
Kind: step.Resource.Kind,
212213
})
213214

214-
// TODO(joelanford): This seems necessary for service accounts tied to
215-
// cluster roles and cluster role bindings because the SA namespace
216-
// is not set in the manifest in this case.
215+
// TODO(joelanford): This seems necessary for namespaced resources
217216
// See: https://github.com/operator-framework/operator-lifecycle-manager/blob/c9405d035bc50d9aa290220cb8d75b0402e72707/pkg/controller/registry/resolver/rbac.go#L133
218-
if step.Resource.Kind == "ServiceAccount" && obj.GetNamespace() == "" {
217+
if supported, namespaced := bundle.IsSupported(step.Resource.Kind); supported && bool(namespaced) {
219218
obj.SetNamespace(installPlanKey.Namespace)
220219
}
220+
221221
switch step.Resource.Kind {
222222
case "CustomResourceDefinition":
223223
crds = append(crds, obj)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: ServiceMonitor
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: memcached-operator-controller-manager-metrics-monitor
7+
spec:
8+
endpoints:
9+
- path: /metrics
10+
port: https
11+
selector:
12+
matchLabels:
13+
control-plane: controller-manager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
control-plane: controller-manager
7+
name: memcached-operator-controller-manager-metrics-service
8+
spec:
9+
ports:
10+
- name: https
11+
port: 8443
12+
targetPort: https
13+
selector:
14+
control-plane: controller-manager
15+
status:
16+
loadBalancer: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: ServiceMonitor
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: memcached-operator-controller-manager-metrics-monitor
7+
spec:
8+
endpoints:
9+
- path: /metrics
10+
port: https
11+
selector:
12+
matchLabels:
13+
control-plane: controller-manager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
control-plane: controller-manager
7+
name: memcached-operator-controller-manager-metrics-service
8+
spec:
9+
ports:
10+
- name: https
11+
port: 8443
12+
targetPort: https
13+
selector:
14+
control-plane: controller-manager
15+
status:
16+
loadBalancer: {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
name: memcached-operator-webhook-service
6+
spec:
7+
ports:
8+
- port: 443
9+
targetPort: 9443
10+
selector:
11+
control-plane: controller-manager
12+
status:
13+
loadBalancer: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: ServiceMonitor
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: memcached-operator-controller-manager-metrics-monitor
7+
spec:
8+
endpoints:
9+
- path: /metrics
10+
port: https
11+
selector:
12+
matchLabels:
13+
control-plane: controller-manager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
control-plane: controller-manager
7+
name: memcached-operator-controller-manager-metrics-service
8+
spec:
9+
ports:
10+
- name: https
11+
port: 8443
12+
targetPort: https
13+
selector:
14+
control-plane: controller-manager
15+
status:
16+
loadBalancer: {}

website/content/en/docs/olm-integration/generation.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ should be set to `0.0.1`. You've also built your operator image, `quay.io/<user>
7171

7272
### Bundle format
7373

74-
A [bundle][bundle] consists of manifests (CSV and CRDs) and metadata that define an Operator
75-
at a particular version. You may have also heard of a bundle image. From the bundle docs:
74+
A [bundle][bundle] consists of manifests (CSV, CRDs, and other supported kinds) and metadata that define an Operator
75+
at a particular version, and an optional [scorecard][scorecard] configuration file. You may have also heard of a
76+
bundle image. From the bundle docs:
7677

7778
> An Operator Bundle is built as a scratch (non-runnable) container image that
7879
> contains operator manifests and specific metadata in designated directories
@@ -86,17 +87,25 @@ bundle images become important once you're ready to [publish][operatorhub] your
8687
SDK projects are scaffolded with a `Makefile` containing the `bundle` recipe by default,
8788
which wraps `generate kustomize manifests`, `generate bundle`, and other related commands.
8889

89-
By default `make bundle` will generate a CSV, copy CRDs, and generate metadata in the bundle format:
90+
By default `make bundle` will generate a CSV, copy CRDs and other supported kinds, generate metadata,
91+
and add your scorecard configuration in the bundle format:
9092

9193
```console
9294
$ make bundle
9395
$ tree ./bundle
9496
./bundle
9597
├── manifests
96-
│   ├── cache.my.domain_memcacheds.yaml
97-
│   └── memcached-operator.clusterserviceversion.yaml
98-
└── metadata
99-
└── annotations.yaml
98+
│   ├── cache.example.com_memcacheds.yaml
99+
│   ├── memcached-operator.clusterserviceversion.yaml
100+
│   ├── memcached-operator-controller-manager-metrics-monitor_monitoring.coreos.com_v1_servicemonitor.yaml
101+
│   ├── memcached-operator-controller-manager-metrics-service_v1_service.yaml
102+
│   ├── memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1beta1_clusterrole.yaml
103+
│   └── memcached-operator-webhook-service_v1_service.yaml
104+
├── metadata
105+
│   └── annotations.yaml
106+
└── tests
107+
└── scorecard
108+
└── config.yaml
100109
```
101110

102111
Bundle metadata in `bundle/metadata/annotations.yaml` contains information about a particular Operator version
@@ -146,9 +155,9 @@ bundle: ...
146155

147156
### Package manifests format
148157

149-
A [package manifests][package-manifests] format consists of on-disk manifests (CSV and CRDs) and metadata that
150-
define an Operator at all versions of that Operator. Each version is contained in its own directory, with a parent
151-
package manifest YAML file containing channel-to-version mappings, much like a bundle's metadata.
158+
A [package manifests][package-manifests] format consists of on-disk manifests (CSV, CRDs and other supported kinds)
159+
and metadata that define an Operator at all versions of that Operator. Each version is contained in its own directory,
160+
with a parent package manifest YAML file containing channel-to-version mappings, much like a bundle's metadata.
152161

153162
If your Operator is already formatted as a package manifests and you do not wish to migrate to the bundle format yet,
154163
you should add the following to your `Makefile` to make development easier:
@@ -310,3 +319,4 @@ being managed, each with a `name` and `url`.
310319
[olm-capabilities]:/docs/advanced-topics/operator-capabilities/operator-capabilities
311320
[csv-markers]:/docs/building-operators/golang/references/markers
312321
[operatorhub]:https://operatorhub.io/
322+
[scorecard]:/docs/advanced-topics/scorecard

0 commit comments

Comments
 (0)