Skip to content

Commit 7705657

Browse files
Merge pull request #1185 from dprince/respin
Reduce the operator bundle sizes
2 parents 39c4136 + 5cb58c2 commit 7705657

File tree

166 files changed

+81415
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+81415
-139
lines changed

.github/workflows/build-openstack-operator.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
go_version: 1.21.x
1919
operator_sdk_version: 1.31.0
2020
bundle_dockerfile: ./bundle.Dockerfile
21-
catalog_extra_bundles_script: ./hack/pin-bundle-images.sh
2221
secrets:
2322
IMAGENAMESPACE: ${{ secrets.IMAGENAMESPACE }}
2423
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*.dll
66
*.so
77
*.dylib
8-
bin
8+
bin/*
99
testbin/*
1010

1111
bundle/*

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ repos:
2626
args: ['operator-lint']
2727
pass_filenames: false
2828
- id: make-crd-schema-check
29+
require_serial: true
2930
name: make-crd-schema-check
3031
language: system
3132
entry: make
3233
args: ['crd-schema-check']
34+
- id: make-bindata
35+
require_serial: true
36+
name: make-bindata
37+
language: system
38+
entry: make
39+
args: ['bindata']
3340
pass_filenames: false
3441

3542
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -47,6 +54,7 @@ repos:
4754
- id: destroyed-symlinks
4855
- id: check-yaml
4956
args: [-m]
57+
exclude: '^bindata/operator|^config/operator'
5058
- id: check-json
5159
- id: detect-private-key
5260
- id: end-of-file-fixer

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ RUN if [ ! -f $CACHITO_ENV_FILE ]; then go mod download ; fi
2626

2727
# Build manager
2828
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; env ${GO_BUILD_EXTRA_ENV_ARGS} go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/manager main.go
29+
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; env ${GO_BUILD_EXTRA_ENV_ARGS} go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/operator cmd/operator/main.go
2930

3031
RUN cp -r config/services ${DEST_ROOT}/services
32+
RUN cp -r bindata ${DEST_ROOT}/bindata
3133

3234
# Use distroless as minimal base image to package the manager binary
3335
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -65,9 +67,11 @@ WORKDIR /
6567

6668
# Install operator binary to WORKDIR
6769
COPY --from=builder ${DEST_ROOT}/manager .
70+
COPY --from=builder ${DEST_ROOT}/operator .
6871

6972
# Install services
7073
COPY --from=builder ${DEST_ROOT}/services ${OPERATOR_SERVICES}
74+
COPY --from=builder ${DEST_ROOT}/bindata /bindata
7175

7276
USER $USER_ID
7377

Makefile

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,30 @@ help: ## Display this help.
131131

132132
##@ Development
133133

134+
# (dprince) FIXME: controller-gen crd didn't seem to like multiple paths so I didn't split it. So we can continue using kubebuilder
135+
# I did split out the rbac for both binaries so we can use separate roles
134136
.PHONY: manifests
135137
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
136-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd$(CRDDESC_OVERRIDE) webhook paths="./..." output:crd:artifacts:config=config/crd/bases && \
138+
mkdir -p config/operator/rbac && \
139+
$(CONTROLLER_GEN) crd$(CRDDESC_OVERRIDE) output:crd:artifacts:config=config/crd/bases webhook paths="./..." && \
140+
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="{./apis/client/...,./apis/core/...,./apis/dataplane/...,./controllers/client/...,./controllers/core/...,./controllers/dataplane/...,./pkg/...}" output:dir=config/rbac && \
141+
$(CONTROLLER_GEN) rbac:roleName=operator-role paths="./controllers/operator/..." paths="./apis/operator/..." output:dir=config/operator/rbac && \
137142
rm -f apis/bases/* && cp -a config/crd/bases apis/
138143

139144
.PHONY: generate
140145
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
141146
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
142147

148+
.PHONY: bindata
149+
bindata: kustomize yq ## Build docker image with the manager.
150+
mkdir -p bindata/crds bindata/rbac bindata/operator
151+
$(KUSTOMIZE) build config/crd > bindata/crds/crds.yaml
152+
$(KUSTOMIZE) build config/default > bindata/operator/operator.yaml
153+
cp config/operator/managers.yaml bindata/operator/
154+
cp config/operator/rabbit.yaml bindata/operator/
155+
$(KUSTOMIZE) build config/rbac > bindata/rbac/rbac.yaml
156+
/bin/bash hack/sync-bindata.sh
157+
143158
.PHONY: fmt
144159
fmt: ## Run go fmt against code.
145160
go fmt ./...
@@ -196,6 +211,7 @@ cover: test ## Run tests and display functional test coverage
196211
.PHONY: build
197212
build: generate fmt vet ## Build manager binary.
198213
go build -o bin/manager main.go
214+
go build -o bin/operator cmd/operator/main.go
199215

200216
.PHONY: run
201217
run: export METRICS_PORT?=8080
@@ -206,8 +222,18 @@ run: manifests generate fmt vet ## Run a controller from your host.
206222
source hack/export_related_images.sh && \
207223
go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)"
208224

225+
.PHONY: run-operator
226+
run-operator: export METRICS_PORT?=8080
227+
run-operator: export HEALTH_PORT?=8081
228+
run-operator: export ENABLE_WEBHOOKS?=false
229+
run-operator: export BASE_BINDATA?=bindata
230+
run-operator: export OPERATOR_IMAGE_URL=${IMG}
231+
run-operator: manifests generate fmt vet ## Run a controller from your host.
232+
source hack/export_operator_related_images.sh && \
233+
go run ./cmd/operator/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)"
234+
209235
.PHONY: docker-build
210-
docker-build: ## Build docker image with the manager.
236+
docker-build: ## Build docker image with the manager.
211237
podman build -t ${IMG} . ${DOCKER_BUILD_ARGS}
212238

213239
.PHONY: docker-push
@@ -272,7 +298,7 @@ GINKGO_TESTS ?= ./tests/... ./apis/client/... ./apis/core/... ./apis/dataplane/.
272298
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
273299

274300
## Tool Versions
275-
KUSTOMIZE_VERSION ?= v3.8.7
301+
KUSTOMIZE_VERSION ?= v5.5.0 #(dprince: bumped to aquire new features like --load-restrictor)
276302
CONTROLLER_TOOLS_VERSION ?= v0.14.0
277303
CRD_MARKDOWN_VERSION ?= v0.0.3
278304
KUTTL_VERSION ?= 0.17.0
@@ -340,11 +366,10 @@ endif
340366
.PHONY: bundle
341367
bundle: build manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
342368
$(OPERATOR_SDK) generate kustomize manifests -q
343-
cd config/manager && \
344-
$(KUSTOMIZE) edit set image controller=$(IMG) && \
345-
$(KUSTOMIZE) edit add patch --kind Deployment --name controller-manager --namespace system --patch "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/env/0\", \"value\": {\"name\": \"OPENSTACK_RELEASE_VERSION\", \"value\": \"$(OPENSTACK_RELEASE_VERSION)\"}}]"
346-
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
347-
cp dependencies.yaml ./bundle/metadata
369+
cd config/operator/deployment/ && $(KUSTOMIZE) edit set image controller=$(IMG) && \
370+
$(KUSTOMIZE) edit add patch --kind Deployment --name openstack-operator-controller-operator --namespace system --patch "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/env/0\", \"value\": {\"name\": \"OPENSTACK_RELEASE_VERSION\", \"value\": \"$(OPENSTACK_RELEASE_VERSION)\"}}]" && \
371+
$(KUSTOMIZE) edit add patch --kind Deployment --name openstack-operator-controller-operator --namespace system --patch "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/env/1\", \"value\": {\"name\": \"OPERATOR_IMAGE_URL\", \"value\": \"$(IMG)\"}}]"
372+
$(KUSTOMIZE) build config/operator --load-restrictor='LoadRestrictionsNone' | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
348373
$(OPERATOR_SDK) bundle validate ./bundle
349374

350375
.PHONY: bundle-build

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ resources:
7777
kind: OpenStackDataPlaneDeployment
7878
path: github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1
7979
version: v1beta1
80+
- api:
81+
crdVersion: v1
82+
namespaced: true
83+
controller: true
84+
domain: openstack.org
85+
group: operator
86+
kind: OpenStack
87+
path: github.com/openstack-k8s-operators/openstack-operator/apis/operator/v1beta1
88+
version: v1beta1
8089
version: "3"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.14.0
7+
name: openstacks.operator.openstack.org
8+
spec:
9+
group: operator.openstack.org
10+
names:
11+
kind: OpenStack
12+
listKind: OpenStackList
13+
plural: openstacks
14+
singular: openstack
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- jsonPath: .status.deployedOperatorCount
19+
name: Deployed Operator Count
20+
type: integer
21+
- description: Status
22+
jsonPath: .status.conditions[0].status
23+
name: Status
24+
type: string
25+
name: v1beta1
26+
schema:
27+
openAPIV3Schema:
28+
properties:
29+
apiVersion:
30+
type: string
31+
kind:
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
type: object
37+
status:
38+
properties:
39+
conditions:
40+
items:
41+
properties:
42+
lastTransitionTime:
43+
format: date-time
44+
type: string
45+
message:
46+
type: string
47+
reason:
48+
type: string
49+
severity:
50+
type: string
51+
status:
52+
type: string
53+
type:
54+
type: string
55+
required:
56+
- lastTransitionTime
57+
- status
58+
- type
59+
type: object
60+
type: array
61+
deployedOperatorCount:
62+
type: integer
63+
observedGeneration:
64+
format: int64
65+
type: integer
66+
type: object
67+
type: object
68+
served: true
69+
storage: true
70+
subresources:
71+
status: {}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package v1beta1
17+
18+
import (
19+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
20+
)
21+
22+
// OpenStack Condition Types used by API objects.
23+
const (
24+
// OpenStackOperatorReadyCondition Status=True condition which indicates if operators have been deployed
25+
OpenStackOperatorReadyCondition condition.Type = "OpenStackOperatorReadyCondition"
26+
)
27+
28+
// Common Messages used by Openstack operator
29+
const (
30+
//
31+
// OpenStackOperator condition messages
32+
//
33+
34+
// OpenStackOperatorErrorMessage
35+
OpenStackOperatorErrorMessage = "OpenStackOperator error occured %s"
36+
37+
// OpenStackOperatorReadyInitMessage
38+
OpenStackOperatorReadyInitMessage = "OpenStackOperator not started"
39+
40+
// OpenStackOperatorReadyRunningMessage
41+
OpenStackOperatorReadyRunningMessage = "OpenStackOperator in progress"
42+
43+
// OpenStackOperatorReadyMessage
44+
OpenStackOperatorReadyMessage = "OpenStackOperator completed"
45+
46+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the operator v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=operator.openstack.org
20+
package v1beta1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "operator.openstack.org", Version: "v1beta1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// OpenStackSpec defines the desired state of OpenStack
25+
type OpenStackSpec struct {
26+
}
27+
28+
// OpenStackStatus defines the observed state of OpenStack
29+
type OpenStackStatus struct {
30+
31+
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
32+
// Conditions
33+
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`
34+
35+
// DeployedOperatorCount - the number of operators deployed
36+
DeployedOperatorCount *int `json:"deployedOperatorCount,omitempty"`
37+
38+
// ObservedGeneration - the most recent generation observed for this object.
39+
ObservedGeneration int64 `json:"observedGeneration,omitempty"` // no spec yet so maybe we don't need this
40+
}
41+
42+
// +kubebuilder:object:root=true
43+
// +kubebuilder:subresource:status
44+
// +kubebuilder:printcolumn:name="Deployed Operator Count",type=integer,JSONPath=`.status.deployedOperatorCount`
45+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
46+
// OpenStack is the Schema for the openstacks API
47+
type OpenStack struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ObjectMeta `json:"metadata,omitempty"`
50+
51+
Spec OpenStackSpec `json:"spec,omitempty"`
52+
Status OpenStackStatus `json:"status,omitempty"`
53+
}
54+
55+
//+kubebuilder:object:root=true
56+
57+
// OpenStackList contains a list of OpenStack
58+
type OpenStackList struct {
59+
metav1.TypeMeta `json:",inline"`
60+
metav1.ListMeta `json:"metadata,omitempty"`
61+
Items []OpenStack `json:"items"`
62+
}
63+
64+
func init() {
65+
SchemeBuilder.Register(&OpenStack{}, &OpenStackList{})
66+
}

0 commit comments

Comments
 (0)