Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Splitting init scripts #529

Merged
merged 37 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8b1fc6b
adding github template for bugs and features
Nov 26, 2019
d0b1721
renaming
Nov 26, 2019
906e185
Merge remote-tracking branch 'upstream/master'
nachocano Nov 27, 2019
671f7d4
Merge remote-tracking branch 'upstream/master'
nachocano Nov 28, 2019
335ff3f
Merge remote-tracking branch 'upstream/master'
Dec 4, 2019
599f281
Merge remote-tracking branch 'upstream/master'
Dec 6, 2019
5b2c1d9
Merge remote-tracking branch 'upstream/master'
Dec 9, 2019
3e60124
Merge remote-tracking branch 'upstream/master'
Dec 9, 2019
e9678ba
adding comment
Dec 14, 2019
943916d
Merge remote-tracking branch 'upstream/master'
Dec 16, 2019
06194cc
Merge remote-tracking branch 'upstream/master'
Dec 18, 2019
3b95c4c
Merge remote-tracking branch 'upstream/master'
Dec 20, 2019
e7d1793
Merge remote-tracking branch 'upstream/master'
Jan 13, 2020
8b8f3fe
Merge branch 'master' of github.com:nachocano/knative-gcp
nachocano Jan 13, 2020
27b558a
Merge remote-tracking branch 'upstream/master'
Jan 14, 2020
1dcaa69
Merge remote-tracking branch 'upstream/master'
Jan 14, 2020
ed4be63
Merge remote-tracking branch 'upstream/master'
Jan 17, 2020
ed892c4
Merge branch 'master' of github.com:nachocano/knative-gcp
nachocano Jan 17, 2020
b5ee575
nits
nachocano Jan 17, 2020
91e64fe
nits
nachocano Jan 17, 2020
bd3b21e
Merge remote-tracking branch 'upstream/master'
Jan 17, 2020
4312cfd
Merge remote-tracking branch 'upstream/master'
Jan 17, 2020
948f834
Merge remote-tracking branch 'upstream/master'
Jan 21, 2020
20cc453
updating to master
Jan 21, 2020
88cc65f
missing files
Jan 21, 2020
631e269
Merge remote-tracking branch 'upstream/master'
nachocano Jan 22, 2020
f8efe36
Merge remote-tracking branch 'upstream/master'
Jan 22, 2020
e296ee0
Merge remote-tracking branch 'upstream/master'
Jan 23, 2020
07a46b4
Merge remote-tracking branch 'upstream/master'
Jan 23, 2020
d02e685
using revision instead of master
Jan 23, 2020
e124481
Merge remote-tracking branch 'upstream/master'
Jan 24, 2020
a0be819
Merge remote-tracking branch 'upstream/master'
Jan 24, 2020
5bc0eff
Merge remote-tracking branch 'upstream/master'
Jan 27, 2020
e1c8edc
Merge remote-tracking branch 'upstream/master'
nachocano Jan 29, 2020
3524ef4
Merge remote-tracking branch 'upstream/master'
nachocano Jan 31, 2020
b892d63
splitting control and data plane scripts
nachocano Jan 31, 2020
6ec64f4
enabling the APIs when initializing the control plane
nachocano Jan 31, 2020
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
2 changes: 1 addition & 1 deletion docs/examples/cloudstoragesource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Notifications for when a new object is added to Google Cloud Storage (GCS).
1. Use `curl` to fetch the email:

```shell
export GCS_SERVICE_ACCOUNT=`curl -s -X GET -H "Authorization: Bearer \`GOOGLE_APPLICATION_CREDENTIALS=./cloudrunevents-pullsub.json gcloud auth application-default print-access-token\`" "https://www.googleapis.com/storage/v1/projects/$PROJECT_ID/serviceAccount" | grep email_address | cut -d '"' -f 4`
export GCS_SERVICE_ACCOUNT=`curl -s -X GET -H "Authorization: Bearer \`GOOGLE_APPLICATION_CREDENTIALS=./cre-pubsub.json gcloud auth application-default print-access-token\`" "https://www.googleapis.com/storage/v1/projects/$PROJECT_ID/serviceAccount" | grep email_address | cut -d '"' -f 4`
```

1. Then grant rights to that Service Account to publish to GCP Pub/Sub.
Expand Down
79 changes: 0 additions & 79 deletions hack/init.sh

This file was deleted.

53 changes: 53 additions & 0 deletions hack/init_control_plane.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Copyright 2020 Google LLC
#
# 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.

# Usage: ./init_control_plane.sh
# The current project set in gcloud MUST be the same as where the cluster is running.

NAMESPACE=cloud-run-events
SERVICE_ACCOUNT=cloud-run-events
PROJECT_ID=$(gcloud config get-value project)
KEY_TEMP=google-cloud-key.json

# Enable APIs.
gcloud services enable pubsub.googleapis.com
gcloud services enable storage-component.googleapis.com
gcloud services enable storage-api.googleapis.com
gcloud services enable cloudscheduler.googleapis.com
gcloud services enable logging.googleapis.com
gcloud services enable stackdriver.googleapis.com

# Create the service account for the control plane
gcloud iam service-accounts create ${SERVICE_ACCOUNT}

# Grant permissions to the service account for the control plane to manage native GCP resources.
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/pubsub.admin
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/storage.admin
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/cloudscheduler.admin
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/logging.configWriter
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/logging.privateLogViewer

# Download a JSON key for the service account.
gcloud iam service-accounts keys create ${KEY_TEMP} --iam-account=${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com

# Create/Patch the secret with the download JSON key in the control plane namespace
kubectl -n ${NAMESPACE} create secret generic google-cloud-key --from-file=key.json=${KEY_TEMP} --dry-run -o yaml | kubectl apply --filename -

# Delete the controller pod in the control plane namespace to refresh the created/patched secret
kubectl delete pod -n ${NAMESPACE} --selector role=controller

# Remove the tmp file.
rm ${KEY_TEMP}
50 changes: 50 additions & 0 deletions hack/init_data_plane.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# Copyright 2020 Google LLC
#
# 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.

# Usage: ./init_data_plane.sh [NAMESPACE]
# where [NAMESPACE] is an optional parameter to specify the namespace to use. If it's not specified, we use the default one.
# if the namespace does not exist, the script will create it.
# The current project set in gcloud MUST be the same as where the cluster is running.
# The script always uses the same service account called cre-pubsub.

SERVICE_ACCOUNT=cre-pubsub
KEY_TEMP=google-cloud-key.json
NAMESPACE=default
if [[ -z "$1" ]]; then
echo "NAMESPACE not provided, using default"
else
NAMESPACE="$1"
echo "NAMESPACE provided, using ${NAMESPACE}"
kubectl create namespace $NAMESPACE
fi

# Create the service account for the data plane
gcloud iam service-accounts create ${SERVICE_ACCOUNT}

# Grant pubsub.editor role to the service account for the data plane to read and/or write to Pub/Sub.
gcloud projects add-iam-policy-binding $PROJECT_ID --member=serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/pubsub.editor

# Download a JSON key for the service account.
gcloud iam service-accounts keys create ${KEY_TEMP} --iam-account=${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com

# Create the secret with the download JSON key.
kubectl --namespace $NAMESPACE create secret generic google-cloud-key --from-file=key.json=${KEY_TEMP}

# Label the namespace to inject a Broker.
kubectl label namespace $NAMESPACE knative-eventing-injection=enabled

# Remove the tmp file.
rm ${KEY_TEMP}