Skip to content

Commit

Permalink
feat(crd): add reference to Grafana secret in Cryostat CR (#432)
Browse files Browse the repository at this point in the history
* commit for now

* add updated yaml

* fixed to only include grafana secret name

* fixed image_namespace thing

* added xdescriptor for secret and fixed other things

* fixed wrong image_namespace
  • Loading branch information
maxcao13 committed Jul 27, 2022
1 parent 5ceb7db commit 4e6f0c7
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1beta1/cryostat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ type CryostatStatus struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Cryostat Conditions",xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Name of the Secret containing the generated Grafana credentials
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes:Secret"}
GrafanaSecret string `json:"grafanaSecret,omitempty"`
// Address of the deployed Cryostat web application
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:org.w3:link"}
ApplicationURL string `json:"applicationUrl"`
Expand Down Expand Up @@ -355,6 +359,7 @@ type JmxCacheOptions struct {
// must be created to instruct the operator to deploy the Cryostat application.
//+operator-sdk:csv:customresourcedefinitions:resources={{Deployment,v1},{Ingress,v1},{PersistentVolumeClaim,v1},{Secret,v1},{Service,v1},{Route,v1},{ConsoleLink,v1}}
// +kubebuilder:printcolumn:name="Application URL",type=string,JSONPath=`.status.applicationUrl`
// +kubebuilder:printcolumn:name="Grafana Secret",type=string,JSONPath=`.status.grafanaSecret`
type Cryostat struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions bundle/manifests/cryostat-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ spec:
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
- description: Name of the Secret containing the generated Grafana credentials
displayName: Grafana Secret
path: grafanaSecret
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
version: v1beta1
- description: FlightRecorder represents a target Pod that is capable of creating JDK Flight Recordings using Cryostat. The Cryostat operator creates FlightRecorder objects when it finds compatible Pods.
displayName: Flight Recorder
Expand Down
6 changes: 6 additions & 0 deletions bundle/manifests/operator.cryostat.io_cryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
- jsonPath: .status.applicationUrl
name: Application URL
type: string
- jsonPath: .status.grafanaSecret
name: Grafana Secret
type: string
name: v1beta1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -892,6 +895,9 @@ spec:
- type
type: object
type: array
grafanaSecret:
description: Name of the Secret containing the generated Grafana credentials
type: string
required:
- applicationUrl
type: object
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ annotations:
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: cryostat-operator
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.builder: operator-sdk-v1.4.0+git
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3

# Annotations for testing.
operators.operatorframework.io.test.mediatype.v1: scorecard+v1
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/operator.cryostat.io_cryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ spec:
- jsonPath: .status.applicationUrl
name: Application URL
type: string
- jsonPath: .status.grafanaSecret
name: Grafana Secret
type: string
name: v1beta1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -1520,6 +1523,9 @@ spec:
- type
type: object
type: array
grafanaSecret:
description: Name of the Secret containing the generated Grafana credentials
type: string
required:
- applicationUrl
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ spec:
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
- description: Name of the Secret containing the generated Grafana credentials
displayName: Grafana Secret
path: grafanaSecret
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
version: v1beta1
- description: FlightRecorder represents a target Pod that is capable of creating JDK Flight Recordings using Cryostat. The Cryostat operator creates FlightRecorder objects when it finds compatible Pods.
displayName: Flight Recorder
Expand Down
8 changes: 8 additions & 0 deletions internal/controllers/cryostat_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ func (r *CryostatReconciler) Reconcile(ctx context.Context, request ctrl.Request
}
}

if grafanaSecret != nil {
instance.Status.GrafanaSecret = grafanaSecret.Name
err = r.Client.Status().Update(ctx, instance)
if err != nil {
return reconcile.Result{}, err
}
}

// OpenShift-specific
if r.IsOpenShift {
err := r.createConsoleLink(ctx, instance, serviceSpecs.CoreURL.String())
Expand Down
18 changes: 18 additions & 0 deletions internal/controllers/cryostat_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ var _ = Describe("CryostatController", func() {
It("should set ApplicationURL in CR Status", func() {
t.expectStatusApplicationURL()
})
It("should set GrafanaSecret in CR Status", func() {
t.expectStatusGrafanaSecretName()
})
It("should create deployment and set owner", func() {
t.expectDeployment()
})
Expand Down Expand Up @@ -239,6 +242,9 @@ var _ = Describe("CryostatController", func() {
It("should set ApplicationURL in CR Status", func() {
t.expectStatusApplicationURL()
})
It("should set GrafanaSecret in CR Status", func() {
t.expectStatusGrafanaSecretName()
})
It("should create deployment and set owner", func() {
t.expectDeployment()
})
Expand Down Expand Up @@ -1761,6 +1767,18 @@ func (t *cryostatTestInput) expectStatusApplicationURL() {
Expect(instance.Status.ApplicationURL).To(Equal("https://cryostat.example.com"))
}

func (t *cryostatTestInput) expectStatusGrafanaSecretName() {
instance := &operatorv1beta1.Cryostat{}
err := t.Client.Get(context.Background(), types.NamespacedName{Name: "cryostat", Namespace: "default"}, instance)

t.reconcileCryostatFully()

err = t.Client.Get(context.Background(), types.NamespacedName{Name: "cryostat", Namespace: "default"}, instance)
Expect(err).ToNot(HaveOccurred())

Expect(instance.Status.GrafanaSecret).To(Equal("cryostat-grafana-basic"))
}

func (t *cryostatTestInput) expectDeployment() {
deployment := &appsv1.Deployment{}
err := t.Client.Get(context.Background(), types.NamespacedName{Name: "cryostat", Namespace: "default"}, deployment)
Expand Down

0 comments on commit 4e6f0c7

Please sign in to comment.