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

Commit

Permalink
operator: changes to generate olm-catalog for OperatorHub
Browse files Browse the repository at this point in the history
Used operator-sdk to generate base manifests and olm-catalog files and
using kustomize patch the CSV file with specific changes. These files
could be pushed to 'community-operators' for publishing
pmem-csi-operator on OperatorHub.
  • Loading branch information
avalluri committed Aug 20, 2020
1 parent eb41855 commit f0fa93c
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 16 deletions.
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/crd
/deploy/olm-catalog
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
{
# Kubebuilder configuration version
version: "2",
domain: "pmem-csi.intel.com",
repo: "github.com/intel/pmem-csi/pkg/pmem-csi-operator",
projectName: "pmem-csi-operator"
}
11 changes: 3 additions & 8 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,8 @@ kind: Deployment
metadata:
name: pmem-csi.intel.com
spec:
deviceMode: "lvm"
pmemPercentage: 50
controllerResources:
requests:
cpu: "200m"
memory: "100Mi"
nodeResources:
requests:
cpu: "200m"
memory: "100Mi"
nodeSelector:
storage: "pmem"

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions deploy/kustomize/olm-catalog/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
newTag: X.Y.Z # this should be replaced with real version number

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/
$ 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
47 changes: 46 additions & 1 deletion operator/operator.make
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OPERATOR_SDK_VERSION=v0.16.0
OPERATOR_SDK_VERSION=v1.0.0

# download operator-sdk binary
_work/bin/operator-sdk-$(OPERATOR_SDK_VERSION):
Expand All @@ -12,3 +12,48 @@ _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION):
# 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
SHORT_VERSION=$(shell echo $(VERSION) | cut -f1,2 -d'.')

# Generate CRD and add kustomizaiton 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
trap '$(MAKE) operator-clean-crd' EXIT
@echo "Generating base catalog ..."
@sed -i -e 's;X.Y.Z;$(VERSION);g' $(MANIFESTS_DIR)/kustomization.yaml
trap "sed -i -e 's;$(VERSION);X.Y.Z;g' $(MANIFESTS_DIR)/kustomization.yaml" EXIT
@_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

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

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

// +kubebuilder:validation:Enum=lvm,direct
const (
// DeviceModeLVM represents 'lvm' device manager
DeviceModeLVM DeviceMode = "lvm"
Expand All @@ -49,10 +50,9 @@ const (

// 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 +65,10 @@ 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: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 @@ -88,6 +90,9 @@ type DeploymentSpec struct {
// 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
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=100
// +kubebuilder:default=50
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 @@ -108,7 +113,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
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.

0 comments on commit f0fa93c

Please sign in to comment.