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

Allow users to spec a serviceName in associations #4404

Merged
merged 3 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions config/crds/all-crds.yaml
Expand Up @@ -183,6 +183,12 @@ spec:
type: string
outputName:
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes
service which will be used to make requests to the referenced
object. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -351,6 +357,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -742,6 +754,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -1033,6 +1051,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand All @@ -1052,6 +1076,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -1956,6 +1986,12 @@ spec:
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. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -2522,6 +2558,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -3028,6 +3070,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down
3 changes: 3 additions & 0 deletions config/crds/bases/agent.k8s.elastic.co_agents.yaml
Expand Up @@ -7602,6 +7602,9 @@ spec:
type: string
outputName:
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes service which will be used to make requests to the referenced object. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
6 changes: 6 additions & 0 deletions config/crds/bases/apm.k8s.elastic.co_apmservers.yaml
Expand Up @@ -70,6 +70,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -243,6 +246,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
6 changes: 6 additions & 0 deletions config/crds/bases/beat.k8s.elastic.co_beats.yaml
Expand Up @@ -7603,6 +7603,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand All @@ -7618,6 +7621,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
Expand Up @@ -4220,6 +4220,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
Expand Up @@ -74,6 +74,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
3 changes: 3 additions & 0 deletions config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml
Expand Up @@ -70,6 +70,9 @@ spec:
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. If left empty the default HTTP service of the referenced resource will be used.
type: string
required:
- name
type: object
Expand Down
Expand Up @@ -189,6 +189,12 @@ spec:
type: string
outputName:
type: string
serviceName:
description: ServiceName is the name of an existing Kubernetes
service which will be used to make requests to the referenced
object. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -363,6 +369,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -754,6 +766,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -1051,6 +1069,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand All @@ -1070,6 +1094,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -1980,6 +2010,12 @@ spec:
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. If left empty the default HTTP service of the referenced
resource will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -2552,6 +2588,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -3064,6 +3106,12 @@ spec:
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.
If left empty the default HTTP service of the referenced resource
will be used.
type: string
required:
- name
type: object
Expand Down
1 change: 1 addition & 0 deletions docs/reference/api-docs.asciidoc
Expand Up @@ -447,6 +447,7 @@ ObjectSelector defines a reference to a Kubernetes object.
| Field | Description
| *`name`* __string__ | Name of the Kubernetes object.
| *`namespace`* __string__ | Namespace of the Kubernetes object. If empty, defaults to the current namespace.
| *`serviceName`* __string__ | ServiceName is the name of an existing Kubernetes service which will be used to make requests to the referenced object. If left empty the default HTTP service of the referenced resource will be used.
|===


Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/common/v1/common.go
Expand Up @@ -49,6 +49,9 @@ type ObjectSelector struct {
Name string `json:"name"`
// Namespace of the Kubernetes object. If empty, defaults to the current namespace.
Namespace string `json:"namespace,omitempty"`
// ServiceName is the name of an existing Kubernetes service which will be used to make requests to the referenced
// object. If left empty the default HTTP service of the referenced resource will be used.
ServiceName string `json:"serviceName,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it clear in the comment and generated doc that the service must exist in the referenced object namespace?

}

// WithDefaultNamespace adds a default namespace to a given ObjectSelector if none is set.
Expand All @@ -57,8 +60,9 @@ func (o ObjectSelector) WithDefaultNamespace(defaultNamespace string) ObjectSele
return o
}
return ObjectSelector{
Namespace: defaultNamespace,
Name: o.Name,
Namespace: defaultNamespace,
Name: o.Name,
ServiceName: o.ServiceName,
}
}

Expand Down
67 changes: 66 additions & 1 deletion pkg/apis/common/v1/common_test.go
Expand Up @@ -4,7 +4,10 @@

package v1

import "testing"
import (
"reflect"
"testing"
)

func TestTLSOptions_Enabled(t *testing.T) {
type fields struct {
Expand Down Expand Up @@ -132,3 +135,65 @@ func TestHTTPConfig_Scheme(t *testing.T) {
})
}
}

func TestObjectSelector_WithDefaultNamespace(t *testing.T) {
type fields struct {
Name string
Namespace string
ServiceName string
}
type args struct {
defaultNamespace string
}
tests := []struct {
name string
fields fields
args args
want ObjectSelector
}{
{
name: "keep non-empty namespace and name, serviceName",
fields: fields{
Name: "a",
Namespace: "b",
ServiceName: "c",
},
args: args{
defaultNamespace: "d",
},
want: ObjectSelector{
Name: "a",
Namespace: "b",
ServiceName: "c",
},
},
{
name: "default empty namespace, keep name and serviceName",
fields: fields{
Name: "a",
Namespace: "",
ServiceName: "c",
},
args: args{
defaultNamespace: "d",
},
want: ObjectSelector{
Name: "a",
Namespace: "d",
ServiceName: "c",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := ObjectSelector{
Name: tt.fields.Name,
Namespace: tt.fields.Namespace,
ServiceName: tt.fields.ServiceName,
}
if got := o.WithDefaultNamespace(tt.args.defaultNamespace); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithDefaultNamespace() = %+v, want %+v", got, tt.want)
}
})
}
}