Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[controller] Add controllers for CephClusterConnection and CephStorageClass resources #3

Merged
merged 21 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
2 changes: 2 additions & 0 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ env:
MODULES_REGISTRY_PASSWORD: ${{ secrets.DEV_MODULES_REGISTRY_PASSWORD }}
RELEASE_CHANNEL: ${{ github.event.inputs.channel }}
MODULES_MODULE_TAG: ${{ github.event.inputs.tag }}
GOPROXY: ${{ secrets.GOPROXY }}
SOURCE_REPO: ${{ secrets.SOURCE_REPO }}

on:
workflow_dispatch:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ __pycache__/
*.py[cod]
*$py.class
.pytest_cache/

# dev
images/controller/Makefile
Binary file removed charts/deckhouse_lib_helm-1.21.0.tgz
Binary file not shown.
Binary file added charts/deckhouse_lib_helm-1.24.0.tgz
Binary file not shown.
87 changes: 87 additions & 0 deletions crds/cephclusterconnection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: cephclusterconnections.storage.deckhouse.io
labels:
heritage: deckhouse
module: csi-ceph
spec:
group: storage.deckhouse.io
scope: Cluster
names:
plural: cephclusterconnections
singular: cephclusterconnection
kind: CephClusterConnection
preserveUnknownFields: false
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
description: |
Ceph cluster connection parameters.
required:
- spec
properties:
spec:
type: object
required:
- clusterID
- userID
- userKey
- monitors
properties:
clusterID:
description: |
Ceph cluster FSID/UUID.

Use `ceph fsid` to get Ceph cluster FSID/UUID.
type: string
userID:
description: |
Username without `client.`.
type: string
userKey:
description: |
Ceph auth key corresponding to the `userID`.
type: string
monitors:
description: |
List of ceph-mon IP addresses in the format `10.0.0.10:6789`.
type: array
items:
type: string
status:
type: object
description: |
Displays current information about the resources managed by the CephClusterConnection custom resource.
properties:
phase:
type: string
description: |
The current state of resources managed by the CephClusterConnection custom resource. Might be:
- Failed (if the controller received incorrect resource configuration or some errors occurred during the operation)
- Create (if everything went fine)
enum:
- Failed
- Created
reason:
type: string
description: |
Additional information about the resources managed by the CephClusterConnection custom resource.
subresources:
status: {}
additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.reason
name: Reason
type: string
priority: 1
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
description: The age of this resource
151 changes: 151 additions & 0 deletions crds/cephstorageclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: cephstorageclasses.storage.deckhouse.io
labels:
heritage: deckhouse
module: csi-ceph
spec:
group: storage.deckhouse.io
scope: Cluster
names:
plural: cephstorageclasses
singular: cephstorageclass
kind: CephStorageClass
preserveUnknownFields: false
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
description: |
CephStorageClass is a Kubernetes Custom Resource that defines a configuration for a Kubernetes Storage class.
required:
- spec
properties:
spec:
type: object
required:
- clusterConnectionName
- reclaimPolicy
- type
oneOf:
- required:
- rbd
- required:
- cephfs
properties:
clusterConnectionName:
description: |
Name of the CephClusterConnection custom resource.
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
reclaimPolicy:
description: |
The storage class's reclaim policy. Might be:
- Delete (If the Persistent Volume Claim is deleted, deletes the Persistent Volume and its associated storage as well)
- Retain (If the Persistent Volume Claim is deleted, remains the Persistent Volume and its associated storage)
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
enum:
- Delete
- Retain
type:
description: |
The type of the storage class. Might be:
- cephfs (CephFS)
- rbd (Rados Block Device)
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
enum:
- cephfs
- rbd
cephfs:
type: object
description: |
CephFS specific parameters.
required:
- fsName
- pool
properties:
fsName:
description: |
Name of the CephFS file system.
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
pool:
description: |
Name of the Ceph pool.
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
rbd:
type: object
description: |
Rados Block Device specific parameters.
required:
- pool
properties:
defaultFSType:
description: |
Default file system type for the Rados Block Device.
type: string
default: ext4
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
pool:
description: |
Name of the Ceph pool.
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
status:
type: object
description: |
Displays current information about the Storage Class.
properties:
phase:
type: string
description: |
The Storage class current state. Might be:
- Failed (if the controller received incorrect resource configuration or some errors occurred during the operation)
- Create (if everything went fine)
enum:
- Failed
- Created
reason:
type: string
description: |
Additional information about the current state of the Storage Class.
subresources:
status: {}
additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.reason
name: Reason
type: string
priority: 1
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
description: The age of this resource
12 changes: 10 additions & 2 deletions enabled
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2021 Flant JSC
# Copyright 2024 Flant JSC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,15 @@
source /deckhouse/shell_lib.sh

function __main__() {
echo "true" > $MODULE_ENABLED_RESULT
enabled::disable_module_if_cluster_is_not_bootstraped
enabled::disable_module_in_kubernetes_versions_less_than 1.23.0

if values::array_has global.enabledModules "ceph-csi" ; then
echo "You must disable the ceph-csi module for the csi-ceph module to work."
echo "false" > "$MODULE_ENABLED_RESULT"
else
echo "true" > "$MODULE_ENABLED_RESULT"
fi
}

enabled::run $@
17 changes: 17 additions & 0 deletions images/controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG BASE_SCRATCH=registry.deckhouse.io/base_images/scratch@sha256:b054705fcc9f2205777d80a558d920c0b4209efdc3163c22b5bfcb5dda1db5fc
ARG BASE_GOLANG_ALPINE_BUILDER=registry.deckhouse.io/base_images/golang:1.22.3-alpine@sha256:dbf216b880b802c22e3f4f2ef0a78396b4a9a6983cb9b767c5efc351ebf946b0

FROM $BASE_GOLANG_ALPINE_BUILDER as builder

WORKDIR /go/src
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
WORKDIR /go/src/cmd
RUN GOOS=linux GOARCH=amd64 go build -o controller

FROM --platform=linux/amd64 $BASE_SCRATCH
COPY --from=builder /go/src/cmd/controller /go/src/cmd/controller

ENTRYPOINT ["/go/src/cmd/controller"]
63 changes: 63 additions & 0 deletions images/controller/api/v1alpha1/ceph_cluster_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2024 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type CephClusterConnection struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CephClusterConnectionSpec `json:"spec"`
Status *CephClusterConnectionStatus `json:"status,omitempty"`
}

type CephClusterConnectionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []CephClusterConnection `json:"items"`
}

type CephClusterConnectionSpec struct {
ClusterID string `json:"clusterID"`
UserID string `json:"userID"`
UserKey string `json:"userKey"`
Monitors []string `json:"monitors"`
CephFS CephClusterConnectionSpecCephFS `json:"cephFS"`
}

type CephClusterConnectionSpecCephFS struct {
SubvolumeGroup string `json:"subvolumeGroup"`
}

type CephClusterConnectionStatus struct {
Phase string `json:"phase,omitempty"`
Reason string `json:"reason,omitempty"`
}

type ClusterConfig struct {
CephFS map[string]string `json:"cephFS"`
ClusterID string `json:"clusterID"`
Monitors []string `json:"monitors"`
}

type ClusterConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ClusterConfig `json:"items"`
}
Loading