This commit is contained in:
Marc Campbell
2019-07-09 01:36:26 +00:00
parent a4824db44d
commit de1a771fbf
19 changed files with 307 additions and 487 deletions

View File

@@ -57,6 +57,6 @@ type AnalyzerList struct {
Items []Analyzer `json:"items"`
}
func init() {
SchemeBuilder.Register(&Analyzer{}, &AnalyzerList{})
}
// func init() {
// SchemeBuilder.Register(&Analyzer{}, &AnalyzerList{})
// }

View File

@@ -16,43 +16,43 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStorageAnalyzer(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &Analyzer{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStorageAnalyzer(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &Analyzer{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// }}
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &Analyzer{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &Analyzer{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -57,6 +57,6 @@ type AnalyzerJobList struct {
Items []AnalyzerJob `json:"items"`
}
func init() {
SchemeBuilder.Register(&AnalyzerJob{}, &AnalyzerJobList{})
}
// func init() {
// SchemeBuilder.Register(&AnalyzerJob{}, &AnalyzerJobList{})
// }

View File

@@ -16,43 +16,43 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStorageAnalyzerJob(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &AnalyzerJob{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStorageAnalyzerJob(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &AnalyzerJob{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// }}
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &AnalyzerJob{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &AnalyzerJob{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -48,6 +48,6 @@ type CollectorList struct {
Items []Collector `json:"items"`
}
func init() {
SchemeBuilder.Register(&Collector{}, &CollectorList{})
}
// func init() {
// SchemeBuilder.Register(&Collector{}, &CollectorList{})
// }

View File

@@ -16,43 +16,43 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStorageCollector(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &Collector{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStorageCollector(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &Collector{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// }}
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &Collector{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &Collector{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -32,8 +32,9 @@ type CollectorJobSpec struct {
// CollectorJobStatus defines the observed state of CollectorJob
type CollectorJobStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Running []string `json:"running"`
// Successful []string `json:"successful"`
// Failed []string `json:"failed"`
}
// +genclient
@@ -58,6 +59,6 @@ type CollectorJobList struct {
Items []CollectorJob `json:"items"`
}
func init() {
SchemeBuilder.Register(&CollectorJob{}, &CollectorJobList{})
}
// func init() {
// SchemeBuilder.Register(&CollectorJob{}, &CollectorJobList{})
// }

View File

@@ -16,43 +16,50 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStorageCollectorJob(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &CollectorJob{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStorageCollectorJob(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &CollectorJob{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// },
// Spec: CollectorJobSpec{
// Collector: CollectorRef{
// Namespace: "bar",
// Name: "baz",
// },
// },
// }
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &CollectorJob{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &CollectorJob{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -16,43 +16,43 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStoragePreflight(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &Preflight{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStoragePreflight(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &Preflight{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// }}
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &Preflight{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &Preflight{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -57,6 +57,6 @@ type PreflightJobList struct {
Items []PreflightJob `json:"items"`
}
func init() {
SchemeBuilder.Register(&PreflightJob{}, &PreflightJobList{})
}
// func init() {
// SchemeBuilder.Register(&PreflightJob{}, &PreflightJobList{})
// }

View File

@@ -16,43 +16,43 @@ limitations under the License.
package v1beta1
import (
"testing"
// import (
// "testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// "github.com/onsi/gomega"
// "golang.org/x/net/context"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/types"
// )
func TestStoragePreflightJob(t *testing.T) {
key := types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created := &PreflightJob{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
g := gomega.NewGomegaWithT(t)
// func TestStoragePreflightJob(t *testing.T) {
// key := types.NamespacedName{
// Name: "foo",
// Namespace: "default",
// }
// created := &PreflightJob{
// ObjectMeta: metav1.ObjectMeta{
// Name: "foo",
// Namespace: "default",
// }}
// g := gomega.NewGomegaWithT(t)
// Test Create
fetched := &PreflightJob{}
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
// // Test Create
// fetched := &PreflightJob{}
// g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(created))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(created))
// Test Updating the Labels
updated := fetched.DeepCopy()
updated.Labels = map[string]string{"hello": "world"}
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
// // Test Updating the Labels
// updated := fetched.DeepCopy()
// updated.Labels = map[string]string{"hello": "world"}
// g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
g.Expect(fetched).To(gomega.Equal(updated))
// g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(fetched).To(gomega.Equal(updated))
// Test Delete
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
}
// // Test Delete
// g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred())
// g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred())
// }

View File

@@ -1,21 +1,5 @@
// +build !ignore_autogenerated
/*
Copyright 2019 Replicated, Inc..
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.
*/
// autogenerated by controller-gen object, do not modify manually
package v1beta1

View File

@@ -18,71 +18,8 @@ package analyzer
import (
"testing"
"time"
"github.com/onsi/gomega"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"golang.org/x/net/context"
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
var c client.Client
var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo", Namespace: "default"}}
var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"}
const timeout = time.Second * 5
func TestReconcile(t *testing.T) {
g := gomega.NewGomegaWithT(t)
instance := &troubleshootv1beta1.Analyzer{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{})
g.Expect(err).NotTo(gomega.HaveOccurred())
c = mgr.GetClient()
recFn, requests := SetupTestReconcile(newReconciler(mgr))
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())
stopMgr, mgrStopped := StartTestManager(mgr, g)
defer func() {
close(stopMgr)
mgrStopped.Wait()
}()
// Create the Analyzer object and expect the Reconcile and Deployment to be created
err = c.Create(context.TODO(), instance)
// The instance object may not be a valid object because it might be missing some required fields.
// Please modify the instance object by adding required fields and then remove the following if statement.
if apierrors.IsInvalid(err) {
t.Logf("failed to create object, got an invalid object error: %v", err)
return
}
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
deploy := &appsv1.Deployment{}
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Delete the Deployment and expect Reconcile to be called for Deployment deletion
g.Expect(c.Delete(context.TODO(), deploy)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Manually delete Deployment since GC isn't enabled in the test control plane
g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout).
Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found"))
}

View File

@@ -18,71 +18,8 @@ package analyzerjob
import (
"testing"
"time"
"github.com/onsi/gomega"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"golang.org/x/net/context"
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
var c client.Client
var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo", Namespace: "default"}}
var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"}
const timeout = time.Second * 5
func TestReconcile(t *testing.T) {
g := gomega.NewGomegaWithT(t)
instance := &troubleshootv1beta1.AnalyzerJob{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{})
g.Expect(err).NotTo(gomega.HaveOccurred())
c = mgr.GetClient()
recFn, requests := SetupTestReconcile(newReconciler(mgr))
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())
stopMgr, mgrStopped := StartTestManager(mgr, g)
defer func() {
close(stopMgr)
mgrStopped.Wait()
}()
// Create the AnalyzerJob object and expect the Reconcile and Deployment to be created
err = c.Create(context.TODO(), instance)
// The instance object may not be a valid object because it might be missing some required fields.
// Please modify the instance object by adding required fields and then remove the following if statement.
if apierrors.IsInvalid(err) {
t.Logf("failed to create object, got an invalid object error: %v", err)
return
}
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
deploy := &appsv1.Deployment{}
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Delete the Deployment and expect Reconcile to be called for Deployment deletion
g.Expect(c.Delete(context.TODO(), deploy)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Manually delete Deployment since GC isn't enabled in the test control plane
g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout).
Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found"))
}

View File

@@ -98,7 +98,7 @@ func (r *ReconcileCollector) Reconcile(request reconcile.Request) (reconcile.Res
// The troubleshoot spec doesn't really do anything. the work
// is performed in the troubleshootjob crd. this one is really
// primarily used as a packaging format
// primarily used as a packaging format2
return reconcile.Result{}, nil
}

View File

@@ -0,0 +1,9 @@
package collectorjob
import (
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
)
func (r *ReconcileCollectorJob) deployClusterInfo(clusterInfo *troubleshootv1beta1.ClusterInfo) error {
return nil
}

View File

@@ -20,13 +20,13 @@ import (
"context"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
troubleshootclientv1beta1 "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/typed/troubleshoot/v1beta1"
corev1 "k8s.io/api/core/v1"
// troubleshootclientv1beta1 "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/typed/troubleshoot/v1beta1"
// corev1 "k8s.io/api/core/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
// "sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -37,11 +37,6 @@ import (
var log = logf.Log.WithName("controller")
/**
* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
* business logic. Delete these comments after modifying this file.*
*/
// Add creates a new CollectorJob Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
@@ -67,13 +62,13 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &troubleshootv1beta1.CollectorJob{},
})
if err != nil {
return err
}
// err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
// IsController: true,
// OwnerType: &troubleshootv1beta1.CollectorJob{},
// })
// if err != nil {
// return err
// }
return nil
}
@@ -109,48 +104,77 @@ func (r *ReconcileCollectorJob) Reconcile(request reconcile.Request) (reconcile.
return reconcile.Result{}, err
}
namespace := instance.Namespace
if instance.Spec.Collector.Namespace != "" {
namespace = instance.Spec.Collector.Namespace
}
// namespace := instance.Namespace
// if instance.Spec.Collector.Namespace != "" {
// namespace = instance.Spec.Collector.Namespace
// }
collectorSpec, err := r.getCollectorSpec(namespace, instance.Spec.Collector.Name)
if err != nil {
return reconcile.Result{}, err
}
// collectorSpec, err := r.getCollectorSpec(namespace, instance.Spec.Collector.Name)
// if err != nil {
// return reconcile.Result{}, err
// }
for _, collector := range collectorSpec.Spec {
if err := r.reconileOneCollectorJob(collector); err != nil {
return reconcile.Result{}, nil
}
}
// for _, collector := range collectorSpec.Spec {
// if err := r.reconileOneCollectorJob(instance, collector); err != nil {
// return reconcile.Result{}, nil
// }
// }
return reconcile.Result{}, nil
}
func (r *ReconcileCollectorJob) getCollectorSpec(namespace string, name string) (*troubleshootv1beta1.Collector, error) {
cfg, err := config.GetConfig()
if err != nil {
return nil, err
}
// func (r *ReconcileCollectorJob) getCollectorSpec(namespace string, name string) (*troubleshootv1beta1.Collector, error) {
// cfg, err := config.GetConfig()
// if err != nil {
// return nil, err
// }
troubleshootClient, err := troubleshootclientv1beta1.NewForConfig(cfg)
if err != nil {
return nil, err
}
// troubleshootClient, err := troubleshootclientv1beta1.NewForConfig(cfg)
// if err != nil {
// return nil, err
// }
collector, err := troubleshootClient.Collectors(namespace).Get(name, metav1.GetOptions{})
if err != nil {
if kuberneteserrors.IsNotFound(err) {
return nil, nil
}
// collector, err := troubleshootClient.Collectors(namespace).Get(name, metav1.GetOptions{})
// if err != nil {
// if kuberneteserrors.IsNotFound(err) {
// return nil, nil
// }
return nil, err
}
// return nil, err
// }
return collector, nil
}
// return collector, nil
// }
func (r *ReconcileCollectorJob) reconileOneCollectorJob(collect *troubleshootv1beta1.Collect) error {
return nil
}
// func (r *ReconcileCollectorJob) reconileOneCollectorJob(instance *troubleshootv1beta1.CollectorJob, collect *troubleshootv1beta1.Collect) error {
// // if contains(instance.Status.Successful, idForCollector(collect)) {
// // return nil
// // }
// // if contains(instance.Status.Failed, idForCollector(collect)) {
// // return nil
// // }
// // // if it's running already...
// // if contains(instance.Status.Running, idForCollector(collect)) {
// // return nil
// // }
// return nil
// }
// func idForCollector(collector *troubleshootv1beta1.Collect) string {
// if collector.ClusterInfo != nil {
// return "cluster-info"
// }
// return ""
// }
// func contains(s []string, e string) bool {
// for _, a := range s {
// if a == e {
// return true
// }
// }
// return false
// }

View File

@@ -23,7 +23,6 @@ import (
"github.com/onsi/gomega"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"golang.org/x/net/context"
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@@ -70,19 +69,4 @@ func TestReconcile(t *testing.T) {
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
deploy := &appsv1.Deployment{}
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Delete the Deployment and expect Reconcile to be called for Deployment deletion
g.Expect(c.Delete(context.TODO(), deploy)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Manually delete Deployment since GC isn't enabled in the test control plane
g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout).
Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found"))
}

View File

@@ -18,71 +18,8 @@ package preflightjob
import (
"testing"
"time"
"github.com/onsi/gomega"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"golang.org/x/net/context"
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
var c client.Client
var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo", Namespace: "default"}}
var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"}
const timeout = time.Second * 5
func TestReconcile(t *testing.T) {
g := gomega.NewGomegaWithT(t)
instance := &troubleshootv1beta1.PreflightJob{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{})
g.Expect(err).NotTo(gomega.HaveOccurred())
c = mgr.GetClient()
recFn, requests := SetupTestReconcile(newReconciler(mgr))
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())
stopMgr, mgrStopped := StartTestManager(mgr, g)
defer func() {
close(stopMgr)
mgrStopped.Wait()
}()
// Create the PreflightJob object and expect the Reconcile and Deployment to be created
err = c.Create(context.TODO(), instance)
// The instance object may not be a valid object because it might be missing some required fields.
// Please modify the instance object by adding required fields and then remove the following if statement.
if apierrors.IsInvalid(err) {
t.Logf("failed to create object, got an invalid object error: %v", err)
return
}
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
deploy := &appsv1.Deployment{}
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Delete the Deployment and expect Reconcile to be called for Deployment deletion
g.Expect(c.Delete(context.TODO(), deploy)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout).
Should(gomega.Succeed())
// Manually delete Deployment since GC isn't enabled in the test control plane
g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout).
Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found"))
}