Skip to content

Commit

Permalink
add KubernetesStorage type
Browse files Browse the repository at this point in the history
  • Loading branch information
pepov committed Jan 22, 2020
1 parent b01d650 commit e536d35
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/secret/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/storage/...

# find or download controller-gen
# download controller-gen if necessary
Expand Down
69 changes: 69 additions & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright © 2020 Banzai Cloud
//
// 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 storage

import (
corev1 "k8s.io/api/core/v1"
)

// +kubebuilder:object:generate=true

type KubernetesStorage struct {
HostPath *corev1.HostPathVolumeSource `json:"hostPath,omitempty"`
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
// PersistentVolumeClaim defines the Spec and the Source at the same time.
// The PVC will be created with the configured spec and the name defined in the source.
PersistentVolumeClaim *PersistentVolumeClaim `json:"pvc,omitempty"`
}

// +kubebuilder:object:generate=true

type PersistentVolumeClaim struct {
PersistentVolumeClaimSpec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty"`
PersistentVolumeSource corev1.PersistentVolumeClaimVolumeSource `json:"source,omitempty"`
}

// GetVolume returns a default emptydir volume if none configured
//
// `name` will be the name of the volume and the lowest level directory in case a hostPath mount is used
// `path` is the path in case the hostPath volume type is used
func (storage KubernetesStorage) GetVolume(name, path string) corev1.Volume {
volume := corev1.Volume{
Name: name,
}
if storage.HostPath != nil {
if storage.HostPath.Path == "" {
storage.HostPath.Path = path
}
volume.VolumeSource = corev1.VolumeSource{
HostPath: storage.HostPath,
}
return volume
} else if storage.EmptyDir != nil {
volume.VolumeSource = corev1.VolumeSource{
EmptyDir: storage.EmptyDir,
}
return volume
} else if storage.PersistentVolumeClaim != nil {
volume.VolumeSource = corev1.VolumeSource{
PersistentVolumeClaim: &storage.PersistentVolumeClaim.PersistentVolumeSource,
}
}
// return a default emptydir volume if none configured
volume.VolumeSource = corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
}
return volume
}
70 changes: 70 additions & 0 deletions pkg/storage/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 e536d35

Please sign in to comment.