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

Remove Elasticsearch field from CRDs #1687

Merged
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
29 changes: 0 additions & 29 deletions config/crds/apm_v1alpha1_apmserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,6 @@ spec:
config:
description: Config represents the APM configuration.
type: object
elasticsearch:
description: Elasticsearch configures how the APM server connects to
Elasticsearch
properties:
auth:
description: Auth configures authentication for APM Server to use.
properties:
secret:
description: SecretKeyRef is a secret that contains the credentials
to use.
type: object
type: object
hosts:
description: Hosts are the URLs of the output Elasticsearch nodes.
items:
type: string
type: array
ssl:
description: SSL configures TLS-related configuration for Elasticsearch
properties:
certificateAuthorities:
description: CertificateAuthorities is a secret that contains
a `tls.crt` entry that contain certificates for server verifications.
properties:
secretName:
type: string
type: object
type: object
type: object
elasticsearchRef:
description: ElasticsearchRef references an Elasticsearch resource in
the Kubernetes cluster. If the namespace is not specified, the current
Expand Down
24 changes: 0 additions & 24 deletions config/crds/kibana_v1alpha1_kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ spec:
config:
description: Config represents Kibana configuration.
type: object
elasticsearch:
description: Elasticsearch configures how Kibana connects to Elasticsearch
properties:
auth:
description: Auth configures authentication for Kibana to use.
properties:
secret:
description: SecretKeyRef is a secret that contains the credentials
to use.
type: object
type: object
certificateAuthorities:
description: CertificateAuthorities names a secret that contains
a CA file entry to use.
properties:
secretName:
type: string
type: object
url:
description: ElasticsearchURL is the URL to the target Elasticsearch
type: string
required:
- url
type: object
elasticsearchRef:
description: ElasticsearchRef references an Elasticsearch resource in
the Kubernetes cluster. If the namespace is not specified, the current
Expand Down
46 changes: 11 additions & 35 deletions pkg/apis/apm/v1alpha1/apmserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ type ApmServerSpec struct {
// If the namespace is not specified, the current resource namespace will be used.
ElasticsearchRef commonv1alpha1.ObjectSelector `json:"elasticsearchRef,omitempty"`

// Elasticsearch configures how the APM server connects to Elasticsearch
// +optional
Elasticsearch ElasticsearchOutput `json:"elasticsearch,omitempty"`

// PodTemplate can be used to propagate configuration to APM Server pods.
// This allows specifying custom annotations, labels, environment variables,
// affinity, resources, etc. for the pods created from this NodeSpec.
Expand All @@ -54,26 +50,6 @@ type ApmServerSpec struct {
SecureSettings []commonv1alpha1.SecretRef `json:"secureSettings,omitempty"`
}

// Elasticsearch contains configuration for the Elasticsearch output
type ElasticsearchOutput struct {

// Hosts are the URLs of the output Elasticsearch nodes.
Hosts []string `json:"hosts,omitempty"`

// Auth configures authentication for APM Server to use.
Auth commonv1alpha1.ElasticsearchAuth `json:"auth,omitempty"`

// SSL configures TLS-related configuration for Elasticsearch
SSL ElasticsearchOutputSSL `json:"ssl,omitempty"`
}

// ElasticsearchOutputSSL contains TLS-related configuration for Elasticsearch
type ElasticsearchOutputSSL struct {
// CertificateAuthorities is a secret that contains a `tls.crt` entry that contain certificates for server
// verifications.
CertificateAuthorities commonv1alpha1.SecretRef `json:"certificateAuthorities,omitempty"`
}

// ApmServerHealth expresses the status of the Apm Server instances.
type ApmServerHealth string

Expand Down Expand Up @@ -101,11 +77,6 @@ func (as ApmServerStatus) IsDegraded(prev ApmServerStatus) bool {
return prev.Health == ApmServerGreen && as.Health != ApmServerGreen
}

// IsConfigured returns true if the output configuration is populated with non-default values.
func (e ElasticsearchOutput) IsConfigured() bool {
return len(e.Hosts) > 0
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand All @@ -121,8 +92,9 @@ type ApmServer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ApmServerSpec `json:"spec,omitempty"`
Status ApmServerStatus `json:"status,omitempty"`
Spec ApmServerSpec `json:"spec,omitempty"`
Status ApmServerStatus `json:"status,omitempty"`
assocConf *commonv1alpha1.AssociationConf
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -143,10 +115,6 @@ func (as *ApmServer) IsMarkedForDeletion() bool {
return !as.DeletionTimestamp.IsZero()
}

func (as *ApmServer) ElasticsearchAuth() commonv1alpha1.ElasticsearchAuth {
return as.Spec.Elasticsearch.Auth
}

func (as *ApmServer) ElasticsearchRef() commonv1alpha1.ObjectSelector {
return as.Spec.ElasticsearchRef
}
Expand All @@ -160,3 +128,11 @@ func (as *ApmServer) SecureSettings() []commonv1alpha1.SecretRef {
func (as *ApmServer) Kind() string {
return Kind
}

func (as *ApmServer) AssociationConf() *commonv1alpha1.AssociationConf {
return as.assocConf
}

func (as *ApmServer) SetAssociationConf(assocConf *commonv1alpha1.AssociationConf) {
as.assocConf = assocConf
}
46 changes: 5 additions & 41 deletions pkg/apis/apm/v1alpha1/zz_generated.deepcopy.go

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

74 changes: 73 additions & 1 deletion pkg/apis/common/v1alpha1/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,78 @@ const (
type Associated interface {
metav1.Object
runtime.Object
ElasticsearchAuth() ElasticsearchAuth
ElasticsearchRef() ObjectSelector
AssociationConf() *AssociationConf
}

// Associator describes an object that allows its association to be set.
type Associator interface {
metav1.Object
runtime.Object
SetAssociationConf(*AssociationConf)
}

// AssociationConf holds the association configuration of an Elasticsearch cluster.
type AssociationConf struct {
AuthSecretName string `json:"authSecretName"`
AuthSecretKey string `json:"authSecretKey"`
CASecretName string `json:"caSecretName"`
URL string `json:"url"`
}

// IsConfigured returns true if all the fields are set.
func (esac *AssociationConf) IsConfigured() bool {
return esac.AuthIsConfigured() && esac.CAIsConfigured() && esac.URLIsConfigured()
}

// AuthIsConfigured returns true if all the auth fields are set.
func (esac *AssociationConf) AuthIsConfigured() bool {
if esac == nil {
return false
}
return esac.AuthSecretName != "" && esac.AuthSecretKey != ""
}

// CAIsConfigured returns true if the CA field is set.
func (esac *AssociationConf) CAIsConfigured() bool {
if esac == nil {
return false
}
return esac.CASecretName != ""
}

// URLIsConfigured returns true if the URL field is set.
func (esac *AssociationConf) URLIsConfigured() bool {
if esac == nil {
return false
}
return esac.URL != ""
}

func (esac *AssociationConf) GetAuthSecretName() string {
if esac == nil {
return ""
}
return esac.AuthSecretName
}

func (esac *AssociationConf) GetAuthSecretKey() string {
if esac == nil {
return ""
}
return esac.AuthSecretKey
}

func (esac *AssociationConf) GetCASecretName() string {
if esac == nil {
return ""
}
return esac.CASecretName
}

func (esac *AssociationConf) GetURL() string {
if esac == nil {
return ""
}
return esac.URL
}
77 changes: 77 additions & 0 deletions pkg/apis/common/v1alpha1/association_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package v1alpha1

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestAssociationConfIsConfigured(t *testing.T) {
tests := []struct {
name string
assocConf *AssociationConf
want bool
}{
{
name: "nil object",
want: false,
},
{
name: "missing URL",
assocConf: &AssociationConf{
AuthSecretName: "auth-secret",
AuthSecretKey: "elastic",
CASecretName: "ca-secret",
},
want: false,
},
{
name: "missing auth secret name",
assocConf: &AssociationConf{
AuthSecretKey: "elastic",
CASecretName: "ca-secret",
URL: "https://my-es.svc",
},
want: false,
},
{
name: "missing auth secret key",
assocConf: &AssociationConf{
AuthSecretName: "auth-secret",
CASecretName: "ca-secret",
URL: "https://my-es.svc",
},
want: false,
},
{
name: "missing CA secret name",
assocConf: &AssociationConf{
AuthSecretName: "auth-secret",
AuthSecretKey: "elastic",
URL: "https://my-es.svc",
},
want: false,
},
{
name: "correctly configured",
assocConf: &AssociationConf{
AuthSecretName: "auth-secret",
AuthSecretKey: "elastic",
CASecretName: "ca-secret",
URL: "https://my-es.svc",
},
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.assocConf.IsConfigured()
require.Equal(t, tt.want, got)
})
}
}
18 changes: 0 additions & 18 deletions pkg/apis/common/v1alpha1/authentication.go

This file was deleted.

Loading