Skip to content

Commit

Permalink
Merge pull request #167 from guymguym/guy-2.0
Browse files Browse the repository at this point in the history
backport 2.0 - to release v2.0.9
  • Loading branch information
guymguym authored Nov 28, 2019
2 parents 8ad20ff + e7aa449 commit db6a79b
Show file tree
Hide file tree
Showing 18 changed files with 1,009 additions and 563 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ For Mac
```
brew install noobaa/noobaa/noobaa
# or
wget https://github.com/noobaa/noobaa-operator/releases/download/v2.0.8/noobaa-mac-v2.0.8; mv noobaa-mac-* noobaa; chmod +x noobaa
wget https://github.com/noobaa/noobaa-operator/releases/download/v2.0.9/noobaa-mac-v2.0.9; mv noobaa-mac-* noobaa; chmod +x noobaa
```

For Linux
```
wget https://github.com/noobaa/noobaa-operator/releases/download/v2.0.8/noobaa-linux-v2.0.8; mv noobaa-linux-* noobaa; chmod +x noobaa
wget https://github.com/noobaa/noobaa-operator/releases/download/v2.0.9/noobaa-linux-v2.0.9; mv noobaa-linux-* noobaa; chmod +x noobaa
```

- Run: `./noobaa --help` for CLI usage
Expand Down
6 changes: 6 additions & 0 deletions deploy/internal/configmap-empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: noobaa
data: {}
2 changes: 1 addition & 1 deletion deploy/internal/text/system_status_readme_ready.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

Open the management console service - take External IP/DNS or Node Port or use port forwarding:

kubectl port-forward -n {{.ServiceMgmt.Namespace}} service/{{.ServiceMgmt.Name}} 11443:8443 &
kubectl port-forward -n {{.ServiceMgmt.Namespace}} service/{{.ServiceMgmt.Name}} 11443:443 &
open https://localhost:11443

2. Test S3 client:
Expand Down
82 changes: 18 additions & 64 deletions doc/backing-store-crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BackingStore CRD represents a storage target to be used as underlying storage fo
These storage targets are used to store deduped+compressed+encrypted chunks of data (encryption keys are stored separately).
Backing-stores are referred to by name when defining [BucketClass](bucket-class-crd.md).

Multiple types of backing-stores are currently supported: aws-s3, s3-compatible, google-cloud-storage, azure-blob.
Multiple types of backing-stores are currently supported: aws-s3, s3-compatible, google-cloud-storage, azure-blob, pv-pool.
Backing-store type pv-pool is not yet supported by the operator. Instead, the web management console must be used to administer pv-pool backing-stores.
Adding support for a new type of backing-store is rather easy as it requires just GET/PUT key-value store, see [Backing-stores supported by NooBaa](https://github.com/noobaa/noobaa-core/tree/master/src/agent/block_store_services).

Expand Down Expand Up @@ -121,75 +121,29 @@ spec:
```
#### PV-POOL type
**Not yet implemented**
Create NooBaa resources StatefulSet with PVC mounted in each pod. Each resource will connect to the NooBaa brain and provide the PV filesystem storage to be used for storing encrypted chunks of data.
This action is supported from the NooBaa dashboard (Deploy Kubernetes Pool).
It is possible to configure the number of pods to be used and their PV size.
Here is an example of a StatefulSet with 3 pods and PV size of 30GB:
Create NooBaa resources StatefulSet with PVC mounted in each pod. Each resource will connect to the NooBaa core and provide the PV filesystem storage to be used for storing encrypted chunks of data. It is possible to configure the number of pods to be used and their PV size.
```shell
noobaa -n noobaa backingstore create pv-pool bs --num-volumes 3 --pv-size-gb 32 --storage-class STORAGE-CLASS-NAME
```
```yaml
---
apiVersion: apps/v1
kind: StatefulSet
apiVersion: noobaa.io/v1alpha1
kind: BackingStore
metadata:
name: noobaa-agent
finalizers:
- noobaa.io/finalizer
labels:
app: noobaa
noobaa-module: noobaa-pool-impl
name: bs
namespace: noobaa
spec:
selector:
matchLabels:
noobaa-module: noobaa-agent
serviceName: noobaa-agent
replicas: 3
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: noobaa
noobaa-module: noobaa-agent
noobaa-s3: "true"
spec:
containers:
- name: noobaa-agent
resources:
requests:
cpu: "100m"
memory: "500Mi"
limits:
cpu: "2"
memory: "2Gi"
env:
- name: CONTAINER_PLATFORM
value: KUBERNETES
- name: AGENT_CONFIG
value: "AGENT_CONFIG_VALUE"
- name: ENDPOINT_PORT
value: "6001"
- name: ENDPOINT_SSL_PORT
value: "6443"
command: ["/noobaa_init_files/noobaa_init.sh", "agent"]
ports:
- containerPort: 60101
volumeMounts:
- name: noobaastorage
mountPath: /noobaa_storage
- name: tmp-logs-vol
mountPath: /usr/local/noobaa/logs
volumes:
- name: tmp-logs-vol
emptyDir: {}
volumeClaimTemplates:
- metadata:
name: noobaastorage
labels:
app: noobaa
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 30Gi
pvPool:
numVolumes: 3
resources:
requests:
storage: 32Gi
storageClass: STORAGE-CLASS-NAME
type: pv-pool
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/noobaa/noobaa-operator/v2

go 1.12
go 1.13

require (
github.com/aws/aws-sdk-go v1.23.8
Expand Down
60 changes: 51 additions & 9 deletions pkg/backingstore/backingstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
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()
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())
}

log.Fatalf("TODO ...")

if len(args) != 1 || args[0] == "" {
log.Fatalf(`❌ Missing expected arguments: <backing-store-name> %s`, 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
106 changes: 79 additions & 27 deletions pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,56 @@ 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 @@ -492,15 +522,17 @@ func (r *Reconciler) MakeExternalConnectionParams() (*nb.AddExternalConnectionPa
}{}
err := json.Unmarshal([]byte(privateKeyJSON), privateKey)
if err != nil {
return nil, util.NewPersistentError("InvalidGoogleSecret",
fmt.Sprintf("Invalid secret for google type %q expected JSON in data.GoogleServiceAccountPrivateKeyJson", r.Secret.Name))
return nil, util.NewPersistentError("InvalidGoogleSecret", fmt.Sprintf(
"Invalid secret for google type %q expected JSON in data.GoogleServiceAccountPrivateKeyJson",
r.Secret.Name,
))
}
conn.Identity = privateKey.ID
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 @@ -542,9 +574,13 @@ func (r *Reconciler) fixAlternateKeysNames() {
// ReconcileExternalConnection handles the external connection using noobaa api
func (r *Reconciler) ReconcileExternalConnection() error {

// TODO we only support creation here, but not updates
if r.ExternalConnectionInfo != nil {
return nil
}
if r.AddExternalConnectionParams == nil {
return nil
}

res, err := r.NBClient.CheckExternalConnectionAPI(*r.AddExternalConnectionParams)
if err != nil {
Expand Down Expand Up @@ -595,20 +631,36 @@ func (r *Reconciler) ReconcileExternalConnection() error {
// ReconcilePool handles the pool using noobaa api
func (r *Reconciler) ReconcilePool() error {

// TODO we only support creation here, but not updates
if r.PoolInfo != nil {
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
Loading

0 comments on commit db6a79b

Please sign in to comment.