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

Add KibanaRef to Beats and support setup.kibana #3211

Merged
merged 11 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func execute() {
if manageBeatAutodiscoverRBAC {
beatcommon.EnableAutodiscoverRBACManagement()
}

if err = apmserver.Add(mgr, params); err != nil {
log.Error(err, "unable to create controller", "controller", "ApmServer")
os.Exit(1)
Expand Down Expand Up @@ -390,6 +389,10 @@ func execute() {
log.Error(err, "unable to create controller", "controller", "beat-es-association")
os.Exit(1)
}
if err = associationctl.AddBeatKibana(mgr, accessReviewer, params); err != nil {
log.Error(err, "unable to create controller", "controller", "beat-kibana-association")
os.Exit(1)
}

if err = remoteca.Add(mgr, accessReviewer, params); err != nil {
log.Error(err, "unable to create controller", "controller", "RemoteClusterCertificateAuthorites")
Expand Down
24 changes: 21 additions & 3 deletions config/crds/all-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,21 @@ spec:
description: Image is the Beat Docker image to deploy. Version and Type
have to match the Beat in the image.
type: string
kibanaRef:
description: KibanaRef is a reference to a Kibana instance running in
the same Kubernetes cluster. It allows automatic setup of dashboards
and visualizations.
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
required:
- name
type: object
serviceAccountName:
description: ServiceAccountName is used to check access from the current
resource to Elasticsearch resource in a different namespace. Can only
Expand All @@ -576,17 +591,20 @@ spec:
status:
description: BeatStatus defines the observed state of a Beat.
properties:
associationStatus:
description: AssociationStatus is the status of an association resource.
type: string
availableNodes:
format: int32
type: integer
elasticsearchAssociationStatus:
description: AssociationStatus is the status of an association resource.
type: string
expectedNodes:
format: int32
type: integer
health:
type: string
kibanaAssociationStatus:
description: AssociationStatus is the status of an association resource.
type: string
type: object
version: v1beta1
versions:
Expand Down
24 changes: 21 additions & 3 deletions config/crds/bases/beat.k8s.elastic.co_beats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12160,6 +12160,21 @@ spec:
description: Image is the Beat Docker image to deploy. Version and Type
have to match the Beat in the image.
type: string
kibanaRef:
description: KibanaRef is a reference to a Kibana instance running in
the same Kubernetes cluster. It allows automatic setup of dashboards
and visualizations.
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
required:
- name
type: object
serviceAccountName:
description: ServiceAccountName is used to check access from the current
resource to Elasticsearch resource in a different namespace. Can only
Expand All @@ -12181,17 +12196,20 @@ spec:
status:
description: BeatStatus defines the observed state of a Beat.
properties:
associationStatus:
description: AssociationStatus is the status of an association resource.
type: string
availableNodes:
format: int32
type: integer
elasticsearchAssociationStatus:
description: AssociationStatus is the status of an association resource.
type: string
expectedNodes:
format: int32
type: integer
health:
type: string
kibanaAssociationStatus:
description: AssociationStatus is the status of an association resource.
type: string
type: object
type: object
version: v1beta1
Expand Down
1 change: 1 addition & 0 deletions docs/reference/api-docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ BeatSpec defines the desired state of a Beat.
| *`type`* __string__ | Type is the type of the Beat to deploy (filebeat, metricbeat, etc.). Any string can be used, but well-known types will be recognized and will allow to provide sane default configurations.
| *`version`* __string__ | Version of the Beat.
| *`elasticsearchRef`* __xref:{anchor_prefix}-github.aaakk.us.kg-elastic-cloud-on-k8s-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster.
| *`kibanaRef`* __xref:{anchor_prefix}-github.aaakk.us.kg-elastic-cloud-on-k8s-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | KibanaRef is a reference to a Kibana instance running in the same Kubernetes cluster. It allows automatic setup of dashboards and visualizations.
| *`image`* __string__ | Image is the Beat Docker image to deploy. Version and Type have to match the Beat in the image.
| *`config`* __xref:{anchor_prefix}-github.aaakk.us.kg-elastic-cloud-on-k8s-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Beat configuration. If provided, it will override the default configuration.
| *`serviceAccountName`* __string__ | ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apm/v1/apmserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func (akb *ApmKibanaAssociation) Associated() commonv1.Associated {
}

func (akb *ApmKibanaAssociation) AssociationConfAnnotationName() string {
return "association.k8s.elastic.co/kb-conf"
return commonv1.KibanaConfigAnnotationName
}

func (akb *ApmKibanaAssociation) AssociatedType() string {
return "kibana"
return commonv1.KibanaAssociationType
}

func (akb *ApmKibanaAssociation) AssociationRef() commonv1.ObjectSelector {
Expand Down
123 changes: 93 additions & 30 deletions pkg/apis/beat/v1beta1/beat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type BeatSpec struct {
// +kubebuilder:validation:Optional
ElasticsearchRef commonv1.ObjectSelector `json:"elasticsearchRef,omitempty"`

// KibanaRef is a reference to a Kibana instance running in the same Kubernetes cluster.
// It allows automatic setup of dashboards and visualizations.
KibanaRef commonv1.ObjectSelector `json:"kibanaRef,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note for other reviewers: I was wondering if we needed the Optional tag here since all the other ones have it, it looks like we only need it if we also set kubebuilder:validation:Required on the package which marks them all as required by default


// Image is the Beat Docker image to deploy. Version and Type have to match the Beat in the image.
// +kubebuilder:validation:Optional
Image string `json:"image,omitempty"`
Expand Down Expand Up @@ -70,7 +74,10 @@ type BeatStatus struct {
Health BeatHealth `json:"health,omitempty"`

// +kubebuilder:validation:Optional
Association commonv1.AssociationStatus `json:"associationStatus,omitempty"`
ElasticsearchAssociationStatus commonv1.AssociationStatus `json:"elasticsearchAssociationStatus,omitempty"`

// +kubebuilder:validation:Optional
KibanaAssocationStatus commonv1.AssociationStatus `json:"kibanaAssociationStatus,omitempty"`
}

type BeatHealth string
Expand Down Expand Up @@ -106,65 +113,121 @@ type Beat struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BeatSpec `json:"spec,omitempty"`
Status BeatStatus `json:"status,omitempty"`
assocConf *commonv1.AssociationConf `json:"-"` //nolint:govet
Spec BeatSpec `json:"spec,omitempty"`
Status BeatStatus `json:"status,omitempty"`
esAssocConf *commonv1.AssociationConf `json:"-"` // nolint:govet
kbAssocConf *commonv1.AssociationConf `json:"-"` // nolint:govet
}

func (b *Beat) Associated() commonv1.Associated {
if b != nil {
return b
var _ commonv1.Associated = &Beat{}

func (b *Beat) GetAssociations() []commonv1.Association {
return []commonv1.Association{
&BeatESAssociation{Beat: b},
&BeatKibanaAssociation{Beat: b},
}
return &Beat{}
}

func (b *Beat) AssociatedType() string {
func (b *Beat) ServiceAccountName() string {
return b.Spec.ServiceAccountName
}

// IsMarkedForDeletion returns true if the Beat is going to be deleted
func (b *Beat) IsMarkedForDeletion() bool {
return !b.DeletionTimestamp.IsZero()
}

func (b *Beat) ElasticsearchRef() commonv1.ObjectSelector {
return b.Spec.ElasticsearchRef
}

type BeatESAssociation struct {
*Beat
}

var _ commonv1.Association = &BeatESAssociation{}

func (b *BeatESAssociation) Associated() commonv1.Associated {
if b == nil {
return nil
}
if b.Beat == nil {
b.Beat = &Beat{}
}
return b.Beat
}

func (b *BeatESAssociation) AssociatedType() string {
return commonv1.ElasticsearchAssociationType
}

func (b *Beat) AssociationRef() commonv1.ObjectSelector {
func (b *BeatESAssociation) AssociationRef() commonv1.ObjectSelector {
return b.Spec.ElasticsearchRef.WithDefaultNamespace(b.Namespace)
}

func (b *Beat) AssociationConfAnnotationName() string {
func (b *BeatESAssociation) AssociationConfAnnotationName() string {
return commonv1.ElasticsearchConfigAnnotationName
}

func (b *Beat) GetAssociations() []commonv1.Association {
return []commonv1.Association{b}
func (b *BeatESAssociation) AssociationConf() *commonv1.AssociationConf {
return b.esAssocConf
}

// IsMarkedForDeletion returns true if the Beat is going to be deleted
func (b *Beat) IsMarkedForDeletion() bool {
return !b.DeletionTimestamp.IsZero()
func (b *BeatESAssociation) SetAssociationConf(conf *commonv1.AssociationConf) {
b.esAssocConf = conf
}

func (b *Beat) ServiceAccountName() string {
return b.Spec.ServiceAccountName
func (b *BeatESAssociation) AssociationStatus() commonv1.AssociationStatus {
return b.Status.ElasticsearchAssociationStatus
}

func (b *Beat) ElasticsearchRef() commonv1.ObjectSelector {
return b.Spec.ElasticsearchRef
func (b *BeatESAssociation) SetAssociationStatus(status commonv1.AssociationStatus) {
b.Status.ElasticsearchAssociationStatus = status
}

func (b *Beat) AssociationConf() *commonv1.AssociationConf {
return b.assocConf
type BeatKibanaAssociation struct {
*Beat
}

func (b *Beat) SetAssociationConf(assocConf *commonv1.AssociationConf) {
b.assocConf = assocConf
var _ commonv1.Association = &BeatKibanaAssociation{}

func (b *BeatKibanaAssociation) AssociationConf() *commonv1.AssociationConf {
return b.kbAssocConf
}

func (b *Beat) AssociationStatus() commonv1.AssociationStatus {
return b.Status.Association
func (b *BeatKibanaAssociation) SetAssociationConf(conf *commonv1.AssociationConf) {
b.kbAssocConf = conf
}

func (b *Beat) SetAssociationStatus(status commonv1.AssociationStatus) {
b.Status.Association = status
func (b *BeatKibanaAssociation) AssociationStatus() commonv1.AssociationStatus {
return b.Status.KibanaAssocationStatus
}

var _ commonv1.Associated = &Beat{}
var _ commonv1.Association = &Beat{}
func (b *BeatKibanaAssociation) SetAssociationStatus(status commonv1.AssociationStatus) {
b.Status.KibanaAssocationStatus = status
}

func (b *BeatKibanaAssociation) Associated() commonv1.Associated {
if b == nil {
return nil
}
if b.Beat == nil {
b.Beat = &Beat{}
}
return b.Beat
}

func (b *BeatKibanaAssociation) AssociatedType() string {
return commonv1.KibanaAssociationType
}

func (b *BeatKibanaAssociation) AssociationRef() commonv1.ObjectSelector {
return b.Spec.KibanaRef.WithDefaultNamespace(b.Namespace)
}

func (b *BeatKibanaAssociation) AssociationConfAnnotationName() string {
return commonv1.KibanaConfigAnnotationName
}

// +kubebuilder:object:root=true

Expand Down
50 changes: 48 additions & 2 deletions pkg/apis/beat/v1beta1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions pkg/apis/common/v1/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const (
ElasticsearchConfigAnnotationName = "association.k8s.elastic.co/es-conf"
ElasticsearchAssociationType = "elasticsearch"

KibanaAssociationType = "kibana"
KibanaConfigAnnotationName = "association.k8s.elastic.co/kb-conf"

AssociationUnknown AssociationStatus = ""
AssociationPending AssociationStatus = "Pending"
AssociationEstablished AssociationStatus = "Established"
Expand Down
Loading