Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

operator: changes to generate olm-catalog for OperatorHub #695

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.tox
Manifest
/_build

/deploy/olm-catalog
/deploy/kustomize/olm-catalog/crd
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ clean:

.PHONY: all build test clean $(CMDS) $(TEST_CMDS)

include operator/operator.make

# Add support for creating and booting a cluster under QEMU.
# All of the commands operate on a cluster stored in _work/$(CLUSTER),
# which defaults to _work/clear-govm. This can be changed with
Expand All @@ -147,6 +145,8 @@ _work/kustomize: _work/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
tar xzf $< -C _work
touch $@

include operator/operator.make

# We generate deployment files with kustomize and include the output
# in the git repo because not all users will have kustomize or it
# might be an unsuitable version. When any file changes, update the
Expand Down
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Project configuration file used by controller-gen and operator-sdk tools
{
avalluri marked this conversation as resolved.
Show resolved Hide resolved
# Kubebuilder configuration version
version: "2",
domain: "pmem-csi.intel.com",
repo: "github.com/intel/pmem-csi/pkg/pmem-csi-operator",
projectName: "pmem-csi-operator"
}
12 changes: 3 additions & 9 deletions deploy/common/pmem-csi.intel.com_v1alpha1_deployment_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ kind: Deployment
metadata:
name: pmem-csi.intel.com
spec:
pmemPercentage: 50
controllerResources:
requests:
cpu: "200m"
memory: "100Mi"
nodeResources:
requests:
cpu: "200m"
memory: "100Mi"
deviceMode: "lvm"
nodeSelector:
avalluri marked this conversation as resolved.
Show resolved Hide resolved
storage: "pmem"

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions deploy/kustomize/olm-catalog/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bases:
- ./crd # this would be generated using: make operator-generate-crd
- ../operator

resources:
- ../../common/pmem-csi.intel.com_v1alpha1_deployment_cr.yaml

images:
- name: intel/pmem-csi-driver
# this version will be replaced during make operator-generate-catalog with the actual version number
newTag: vX.Y.Z

