Skip to content

Commit

Permalink
Fixing nullpointer error with rest config lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Zane Williamson <[email protected]>
  • Loading branch information
sepulworld committed Jan 3, 2020
1 parent 3a5e477 commit fdfdeda
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
- args:
- -zk-operator=true
- -etcd-operator=false
- -ingress-base-domain=ing.local.domain
image: bloomberg/solr-operator:latest
imagePullPolicy: Always
name: solr-operator
Expand Down
14 changes: 7 additions & 7 deletions controllers/solrbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package controllers

import (
"context"
"reflect"
"time"

"github.com/bloomberg/solr-operator/controllers/util"
"github.com/go-logr/logr"
batchv1 "k8s.io/api/batch/v1"
Expand All @@ -26,25 +29,20 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"reflect"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"time"

solrv1beta1 "github.com/bloomberg/solr-operator/api/v1beta1"
)

var (
Config *rest.Config
)

// SolrBackupReconciler reconciles a SolrBackup object
type SolrBackupReconciler struct {
client.Client
Log logr.Logger
scheme *runtime.Scheme
config *rest.Config
}

// +kubebuilder:rbac:groups="",resources=pods/exec,verbs=create
Expand Down Expand Up @@ -131,6 +129,7 @@ func (r *SolrBackupReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
func reconcileSolrCloudBackup(r *SolrBackupReconciler, backup *solrv1beta1.SolrBackup) (solrCloud *solrv1beta1.SolrCloud, collectionBackupsFinished bool, actionTaken bool, err error) {
// Get the solrCloud that this backup is for.
solrCloud = &solrv1beta1.SolrCloud{}

err = r.Get(context.TODO(), types.NamespacedName{Namespace: backup.Namespace, Name: backup.Spec.SolrCloud}, solrCloud)
if err != nil && errors.IsNotFound(err) {
r.Log.Error(err, "Could not find cloud to backup", "namespace", backup.Namespace, "backupName", backup.Name, "solrCloudName", backup.Spec.SolrCloud)
Expand All @@ -152,7 +151,7 @@ func reconcileSolrCloudBackup(r *SolrBackupReconciler, backup *solrv1beta1.SolrB
// This should only occur before the backup processes have been started
if backup.Status.SolrVersion == "" {
// Prep the backup directory in the persistentVolume
err := util.EnsureDirectoryForBackup(solrCloud, backup.Name, Config)
err := util.EnsureDirectoryForBackup(solrCloud, backup.Name, r.config)
if err != nil {
return solrCloud, collectionBackupsFinished, actionTaken, err
}
Expand Down Expand Up @@ -295,6 +294,7 @@ func (r *SolrBackupReconciler) SetupWithManagerAndReconciler(mgr ctrl.Manager, r
For(&solrv1beta1.SolrBackup{}).
Owns(&batchv1.Job{})

r.config = mgr.GetConfig()
r.scheme = mgr.GetScheme()
return ctrlBuilder.Complete(reconciler)
}
5 changes: 3 additions & 2 deletions controllers/util/backup_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
)

const (
BaseBackupRestorePath = "/var/solr-backup-restore"
TarredFile = "/var/solr-backup-restore/backup.tgz"
BaseBackupRestorePath = "/var/solr/solr-backup-restore"
TarredFile = "/var/solr/solr-backup-restore/backup.tgz"
BackupTarCommand = "cd " + BaseBackupRestorePath + " && tar -czf /tmp/backup.tgz * && mv /tmp/backup.tgz " + TarredFile + " && chmod -R a+rwx " + TarredFile + " && cd - && "
CleanupCommand = " && rm -rf " + BaseBackupRestorePath + "/{*,.*}"

Expand Down Expand Up @@ -432,6 +432,7 @@ func RunExecForPod(podName string, namespace string, command []string, config re
Stderr: &stderr,
Tty: false,
})

if err != nil {
return fmt.Errorf("error in Stream: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions example/dependencies/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ spec:
shortNames:
- zk
additionalPrinterColumns:
- name: Members
- name: Replicas
type: integer
description: The number zookeeper members running
description: The number of ZooKeeper servers in the ensemble
JSONPath: .status.replicas
- name: Ready Members
- name: Ready Replicas
type: integer
description: The number zookeeper members ready
description: The number of ZooKeeper servers in the ensemble that are in a Ready state
JSONPath: .status.readyReplicas
- name: Internal Endpoint
type: string
Expand All @@ -35,4 +35,4 @@ spec:
scope: Namespaced
version: v1beta1
subresources:
status: {}
status: {}
2 changes: 1 addition & 1 deletion example/dependencies/operators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
containers:
- name: zk-operator
# Replace this with the built image name
image: pravega/zookeeper-operator:v0.2.0
image: pravega/zookeeper-operator:0.2.4
ports:
- containerPort: 60000
name: metrics
Expand Down
15 changes: 10 additions & 5 deletions example/test_solrbackup.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
apiVersion: solr.bloomberg.com/v1beta1
kind: SolrBackup
metadata:
labels:
controller-tools.k8s.io: "1.0"
name: solrbackup-sample
name: solrbackup-test
namespace: default
spec:
# Add fields here
foo: bar
persistence:
volume:
source:
persistentVolumeClaim:
claimName: "pvc-test"
solrCloud: example
collections:
- example
7 changes: 7 additions & 0 deletions example/test_solrcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ kind: SolrCloud
metadata:
name: example
spec:
dataPvcSpec:
resources:
requests:
storage: "5Gi"
backupRestoreVolume:
persistentVolumeClaim:
claimName: "pvc-test"
replicas: 3
solrImage:
tag: 8.2.0
Expand Down

0 comments on commit fdfdeda

Please sign in to comment.