Skip to content

Commit

Permalink
add profile feature in maya types (openebs-archive#134)
Browse files Browse the repository at this point in the history
* introduce k8s based storage class utility file
* fix a minor doc issue while implementing openebs/openebs#717

1. Why is this change necessary ?

This is a part of bigger scheme of things. It will
enable part implementation of openebs/openebs#693
openebs/openebs#694 and openebs/openebs#409

This particular implementation fixes openebs/openebs#717

2. How does this change address the issue ?

- Adds a k8s_storage_class.go file

- Adds a few labels, keys & utility functions
w.r.t storage class

3. How to verify this change ?

- make should work fine

- The actual verfication will be part of
bigger changes mentioned in above issues.

4. What side effects does this change have ?

- None

- Unit test should be implemented as mentioned in
openebs/openebs#725
  • Loading branch information
Amit Kumar Das authored and kmova committed Oct 26, 2017
1 parent 4aa516f commit ec6cc6d
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
23 changes: 23 additions & 0 deletions types/profiles/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2017 The OpenEBS Authors.
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.
*/

// Profiles are related to OpenEBS volume.
// Profiles can be categorized into volume related placements, volume
// related provisioning, and probably a few more features in the future.
// Profiles are meant to be used by storage admins to communicate
// their volume requirements to Maya without being involved into providing
// exact values or numbers.
package v1
119 changes: 119 additions & 0 deletions types/profiles/v1/profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
Copyright 2017 The OpenEBS Authors.
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.
*/

// This file deals with the labels, constants, defaults & utility
// functions related to the profiles
package v1

import (
"fmt"
"strings"
)

// ProvisionPolicyKey type deals with the keys associated with
// volume provisioning. It is expected that these keys will have
// corresponding values.
//
// USAGE:
// When OpenEBS storage is managed with Kubernetes (K8s) as the underlying
// container orchestrator, then provision policy key can be used as following:
//
// apiVersion: storage.k8s.io/v1
// kind: StorageClass
// metadata:
// name: openebs-jupyter
// labels:
// provision/replica-count: 2
// provision/controller-count: 1
// provisioner: openebs.io/provisioner-iscsi
// parameters:
// pool: hostdir-var
// replica: "2"
// size: 5G
type ProvisionPolicyKey string

const (
ReplicaCountPPK ProvisionPolicyKey = "provision/replica-count"
ControllerCountPPK ProvisionPolicyKey = "provision/controller-count"
ReplicaTolerationPPK ProvisionPolicyKey = "provision/replica-toleration"
ControllerTolerationPPK ProvisionPolicyKey = "provision/controller-toleration"
)

// PlacementPolicyKey is a constant which will be used as a key. This key can be
// associated with one or more placement policies as value(s).
//
// USAGE:
// When OpenEBS storage is managed with Kubernetes (K8s) as the underlying
// container orchestrator; then placement policy key can be used as following:
//
// apiVersion: storage.k8s.io/v1
// kind: StorageClass
// metadata:
// name: openebs-jupyter
// labels:
// placement: "spread-replica, sticky-replica"
// provision/replica-count: 2
// provisioner: openebs.io/provisioner-iscsi
// parameters:
// pool: hostdir-var
// replica: "2"
// size: 5G
const (
PlacementPolicyKey string = "placement"
)

// PlacementPolicyValue type deals with various volume placement related
// policy value(s). These can be thought of as flags. Presence of these policy
// flags indicate enabling of corresponding placement.
//
// NOTE to developer:
// Care should be exercised to filter/prioritize policies if some of them
// are conflicting. Particular examples will be mentioned when the developer
// have them.
//
// USAGE:
// Already mentioned in PlacementPolicyKey
type PlacementPolicyValue string

const (
SpreadReplicaPPV PlacementPolicyValue = "spread-replica"
StickyReplicaPPV PlacementPolicyValue = "sticky-replica"
)

// IsStickyReplica indicates if sticking replicas to their placement
// Nodes is mentioned in provided policies.
func IsStickyReplica(policies map[string]string) (bool, error) {
// TODO logic
return false, fmt.Errorf("Not implemented")
}

// IsSpreadReplica indicates if spreading the replicas across Nodes
// is mentioned in provided policies.
func IsSpreadReplica(policies map[string]string) (bool, error) {
// TODO logic
return false, fmt.Errorf("Not implemented")
}

// GetReplicaCount gets the value of replica count if available
func GetReplicaCount(policies map[string]string) (string, bool) {
for k, v := range policies {
if strings.TrimSpace(k) == string(ReplicaCountPPK) {
return strings.TrimSpace(v), true
}
}

return "", false
}

0 comments on commit ec6cc6d

Please sign in to comment.