25 changes: 25 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Branching](#branching)
- [Tagging](#tagging)
- [Release checklist](#release-checklist)
- [Release PMEM-CSI operator](#release-PMEM-CSI-operator)
- [APIs](#apis)
- [CSI API](#csi-api)
- [Network ports](#network-ports)
Expand Down Expand Up @@ -151,6 +152,30 @@ Jenkinsfile ensures that.
Hub](https://hub.docker.com/r/intel/pmem-csi-driver/tags?page=1&ordering=last_updated).
* Publish the GitHub release.

### Release PMEM-CSI operator

Follow below steps to publish new operator release to [OperatorHub](https://operatorhub.io):

* Generate OLM catalog for new release
``` console
$ make operator-generate-catalog VERSION=<X.Y.Z> #semantic version number
```
Running the above command generates the OLM catalog files under `deploy/olm-catalog/<X.Y.Z>`

* Clone `operator-framework/community-operators` repository
``` console
$ git clone https://github.com/operator-framework/community-operators.git
```

* Copy generated catalog files. Commit the changes and submit a pull request to
[community-operators](https://github.com/operator-framework/community-operators) repository.
```console
$ cp -r <PMEM-CSI_ROOT>/deploy/olm-catalog/ <COMMUNITY-OPERATORS_ROOT>/upstream-community-operators/pmem-csi-operator/
pohly marked this conversation as resolved.
Show resolved Hide resolved
$ cd <COMMUNITY-OPERATORS_ROOT>
$ git add upstream-community-operators/pmem-csi-operator/
$ git commit -s -m "Updating PMEM-CSI Operator to version <X.Y.Z>"
```

## APIs

### CSI API
Expand Down
68 changes: 66 additions & 2 deletions operator/operator.make
Original file line number Diff line number Diff line change
@@ -1,14 +1,78 @@
OPERATOR_SDK_VERSION=v0.16.0
OPERATOR_SDK_VERSION=v1.0.0

# download operator-sdk binary
_work/bin/operator-sdk-$(OPERATOR_SDK_VERSION):
mkdir -p _work/bin/ 2> /dev/null
curl -L https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk-$(OPERATOR_SDK_VERSION)-x86_64-linux-gnu -o $(abspath $@)
# Building operator-sdk from sources as that needs below fixes:
# https://github.com/operator-framework/operator-sdk/pull/3787
# https://github.com/operator-framework/operator-sdk/pull/3786
# curl -L https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk-$(OPERATOR_SDK_VERSION)-x86_64-linux-gnu -o $(abspath $@)
tmpdir=`mktemp -d` && \
trap 'set -x; rm -rf $$tmpdir' EXIT && \
git clone --branch 1.0.0+fixes https://github.com/avalluri/operator-sdk.git $$tmpdir && \
cd $$tmpdir && $(MAKE) build/operator-sdk && \
cp $$tmpdir/build/operator-sdk $(abspath $@) && \
chmod a+x $(abspath $@)
cd $(dir $@); ln -sf operator-sdk-$(OPERATOR_SDK_VERSION) operator-sdk

# Re-generates the K8S source. This target is supposed to run
# upon any changes made to operator api.
#
# GOROOT is needed because of https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525132306
operator-generate-k8s: _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION)
GOROOT=$(shell $(GO) env GOROOT) _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION) generate k8s

# find or download if necessary controller-gen
# this make target is copied from Makefile generated
# by operator-sdk init
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e; \
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
GOPATH=$$($(GO) env GOPATH) ;\
$(GO) mod init tmp ;\
$(GO) get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR; \
}
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

MANIFESTS_DIR=deploy/kustomize/olm-catalog
CATALOG_DIR=deploy/olm-catalog
BUNDLE_DIR=deploy/bundle
SHORT_VERSION=$(shell echo $(VERSION) | cut -f1,2 -d'.')
KUBECONFIG := $(shell echo $(PWD)/_work/$(CLUSTER)/kube.config)
# Defaults to 0.7.0 release to generate catalog to use for e2e tests
VERSION := 0.7.0

# Generate CRD and add kustomization support
operator-generate-crd: controller-gen
@echo "Generating CRD ..."
$(CONTROLLER_GEN) crd:trivialVersions=true,crdVersions=v1beta1 paths=./pkg/apis/... output:dir=$(MANIFESTS_DIR)/crd/
@echo "resources: [pmem-csi.intel.com_deployments.yaml]" > $(MANIFESTS_DIR)/crd/kustomization.yaml

# Generate packagemanifests using operator-sdk.
operator-generate-catalog: _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION) _work/kustomize operator-generate-crd
@echo "Generating base catalog ..."
@_work/kustomize build --load_restrictor=none $(MANIFESTS_DIR) | $< generate packagemanifests --version $(VERSION) \
--kustomize-dir $(MANIFESTS_DIR) --output-dir $(CATALOG_DIR)
@sed -i -e 's;X.Y.Z;$(VERSION);g' -e 's;X.Y;$(SHORT_VERSION);g' $(CATALOG_DIR)/$(VERSION)/pmem-csi-operator.clusterserviceversion.yaml
$(MAKE) operator-clean-crd

# Generate OLM bundle. OperatorHub/OLM still does not support bundle format
# but soon it will move from 'packagemanifests' to 'bundles'.
operator-generate-bundle: _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION) _work/kustomize operator-generate-crd
@echo "Generating operator bundle ..."
@_work/kustomize build --load_restrictor=none $(MANIFESTS_DIR) | $< generate bundle --version=$(VERSION) \
--kustomize-dir=$(MANIFESTS_DIR) --output-dir=$(BUNDLE_DIR)
@sed -i -e 's;X.Y.Z;$(VERSION);g' -e 's;X.Y;$(SHORT_VERSION);g' $(CATALOG_DIR)/$(VERSION)/pmem-csi-operator.clusterserviceversion.yaml

operator-clean-crd:
rm -rf $(MANIFESTS_DIR)/crd

operator-clean-catalog:
rm -rf $(CATALOG_DIR)
24 changes: 19 additions & 5 deletions pkg/apis/pmemcsi/v1alpha1/deployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,26 @@ func (mode *DeviceMode) String() string {
return string(*mode)
}

// +kubebuilder:validation:Enum=lvm,direct
const (
// DeviceModeLVM represents 'lvm' device manager
DeviceModeLVM DeviceMode = "lvm"
// DeviceModeDirect represents 'direct' device manager
DeviceModeDirect DeviceMode = "direct"
)

// NOTE(avalluri): Due to below errors we stop setting
// few CRD schema fields by prefixing those lines a '-'.
// Once the below issues go fixed replace those '-' with '+'
// Setting default(+kubebuilder:default=value) for v1beta1 CRD fails, only supports since v1 CRD.
// Related issue : https://github.com/kubernetes-sigs/controller-tools/issues/478
// Fails setting min/max for integers: https://github.com/helm/helm/issues/5806
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an issue in our issue tracker for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still open.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// DeploymentSpec defines the desired state of Deployment
type DeploymentSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make operator-generate-k8s" to regenerate code after modifying this file

// Image holds container image options
// PMEM-CSI driver container image
Image string `json:"image,omitempty"`
// PullPolicy image pull policy one of Always, Never, IfNotPresent
PullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand All @@ -65,8 +72,11 @@ type DeploymentSpec struct {
// NodeResources Compute resources required by Node driver
NodeResources *corev1.ResourceRequirements `json:"nodeResources,omitempty"`
// DeviceMode to use to manage PMEM devices. One of lvm, direct
// +kubebuilder:default:lvm
DeviceMode DeviceMode `json:"deviceMode,omitempty"`
// LogLevel number for the log verbosity
// +kubebuilder:validation:Required
// kubebuilder:default=3
LogLevel uint16 `json:"logLevel,omitempty"`
// RegistryCert encoded certificate signed by a CA for registry server authentication
// If not provided, provisioned one by the operator using self-signed CA
Expand All @@ -86,8 +96,12 @@ type DeploymentSpec struct {
// NodeSelector node labels to use for selection of driver node
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// PMEMPercentage represents the percentage of space to be used by the driver in each PMEM region
// on every node. Default 100
// This is only valid for driver in LVM mode
// on every node.
// This is only valid for driver in LVM mode.
// +kubebuilder:validation:Required
// -kubebuilder:validation:Minimum=1
// -kubebuilder:validation:Maximum=100
// -kubebuilder:default=100
PMEMPercentage uint16 `json:"pmemPercentage,omitempty"`
// Labels contains additional labels for all objects created by the operator.
Labels map[string]string `json:"labels,omitempty"`
Expand All @@ -110,7 +124,7 @@ type DeploymentStatus struct {

// Deployment is the Schema for the deployments API
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=deployments,scope=Namespaced
// +kubebuilder:resource:path=deployments,scope=Cluster
pohly marked this conversation as resolved.
Show resolved Hide resolved
type Deployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pmemcsi/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading