-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(iam): add iam bindings to crds #191
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36904fe
feat(iam): add iam bindings to crds
tpokki 1ebedb3
Merge branch 'main' of https://github.com/quipper/google-cloud-pubsub…
tpokki 74fe297
Merge branch 'main' into iam
tpokki ac00623
Merge branch 'main' into iam
tpokki b561042
Merge branch 'main' into iam
int128 530d560
Merge branch 'main' into iam
tpokki cd4c27c
Merge branch 'main' into iam
tpokki b7dac43
move reflection to own function
tpokki 29f4d8e
Merge branch 'main' into iam
tpokki dbf29cb
Merge branch 'main' into iam
tpokki 4deff68
Merge branch 'main' into iam
tpokki 897d38e
Merge branch 'main' into iam
tpokki 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2022. | ||
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 v1 | ||
|
||
// IamBinding provides authorative binding of permissions to for the resource. | ||
type IamBinding struct { | ||
// Role granted for the service accounts on topic / subscription level. | ||
//+kubebuilder:validation:Required | ||
//+kubebuilder:example="roles/pubsub.publisher" | ||
Role string `json:"role"` | ||
|
||
// Service accounts assigned with the role | ||
//+kubebuilder:validation:Required | ||
ServiceAccounts []string `json:"serviceAccounts"` | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"time" | ||
|
||
"cloud.google.com/go/iam" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
googlecloudpubsuboperatorv1 "github.com/quipper/google-cloud-pubsub-operator/api/v1" | ||
|
@@ -52,6 +53,61 @@ var _ = Describe("Subscription controller", func() { | |
}, 3*time.Second, 100*time.Millisecond).Should(Succeed()) | ||
}) | ||
|
||
It("Should create a Pub/Sub Subscription with IAM Binding", func(ctx context.Context) { | ||
const projectID = "subscription-project-1" | ||
const subscriptionID = "my-subscription-with-iam" | ||
psClient, err := pubsubtest.NewClient(ctx, projectID, psServer) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
By("Creating a Topic") | ||
topicID := "my-topic-2" | ||
_, err = psClient.CreateTopic(ctx, topicID) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
By("Creating a Subscription") | ||
subscription := &googlecloudpubsuboperatorv1.Subscription{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "googlecloudpubsuboperator.quipper.github.io/v1", | ||
Kind: "Subscription", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "example-", | ||
Namespace: "default", | ||
}, | ||
Spec: googlecloudpubsuboperatorv1.SubscriptionSpec{ | ||
SubscriptionProjectID: projectID, | ||
SubscriptionID: subscriptionID, | ||
TopicProjectID: projectID, | ||
TopicID: topicID, | ||
Bindings: []googlecloudpubsuboperatorv1.IamBinding{ | ||
{ | ||
Role: "roles/pubsub.consumer", | ||
ServiceAccounts: []string{ | ||
"[email protected]", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, subscription)).Should(Succeed()) | ||
|
||
By("Checking if the Subscription exists") | ||
Eventually(func(g Gomega) { | ||
sub := psClient.Subscription(subscriptionID) | ||
subscriptionExists, err := sub.Exists(ctx) | ||
g.Expect(err).ShouldNot(HaveOccurred()) | ||
g.Expect(subscriptionExists).Should(BeTrue()) | ||
|
||
policy, err := sub.IAM().Policy(ctx) | ||
g.Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
consumers := policy.Members(iam.RoleName("roles/pubsub.consumer")) | ||
g.Expect(consumers).Should(ContainElement("[email protected]")) | ||
g.Expect(consumers).Should(HaveLen(1)) | ||
|
||
}, 3*time.Second, 100*time.Millisecond).Should(Succeed()) | ||
}) | ||
|
||
It("Should update the status if error", func(ctx context.Context) { | ||
const projectID = "subscription-project-2" | ||
|
||
|
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
Oops, something went wrong.
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.
Thank you for the great work! I really understand why the reflection is needed and hope
pstest
package exports the internal*grpc.Server
.If the integration test is broken due to the change of
pstest
structure, it may be difficult to investigate the root cause. I'd like to suggest to extract this part to a separated function and write a unit test against the function. It ensures that the reflection works as we expect.For example,