-
Notifications
You must be signed in to change notification settings - Fork 440
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 creation of ServiceAccount to the Target Allocator #836
Merged
pavolloffay
merged 6 commits into
open-telemetry:main
from
jaronoff97:target-allocator-service-account
Jun 3, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c44c8d9
Added the creation or linking of an existing service account to the t…
jaronoff97 aa48a29
Fix test
jaronoff97 195652a
Updated from feedback
jaronoff97 ebbaa41
Fixed test package
jaronoff97 04ad74c
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
jaronoff97 464c9fb
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
jaronoff97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package targetallocator | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
"github.com/open-telemetry/opentelemetry-operator/pkg/naming" | ||
) | ||
|
||
// ServiceAccountName returns the name of the existing or self-provisioned service account to use for the given instance. | ||
func ServiceAccountName(instance v1alpha1.OpenTelemetryCollector) string { | ||
if len(instance.Spec.TargetAllocator.ServiceAccount) == 0 { | ||
return naming.ServiceAccount(instance) | ||
} | ||
|
||
return instance.Spec.TargetAllocator.ServiceAccount | ||
} | ||
|
||
//ServiceAccount returns the service account for the given instance. | ||
func ServiceAccount(otelcol v1alpha1.OpenTelemetryCollector) corev1.ServiceAccount { | ||
labels := Labels(otelcol) | ||
labels["app.kubernetes.io/name"] = naming.TargetAllocatorServiceAccount(otelcol) | ||
|
||
return corev1.ServiceAccount{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: naming.TargetAllocatorServiceAccount(otelcol), | ||
Namespace: otelcol.Namespace, | ||
Labels: labels, | ||
Annotations: otelcol.Annotations, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package targetallocator | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
) | ||
|
||
func TestServiceAccountNewDefault(t *testing.T) { | ||
// prepare | ||
otelcol := v1alpha1.OpenTelemetryCollector{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-instance", | ||
}, | ||
} | ||
|
||
// test | ||
sa := ServiceAccountName(otelcol) | ||
|
||
// verify | ||
assert.Equal(t, "my-instance-collector", sa) | ||
} | ||
|
||
func TestServiceAccountOverride(t *testing.T) { | ||
// prepare | ||
otelcol := v1alpha1.OpenTelemetryCollector{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-instance", | ||
}, | ||
Spec: v1alpha1.OpenTelemetryCollectorSpec{ | ||
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{ | ||
ServiceAccount: "my-special-sa", | ||
}, | ||
}, | ||
} | ||
|
||
// test | ||
sa := ServiceAccountName(otelcol) | ||
|
||
// verify | ||
assert.Equal(t, "my-special-sa", sa) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches what is done for the collector