Skip to content
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
7 changes: 7 additions & 0 deletions infra/gcp/ensure-staging-storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ function ensure_staging_gcs_bucket() {

color 6 "Ensuring ${writers} can write to ${bucket} in project: ${project}"
empower_group_to_write_gcs_bucket "${writers}" "${bucket}"

# Ensure logging is turned on
ensure_gcs_bucket_logging "${bucket}"
}

# Ensure a GCR repo is provisioned in the given staging project, with
Expand All @@ -205,6 +208,7 @@ function ensure_staging_gcr_repo() {
fi
local project="${1}"
local writers="${2}"
local gcr_bucket="gs://artifacts.${1}.appspot.com"

color 6 "Ensuring a GCR repo exists for project: ${project}"
ensure_gcr_repo "${project}"
Expand All @@ -214,6 +218,9 @@ function ensure_staging_gcr_repo() {

color 6 "Ensuring GCR admins can admin GCR for project: ${project}"
empower_gcr_admins "${project}"

color 6 "Ensuring logging on ${gcr_bucket} for GCR project: ${project}"
ensure_gcs_bucket_logging "${gcr_bucket}"
}

# Ensure GCB is setup for the given staging project, by ensuring the
Expand Down
3 changes: 3 additions & 0 deletions infra/gcp/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ trap 'cleanup_tmpdir' EXIT
# Useful organization-wide constants
#

# Set up logs bucket
export K8S_INFRA_GCSLOGS_BUCKET="gs://k8s-infra-artifacts-gcslogs"

# The GCP org stuff needed to turn it all on.
readonly GCP_ORG="758905017065" # kubernetes.io
readonly GCP_BILLING="018801-93540E-22A20E"
Expand Down
22 changes: 22 additions & 0 deletions infra/gcp/lib_gcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ function ensure_public_gcs_bucket() {
ensure_gcs_role_binding "${bucket}" "allUsers" "objectViewer"
}

# Set up logging
# $1: The GCS bucket (e.g. gs://k8s-infra-foo)
function ensure_gcs_bucket_logging() {
if [ $# != 1 ] || [ -z "$1" ]; then
echo "ensure_gcs_bucket_logging(bucket) requires 1 argument" >&2
return 1
fi
local bucket="$1"

local intent="${TMPDIR}/gcs-bucket-logging.intent.yaml"
local before="${TMPDIR}/gcs-bucket-logging.before.yaml"
local after="${TMPDIR}/gcs-bucket-logging.after.yaml"

echo "{\"logBucket\": \"${K8S_INFRA_GCSLOGS_BUCKET}\", \"logObjectPrefix\": \"$bucket\"}" > "${intent}"
gsutil logging get "${bucket}"> "${before}"
if ! diff "${intent}" "${before}"; then
gsutil logging set on -b "${K8S_INFRA_GCSLOGS_BUCKET}" -o "${bucket#gs://}" "${bucket}"
gsutil logging get on -b "${K8S_INFRA_GCSLOGS_BUCKET}" -o "${bucket#gs://}" "${bucket}" > "${after}"
diff_colorized "${before}" "${after}"
fi
}

# Ensure the bucket exists and is NOT world-accessible
# $1: The GCP project
# $2: The bucket (e.g. gs://bucket-name)
Expand Down