Skip to content

Commit

Permalink
Merge pull request #182 from AccessibleAI/DEV-23408-metastorageprovis…
Browse files Browse the repository at this point in the history
…ioner

add metastorage provisioner
  • Loading branch information
MrEsL authored Aug 20, 2024
2 parents 6a59f62 + c972751 commit 2bf4393
Show file tree
Hide file tree
Showing 29 changed files with 1,765 additions and 88 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.21.1 as builder
FROM golang:1.22.6 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -17,6 +17,7 @@ COPY cmd/ cmd/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o cnvrg-operator cmd/operator/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o cnvrg-metastorageprovisioner cmd/metastorageprovisioner/main.go


FROM registry.access.redhat.com/ubi9/ubi:latest
Expand All @@ -31,4 +32,5 @@ USER 1000
WORKDIR /opt/app-root
COPY license /licenses
COPY --from=builder /workspace/cnvrg-operator .
COPY --from=builder /workspace/cnvrg-metastorageprovisioner .

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 ;\
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down
1 change: 0 additions & 1 deletion api/v1/zz_generated.deepcopy.go

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

36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 v1 contains API Schema definitions for the mlops v1 API group
// +kubebuilder:object:generate=true
// +groupName=mlops.cnvrg.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "mlops.cnvrg.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
83 changes: 83 additions & 0 deletions api/v1alpha1/metastoragetypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package v1alpha1

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

// +kubebuilder:object:generate=true

const (
Running MetaStorageProvisionerStatus = "running"
Failed MetaStorageProvisionerStatus = "failed"
Pending MetaStorageProvisionerStatus = "pending"
Deleting MetaStorageProvisionerStatus = "deleting"
)

func init() {
SchemeBuilder.Register(&MetaStorageProvisioner{}, &MetaStorageProvisionerList{})
}

type MetaStorageProvisionerStatus string

// MetaStorageProvisioner represents the storage provisioner to be installed
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type MetaStorageProvisioner struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec StorageProvisionerSpec `json:"spec, omitempty"`
Status StorageProvisionerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
type MetaStorageProvisionerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []MetaStorageProvisioner `json:"items"`
}

// StorageProvisionerSpec defines the desired state of MetaStorageProvisioner
type StorageProvisionerSpec struct {
ProvisionerType `json:",inline"`
}

// StorageProvisionerStatus defines the observed state of MetaStorageProvisioner
type StorageProvisionerStatus struct {
Status MetaStorageProvisionerStatus `json:"status"`
}

type ProvisionerType struct {
// only one of the following should be set
// +optional
NFSProvisioner *NFSProvisioner `json:"NFSProvisioner,omitempty"`
}

// NFSProvisioner represents the NFS provisioner
type NFSProvisioner struct {
NFSServer string `json:"nfsServer"`
NFSPath string `json:"nfsPath"`
// +optional
StorageClassName string `json:"storageClassName,omitempty"`
}

// Validate ensures provisioner type is valid
func (p *ProvisionerType) Validate() error {
count := 0
if p.NFSProvisioner != nil {
count++
if p.NFSProvisioner.NFSServer == "" {
return fmt.Errorf("nfs server cannot be empty")
}
if p.NFSProvisioner.NFSPath == "" {
return fmt.Errorf("nfs path cannot be empty")
}
}

if count > 1 {
return fmt.Errorf("only one provisioner type can be set")
}
return nil
}
148 changes: 148 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 6 additions & 0 deletions charts/metastorageprovisioner/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: metastorageprovisioner
description: A cnvrg.io storage provisioner
type: application
version: 5.1.0
appVersion: 5.1.0
11 changes: 11 additions & 0 deletions charts/metastorageprovisioner/templates/clusterrole.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: "cnvrg-metastorageprovisioner-{{ .Release.Namespace }}"
rules:
- apiGroups:
- "*"
resources:
- "*"
verbs:
- "*"
42 changes: 42 additions & 0 deletions charts/metastorageprovisioner/templates/dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: metastorageprovisioner
namespace: {{ .Release.Namespace }}
labels:
app: metastorageprovisioner
component: metastorageprovisioner
spec:
selector:
matchLabels:
app: metastorageprovisioner
component: metastorageprovisioner
template:
metadata:
labels:
app: metastorageprovisioner
component: metastorageprovisioner
spec:
serviceAccountName: cnvrg-metastorageprovisioner
containers:
- name: metastorageprovisioner
imagePullPolicy: Always
{{- if .Values.version }}
image: "{{.Values.imageHub}}/cnvrg-operator:{{.Values.version}}"
{{- else }}
image: "{{.Values.imageHub}}/cnvrg-operator:{{.Chart.Version}}"
{{- end }}
command:
- /opt/app-root/cnvrg-metastorageprovisioner
- start
env:
- name: HELM_CACHE_HOME
value: /tmp/
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
13 changes: 13 additions & 0 deletions charts/metastorageprovisioner/templates/rolebinding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: "cnvrg-metastorageprovisioner-{{ .Release.Namespace }}"
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: "cnvrg-metastorageprovisioner-{{ .Release.Namespace }}"
subjects:
- kind: ServiceAccount
name: cnvrg-metastorageprovisioner
namespace: {{.Release.Namespace}}
7 changes: 7 additions & 0 deletions charts/metastorageprovisioner/templates/sa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: cnvrg-metastorageprovisioner
namespace: {{ .Release.Namespace }}
imagePullSecrets:
- name: {{ .Values.imagePullSecretRef }}
Loading

0 comments on commit 2bf4393

Please sign in to comment.