Skip to content

Commit

Permalink
Add KibanaRef to Beats
Browse files Browse the repository at this point in the history
  • Loading branch information
pebrc committed Jun 9, 2020
1 parent 4d6c17f commit ce20b9a
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 101 deletions.
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 APM agent central configuration
management in Kibana.
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
kibanaAssocationStatus:
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 APM agent central configuration
management in Kibana.
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
kibanaAssocationStatus:
description: AssociationStatus is the status of an association resource.
type: string
type: object
type: object
version: v1beta1
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"`

// 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"`
ElasticsearchAssociation commonv1.AssociationStatus `json:"elasticsearchAssociationStatus,omitempty"`

// +kubebuilder:validation:Optional
KibanaAssocation commonv1.AssociationStatus `json:"kibanaAssocationStatus,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
}

var _ commonv1.Associated = &Beat{}

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

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

type BeatESAssociation struct {
*Beat
}

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

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

func (b *Beat) AssociatedType() string {
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.ElasticsearchAssociation
}

func (b *Beat) ElasticsearchRef() commonv1.ObjectSelector {
return b.Spec.ElasticsearchRef
func (b *BeatESAssociation) SetAssociationStatus(status commonv1.AssociationStatus) {
b.Status.ElasticsearchAssociation = 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.KibanaAssocation
}

var _ commonv1.Associated = &Beat{}
var _ commonv1.Association = &Beat{}
func (b *BeatKibanaAssociation) SetAssociationStatus(status commonv1.AssociationStatus) {
b.Status.KibanaAssocation = 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
}

// 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
}

// +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

0 comments on commit ce20b9a

Please sign in to comment.