Skip to content

Commit

Permalink
Merge pull request #69 from rancher/fix-install-namespace
Browse files Browse the repository at this point in the history
If rancher logging is already installed, create logging CRs in its control namespace
  • Loading branch information
kralicky authored Jun 25, 2021
2 parents 065a104 + 546e4bd commit 2aca5a8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions apis/demo/v1alpha1/opnidemo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type OpniDemoSpec struct {
NulogServiceCPURequest string `json:"nulogServiceCpuRequest"`
NulogTrainImage string `json:"nulogTrainImage"`
CreateKibanaDashboard *bool `json:"createKibanaDashboard,omitempty"`
LoggingCRDNamespace *string `json:"loggingCrdNamespace,omitempty"`
}

type ComponentsSpec struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/demo/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/crd/bases/demo.opni.io_opnidemoes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ spec:
type: string
elasticsearchUser:
type: string
loggingCrdNamespace:
type: string
minioAccessKey:
type: string
minioSecretKey:
Expand Down
71 changes: 71 additions & 0 deletions controllers/demo/opnidemo_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"

"github.com/rancher/opni/apis/demo/v1alpha1"
)
Expand Down Expand Up @@ -267,4 +268,74 @@ var _ = Describe("OpniDemo Controller", func() {
}, timeout, interval)
})
})
When("installing without rancher logging", func() {
demo := v1alpha1.OpniDemo{
ObjectMeta: v1.ObjectMeta{
Name: crName + "2",
Namespace: crNamespace,
},
Spec: v1alpha1.OpniDemoSpec{
Components: v1alpha1.ComponentsSpec{
Infra: v1alpha1.InfraStack{
DeployHelmController: true,
DeployNvidiaPlugin: true,
},
Opni: v1alpha1.OpniStack{
Minio: v1alpha1.ChartOptions{
Enabled: true,
},
Nats: v1alpha1.ChartOptions{
Enabled: true,
},
Elastic: v1alpha1.ChartOptions{
Enabled: true,
},
RancherLogging: v1alpha1.ChartOptions{
Enabled: false,
},
DeployGpuServices: true,
},
},
MinioAccessKey: "testAccessKey",
MinioSecretKey: "testSecretKey",
MinioVersion: "1",
NatsVersion: "1",
NatsPassword: "password",
NatsReplicas: 1,
NatsMaxPayload: 12345,
NvidiaVersion: "1",
ElasticsearchUser: "user",
ElasticsearchPassword: "password",
NulogServiceCPURequest: "1",
NulogTrainImage: "does-not-exist/name:tag",
LoggingCRDNamespace: pointer.String("default"),
},
}
It("should succeed", func() {
Expect(k8sClient.Create(context.Background(), &demo)).To(Succeed())
Eventually(func() error {
cluster := v1alpha1.OpniDemo{}
return k8sClient.Get(context.Background(), types.NamespacedName{
Name: crName + "2",
Namespace: crNamespace,
}, &cluster)
}, timeout, interval).Should(BeNil())
})
It("should create the logging CRs in the control namespace", func() {
Eventually(func() error {
clusterFlow := loggingv1beta1.ClusterFlow{}
return k8sClient.Get(context.Background(), types.NamespacedName{
Namespace: "default",
Name: "aiops-demo-log-flow",
}, &clusterFlow)
}, timeout, interval)
Eventually(func() error {
clusterOutput := loggingv1beta1.ClusterOutput{}
return k8sClient.Get(context.Background(), types.NamespacedName{
Namespace: "default",
Name: "aiops-demo-log-output",
}, &clusterOutput)
}, timeout, interval)
})
})
})
18 changes: 16 additions & 2 deletions pkg/demo/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,17 @@ const (
)

func BuildClusterFlow(spec *demov1alpha1.OpniDemo) *loggingv1beta1.ClusterFlow {
controlNamespace := spec.Namespace
if !spec.Spec.Components.Opni.RancherLogging.Enabled {
if ns := spec.Spec.LoggingCRDNamespace; ns != nil {
controlNamespace = *ns
}
}

return &loggingv1beta1.ClusterFlow{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterFlowName,
Namespace: spec.Namespace,
Namespace: controlNamespace,
},
Spec: loggingv1beta1.ClusterFlowSpec{
Match: []loggingv1beta1.ClusterMatch{
Expand Down Expand Up @@ -551,10 +558,17 @@ func BuildClusterFlow(spec *demov1alpha1.OpniDemo) *loggingv1beta1.ClusterFlow {
}

func BuildClusterOutput(spec *demov1alpha1.OpniDemo) *loggingv1beta1.ClusterOutput {
controlNamespace := spec.Namespace
if !spec.Spec.Components.Opni.RancherLogging.Enabled {
if ns := spec.Spec.LoggingCRDNamespace; ns != nil {
controlNamespace = *ns
}
}

return &loggingv1beta1.ClusterOutput{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterOutputName,
Namespace: spec.Namespace,
Namespace: controlNamespace,
},
Spec: loggingv1beta1.ClusterOutputSpec{
OutputSpec: loggingv1beta1.OutputSpec{
Expand Down
12 changes: 12 additions & 0 deletions pkg/opnictl/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ func BuildCreateDemoCmd() *cobra.Command {
opniDemo.Spec.Components.Infra.DeployNvidiaPlugin = (deployNvidiaPlugin == "true")
}

if !opniDemo.Spec.Components.Opni.RancherLogging.Enabled {
var response string
if err := survey.AskOne(&survey.Input{
Message: "Enter the namespace where Rancher Logging is installed:",
Default: "cattle-logging-system",
Help: "This is the \"control namespace\" where the BanzaiCloud Logging Operator looks for ClusterFlow and ClusterOutput resources.",
}, &response); err != nil {
return err
}
opniDemo.Spec.LoggingCRDNamespace = &response
}

var loggingValues = map[string]intstr.IntOrString{}
provider, err := providers.Detect(cmd.Context(), common.K8sClient)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions staging/staging_autogen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ spec:
type: string
elasticsearchUser:
type: string
loggingCrdNamespace:
type: string
minioAccessKey:
type: string
minioSecretKey:
Expand Down

0 comments on commit 2aca5a8

Please sign in to comment.