Skip to content

Commit

Permalink
Feature #91 Enable backingstore type pv-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
ron1 authored and guymguym committed Nov 28, 2019
1 parent 8ad20ff commit 9f3f7ee
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 35 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ require (
github.com/coreos/prometheus-operator v0.29.0
github.com/docker/distribution v2.7.1+incompatible
github.com/go-openapi/spec v0.19.2
github.com/go-openapi/validate v0.18.0 // indirect
github.com/gobuffalo/flect v0.1.6 // indirect
github.com/google/uuid v1.1.1
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/hashicorp/go-version v1.2.0
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20190924175516-f3ba69cc601e
github.com/openshift/api v3.9.1-0.20190424152011-77b8897ec79a+incompatible
github.com/openshift/cloud-credential-operator v0.0.0-20190614194054-1ccced634f6c
github.com/openshift/custom-resource-status v0.0.0-20190801200128-4c95b3a336cd
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190605231540-b8a4faf68e36 // 0.11.0
github.com/operator-framework/operator-sdk v0.10.0
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/rook/rook v1.1.2
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
Expand Down
62 changes: 52 additions & 10 deletions pkg/backingstore/backingstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -158,6 +159,14 @@ func CmdCreatePVPool() *cobra.Command {
Short: "Create pv-pool backing store",
Run: RunCreatePVPool,
}
cmd.Flags().Uint32(
"num-volumes", 0,
`Number of volumes in the store`,
)
cmd.Flags().Uint32(
"pv-size-gb", 0,
`PV size of each volume in the store`,
)
cmd.Flags().String(
"storage-class", "",
"The storage class to use for PV provisioning",
Expand Down Expand Up @@ -249,10 +258,12 @@ func createCommon(cmd *cobra.Command, args []string, storeType nbv1.StoreType, p
log.Fatalf(`❌ Could not create BackingStore %q in Namespace %q (conflict)`, backStore.Name, backStore.Namespace)
}

// Create secret
util.Panic(controllerutil.SetControllerReference(backStore, secret, scheme.Scheme))
if !util.KubeCreateSkipExisting(secret) {
log.Fatalf(`❌ Could not create Secret %q in Namespace %q (conflict)`, secret.Name, secret.Namespace)
if GetBackingStoreSecret(backStore) != nil {
// Create secret
util.Panic(controllerutil.SetControllerReference(backStore, secret, scheme.Scheme))
if !util.KubeCreateSkipExisting(secret) {
log.Fatalf(`❌ Could not create Secret %q in Namespace %q (conflict)`, secret.Name, secret.Namespace)
}
}

log.Printf("")
Expand Down Expand Up @@ -355,12 +366,43 @@ func RunCreateGoogleCloudStorage(cmd *cobra.Command, args []string) {
// RunCreatePVPool runs a CLI command
func RunCreatePVPool(cmd *cobra.Command, args []string) {
log := util.Logger()

log.Fatalf("TODO ...")

if len(args) != 1 || args[0] == "" {
log.Fatalf(`❌ Missing expected arguments: <backing-store-name> %s`, cmd.UsageString())
}
createCommon(cmd, args, nbv1.StoreTypePVPool, func(backStore *nbv1.BackingStore, secret *corev1.Secret) {
numVolumes, _ := cmd.Flags().GetUint32("num-volumes")
pvSizeGB, _ := cmd.Flags().GetUint32("pv-size-gb")
storageClass, _ := cmd.Flags().GetString("storage-class")
if numVolumes == 0 {
fmt.Printf("Enter number of volumes: ")
_, err := fmt.Scan(&numVolumes)
util.Panic(err)
if numVolumes == 0 {
log.Fatalf(`❌ Missing number of volumes %s`, cmd.UsageString())
}
}
if numVolumes > 20 {
log.Fatalf(`❌ Number of volumes seems to be too large %d %s`, numVolumes, cmd.UsageString())
}

if pvSizeGB == 0 {
fmt.Printf("Enter PV size (GB): ")
_, err := fmt.Scan(&pvSizeGB)
util.Panic(err)
if pvSizeGB == 0 {
log.Fatalf(`❌ Missing PV size (GB) %s`, cmd.UsageString())
}
}
if pvSizeGB > 1024 {
log.Fatalf(`❌ PV size seems to be too large %d %s`, pvSizeGB, cmd.UsageString())
}
backStore.Spec.PVPool = &nbv1.PVPoolSpec{
StorageClass: storageClass,
NumVolumes: int(numVolumes),
VolumeResources: &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: *resource.NewScaledQuantity(int64(pvSizeGB), resource.Giga),
},
},
}
})
}

// RunDelete runs a CLI command
Expand Down
93 changes: 68 additions & 25 deletions pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,51 @@ func (r *Reconciler) ReadSystemInfo() error {
}
r.SystemInfo = &systemInfo

// Check if pool exists
for i := range r.SystemInfo.Pools {
p := &r.SystemInfo.Pools[i]
if p.Name == r.BackingStore.Name {
r.PoolInfo = p
break
}
}

pool := r.PoolInfo
if r.BackingStore.Spec.Type == nbv1.StoreTypePVPool {
if pool != nil && pool.ResourceType != "HOSTS" {
return util.NewPersistentError("InvalidBackingStore",
fmt.Sprintf("BackingStore %q w/existing pool %+v has unexpected resource type %+v", r.BackingStore.Name, pool, pool.ResourceType))
}
pvPool := r.BackingStore.Spec.PVPool
qty := pvPool.VolumeResources.Requests[corev1.ResourceName(corev1.ResourceStorage)]
gbsize, _ := qty.AsInt64()
r.CreateHostsPoolParams = &nb.CreateHostsPoolParams{
Name: r.BackingStore.Name,
IsManaged: true,
HostCount: int(pvPool.NumVolumes),
HostConfig: nb.PoolHostsInfo{VolumeSize: gbsize},
}
return nil
}
if pool != nil && pool.ResourceType != "CLOUD" {
return util.NewPersistentError("InvalidBackingStore",
fmt.Sprintf("BackingStore %q w/existing pool %+v has unexpected resource type %+v", r.BackingStore.Name, pool, pool.ResourceType))
}

conn, err := r.MakeExternalConnectionParams()
if err != nil {
return err
}

// Check if pool exists
for i := range r.SystemInfo.Pools {
p := &r.SystemInfo.Pools[i]
if p.Name == r.BackingStore.Name {
if p.CloudInfo != nil &&
p.CloudInfo.EndpointType == conn.EndpointType &&
p.CloudInfo.Endpoint == conn.Endpoint &&
p.CloudInfo.Identity == conn.Identity {
// pool exists and connection match
r.PoolInfo = p
} else {
// TODO pool exists but connection mismatch
r.Logger.Warnf("using existing pool but connection mismatch %+v pool %+v %+v", conn, p, p.CloudInfo)
r.PoolInfo = p
}
// Check that noobaa-core uses the same connection as the pool
// Due to noobaa/noobaa-core#5750 the identity (access-key) is not returned in the api call so just warn for now
// TODO Improve handling of this condition
if pool != nil {
if pool.CloudInfo == nil ||
pool.CloudInfo.EndpointType != conn.EndpointType ||
pool.CloudInfo.Endpoint != conn.Endpoint ||
pool.CloudInfo.Identity != conn.Identity {
r.Logger.Warnf("using existing pool but connection mismatch %+v pool %+v %+v", conn, pool, pool.CloudInfo)
}
}

Expand Down Expand Up @@ -499,8 +524,8 @@ func (r *Reconciler) MakeExternalConnectionParams() (*nb.AddExternalConnectionPa
conn.Secret = privateKeyJSON

case nbv1.StoreTypePVPool:
return nil, util.NewPersistentError("NotYetImplemented",
fmt.Sprintf("Not yet implemented backing store type %q", r.BackingStore.Spec.Type))
return nil, util.NewPersistentError("InvalidType",
fmt.Sprintf("%q type does not have external connection params", r.BackingStore.Spec.Type))

default:
return nil, util.NewPersistentError("InvalidType",
Expand Down Expand Up @@ -546,6 +571,9 @@ func (r *Reconciler) ReconcileExternalConnection() error {
return nil
}

if r.AddExternalConnectionParams == nil {
return nil
}
res, err := r.NBClient.CheckExternalConnectionAPI(*r.AddExternalConnectionParams)
if err != nil {
if rpcErr, isRPCErr := err.(*nb.RPCError); isRPCErr {
Expand Down Expand Up @@ -599,16 +627,31 @@ func (r *Reconciler) ReconcilePool() error {
return nil
}

err := r.NBClient.CreateCloudPoolAPI(*r.CreateCloudPoolParams)
if err != nil {
return err
poolName := ""

if r.CreateHostsPoolParams != nil {
err := r.NBClient.CreateHostsPoolAPI(*r.CreateHostsPoolParams)
if err != nil {
return err
}
poolName = r.CreateHostsPoolParams.Name
}

err = r.NBClient.UpdateAllBucketsDefaultPool(nb.UpdateDefaultPoolParams{
PoolName: r.CreateCloudPoolParams.Name,
})
if err != nil {
return err
if r.CreateCloudPoolParams != nil {
err := r.NBClient.CreateCloudPoolAPI(*r.CreateCloudPoolParams)
if err != nil {
return err
}
poolName = r.CreateCloudPoolParams.Name
}

if poolName != "" {
err := r.NBClient.UpdateAllBucketsDefaultPool(nb.UpdateDefaultPoolParams{
PoolName: poolName,
})
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 9f3f7ee

Please sign in to comment.