Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify setup of Enterprise Search access through Kibana UI #4598

Merged
merged 29 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
caf46b8
Introduce Enterprise Search reference to the Kibana CRD
sebgl Jun 29, 2021
243c146
Move ent naming functions around for better reuse
sebgl Jun 29, 2021
0e2bdfe
Rely on convenient kibana.ESAssociation() accessor
sebgl Jun 29, 2021
e22a187
Add k8s.ObjectExists() help function
sebgl Jun 29, 2021
4aa8b96
Homogenize association controllers labels comments
sebgl Jun 29, 2021
c9505e3
Make ES user creation optional in the assoc controller through an opt…
sebgl Jun 29, 2021
23822ca
Add kibana-ent association controller
sebgl Jun 29, 2021
86a183e
Check whether the referenced resource (not necessarily es) exists
sebgl Jun 29, 2021
27d89af
Configure Kibana for Enterprise Search connectivity
sebgl Jun 29, 2021
e808dba
Allow association configuration with no es auth (secretName: "-")
sebgl Jun 29, 2021
06e5556
Make the association controller reconciliation work when no es auth i…
sebgl Jun 29, 2021
f978a98
Unrelated typo fix
sebgl Jun 29, 2021
01cedb8
Minor association controller unit test fixes
sebgl Jun 29, 2021
c794a4e
Make multi-association watches work when no ES reference is required
sebgl Jun 29, 2021
2e007db
Add an integration test for Kibana<->Enterprise Search association st…
sebgl Jun 29, 2021
06dd152
Add missing license header
sebgl Jun 29, 2021
0641609
Make linter happier
sebgl Jun 29, 2021
4dcebbd
Rename AssociatedNamer to ReferencedResourceNamer
sebgl Jun 29, 2021
9a7a987
Refactor dynamic watches
sebgl Jun 29, 2021
2863996
Remove the need for ReferencedResourceExists()
sebgl Jun 29, 2021
084b668
Fix unit tests
sebgl Jun 29, 2021
18836be
Fixes from PR review
sebgl Jul 1, 2021
3da7275
Make linter happy
sebgl Jul 1, 2021
20522ab
Fix comments
sebgl Jul 5, 2021
edac7aa
Report es association status in status.elasticsearchAssociationStatus
sebgl Jul 5, 2021
b5a11e3
Regen CRDs
sebgl Jul 5, 2021
e8585d4
Gen api docs
sebgl Jul 5, 2021
b64d912
Regen v1beta1 crds
sebgl Jul 5, 2021
c4ae1a0
Fix kibana status e2e test
sebgl Jul 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ func registerControllers(mgr manager.Manager, params operator.Parameters, access
{name: "APM-ES", registerFunc: associationctl.AddApmES},
{name: "APM-KB", registerFunc: associationctl.AddApmKibana},
{name: "KB-ES", registerFunc: associationctl.AddKibanaES},
{name: "KB-ENT", registerFunc: associationctl.AddKibanaEnt},
{name: "ENT-ES", registerFunc: associationctl.AddEntES},
{name: "BEAT-ES", registerFunc: associationctl.AddBeatES},
{name: "BEAT-KB", registerFunc: associationctl.AddBeatKibana},
Expand Down Expand Up @@ -708,7 +709,7 @@ func garbageCollectUsers(cfg *rest.Config, managedNamespaces []string) {
}
err = ugc.
For(&apmv1.ApmServerList{}, associationctl.ApmAssociationLabelNamespace, associationctl.ApmAssociationLabelName).
For(&kbv1.KibanaList{}, associationctl.KibanaESAssociationLabelNamespace, associationctl.KibanaESAssociationLabelName).
For(&kbv1.KibanaList{}, associationctl.KibanaAssociationLabelNamespace, associationctl.KibanaAssociationLabelName).
For(&entv1.EnterpriseSearchList{}, associationctl.EntESAssociationLabelNamespace, associationctl.EntESAssociationLabelName).
For(&beatv1beta1.BeatList{}, associationctl.BeatAssociationLabelNamespace, associationctl.BeatAssociationLabelName).
For(&agentv1alpha1.AgentList{}, associationctl.AgentAssociationLabelNamespace, associationctl.AgentAssociationLabelName).
Expand Down
31 changes: 30 additions & 1 deletion config/crds/v1/all-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6136,6 +6136,28 @@ spec:
required:
- name
type: object
enterpriseSearchRef:
description: EnterpriseSearchRef is a reference to an EnterpriseSearch
running in the same Kubernetes cluster. Kibana provides the default
Enterprise Search UI starting version 7.14.
properties:
name:
description: Name of the Kubernetes object.
type: string
namespace:
description: Namespace of the Kubernetes object. If empty, defaults
to the current namespace.
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes
service which will be used to make requests to the referenced
object. It has to be in the same namespace as the referenced
resource. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
http:
description: HTTP holds the HTTP layer configuration for Kibana.
properties:
Expand Down Expand Up @@ -6630,13 +6652,20 @@ spec:
description: KibanaStatus defines the observed state of Kibana
properties:
associationStatus:
description: AssociationStatus is the status of an association resource.
description: AssociationStatus is the status of any auto-linking to
Elasticsearch clusters. This was kept as "associationStatus" rather
than a more consistent "elasticsearchAssociationStatus" for backward-compatibility
reasons.
type: string
availableNodes:
description: AvailableNodes is the number of available replicas in
the deployment.
format: int32
type: integer
enterpriseSearchAssociationStatus:
description: EnterpriseSearchAssociationStatus is the status of any
auto-linking to Enterprise Search.
type: string
health:
description: Health of the deployment.
type: string
Expand Down
31 changes: 30 additions & 1 deletion config/crds/v1/bases/kibana.k8s.elastic.co_kibanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ spec:
required:
- name
type: object
enterpriseSearchRef:
description: EnterpriseSearchRef is a reference to an EnterpriseSearch
running in the same Kubernetes cluster. Kibana provides the default
Enterprise Search UI starting version 7.14.
properties:
name:
description: Name of the Kubernetes object.
type: string
namespace:
description: Namespace of the Kubernetes object. If empty, defaults
to the current namespace.
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes
service which will be used to make requests to the referenced
object. It has to be in the same namespace as the referenced
resource. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
http:
description: HTTP holds the HTTP layer configuration for Kibana.
properties:
Expand Down Expand Up @@ -7263,13 +7285,20 @@ spec:
description: KibanaStatus defines the observed state of Kibana
properties:
associationStatus:
description: AssociationStatus is the status of an association resource.
description: AssociationStatus is the status of any auto-linking to
Elasticsearch clusters. This was kept as "associationStatus" rather
than a more consistent "elasticsearchAssociationStatus" for backward-compatibility
reasons.
type: string
availableNodes:
description: AvailableNodes is the number of available replicas in
the deployment.
format: int32
type: integer
enterpriseSearchAssociationStatus:
description: EnterpriseSearchAssociationStatus is the status of any
auto-linking to Enterprise Search.
type: string
health:
description: Health of the deployment.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6181,6 +6181,28 @@ spec:
required:
- name
type: object
enterpriseSearchRef:
description: EnterpriseSearchRef is a reference to an EnterpriseSearch
running in the same Kubernetes cluster. Kibana provides the default
Enterprise Search UI starting version 7.14.
properties:
name:
description: Name of the Kubernetes object.
type: string
namespace:
description: Namespace of the Kubernetes object. If empty, defaults
to the current namespace.
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes
service which will be used to make requests to the referenced
object. It has to be in the same namespace as the referenced
resource. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
http:
description: HTTP holds the HTTP layer configuration for Kibana.
properties:
Expand Down Expand Up @@ -6675,13 +6697,20 @@ spec:
description: KibanaStatus defines the observed state of Kibana
properties:
associationStatus:
description: AssociationStatus is the status of an association resource.
description: AssociationStatus is the status of any auto-linking to
Elasticsearch clusters. This was kept as "associationStatus" rather
than a more consistent "elasticsearchAssociationStatus" for backward-compatibility
reasons.
type: string
availableNodes:
description: AvailableNodes is the number of available replicas in
the deployment.
format: int32
type: integer
enterpriseSearchAssociationStatus:
description: EnterpriseSearchAssociationStatus is the status of any
auto-linking to Enterprise Search.
type: string
health:
description: Health of the deployment.
type: string
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/common/v1/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ const (
KibanaConfigAnnotationNameBase = "association.k8s.elastic.co/kb-conf"
KibanaAssociationType = "kibana"

EntConfigAnnotationNameBase = "association.k8s.elastic.co/ent-conf"
EntAssociationType = "ent"

AssociationUnknown AssociationStatus = ""
AssociationPending AssociationStatus = "Pending"
AssociationEstablished AssociationStatus = "Established"
Expand All @@ -106,6 +109,10 @@ const (
// should use `SingletonAssociationID` as their `AssociationID`. On the contrary, Agent can have unbounded number
// of Associations so Agent-ES Associations should _not_ use `SingletonAssociationID`.
SingletonAssociationID = ""

// NoAuthRequiredValue is the value set for AuthSecretName if no authentication
// credentials are necessary for that association.
NoAuthRequiredValue = "-"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming here that no secret will ever be named "-". Since this is a value we set with our own secret naming scheme it should be OK.
It's somewhat nice because it doesn't break the existing schema and is quite easy to manipulate in the code.
However it also feels a bit "implicit", we could also modify the assoc conf schema to make things more explicit. WDYT?

)

// Associated represents an Elastic stack resource that is associated with other stack resources.
Expand Down Expand Up @@ -193,14 +200,23 @@ func (ac *AssociationConf) IsConfigured() bool {
return ac.AuthIsConfigured() && ac.URLIsConfigured()
}

// AuthIsConfigured returns true if all the auth fields are set.
// AuthIsConfigured returns true if the auth fields are set.
func (ac *AssociationConf) AuthIsConfigured() bool {
if ac == nil {
return false
}
if ac.NoAuthRequired() {
// auth fields are not required, but still configured
return true
}
// ensure both secret name and secret key are provided
return ac.AuthSecretName != "" && ac.AuthSecretKey != ""
}

func (ac *AssociationConf) NoAuthRequired() bool {
return ac.AuthSecretName == NoAuthRequiredValue
}

// CAIsConfigured returns true if the CA field is set.
func (ac *AssociationConf) CAIsConfigured() bool {
if ac == nil {
Expand Down
65 changes: 65 additions & 0 deletions pkg/apis/common/v1/association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func TestAssociationConfIsConfigured(t *testing.T) {
},
want: true,
},
{
name: "correctly configured with no auth required",
assocConf: &AssociationConf{
AuthSecretName: "-",
CASecretName: "ca-secret",
URL: "https://my-es.svc",
},
want: true,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -252,3 +261,59 @@ func TestAssociationStatusMap_String(t *testing.T) {
})
}
}

func TestAssociationConf_AuthIsConfigured(t *testing.T) {
type fields struct {
AuthSecretName string
AuthSecretKey string
}
tests := []struct {
name string
fields fields
want bool
}{
{
name: "auth configured",
fields: fields{
AuthSecretName: "secret-name",
AuthSecretKey: "secret-key",
},
want: true,
},
{
name: "auth secret key not configured",
fields: fields{
AuthSecretName: "secret-name",
AuthSecretKey: "",
},
want: false,
},
{
name: "auth not configured",
fields: fields{
AuthSecretName: "",
AuthSecretKey: "",
},
want: false,
},
{
name: "auth not required (but still configured)",
fields: fields{
AuthSecretName: "-",
AuthSecretKey: "",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ac := &AssociationConf{
AuthSecretName: tt.fields.AuthSecretName,
AuthSecretKey: tt.fields.AuthSecretKey,
}
if got := ac.AuthIsConfigured(); got != tt.want {
t.Errorf("AuthIsConfigured() = %v, want %v", got, tt.want)
}
})
}
}
4 changes: 4 additions & 0 deletions pkg/apis/enterprisesearch/v1/enterprisesearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
common_name "github.com/elastic/cloud-on-k8s/pkg/controller/common/name"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -19,6 +20,9 @@ const (
Kind = "EnterpriseSearch"
)

// Namer is a Namer that is configured with the defaults for resources related to an EnterpriseSearch resource.
var Namer = common_name.NewNamer("ent")

// EnterpriseSearchSpec holds the specification of an Enterprise Search resource.
type EnterpriseSearchSpec struct {
// Version of Enterprise Search.
Expand Down
Loading