Skip to content

Commit

Permalink
Merge pull request #2080 from barney-s/simple-gcp
Browse files Browse the repository at this point in the history
Adding a simple GCP example that creates a storage bucket
  • Loading branch information
google-oss-prow[bot] authored Jun 21, 2024
2 parents aa89ccf + 1fd795d commit 889f641
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
32 changes: 32 additions & 0 deletions experiments/compositions/samples/FirstGCPComposition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Storage Bucket with CORS and Retention

## Create the composition

```
kubectl create -f composition/cors-bucket.yaml
```

## Create a CRBucket instance

Create a new `Team` CR

```
kubectl apply -f - <<EOF
apiVersion: facade.compositions.google.com/v1
kind: CRBucket
metadata:
name: example-bucket
namespace: config-control
spec:
corsurl: "something.foobar.com"
retention: 10 # days
EOF
```

## Cleaning up

When done with testing, cleanup the resources by deleting the `CRBucket` CRs.

```
kubectl delete crbucket -n config-control example-bucket
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2024 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.

apiVersion: composition.google.com/v1alpha1
kind: Composition
metadata:
name: cors-bucket
spec:
inputAPIGroup: crbuckets.facade.compositions.google.com # Facade API
expanders:
- type: jinja2 # inbuilt jinja2 expander
name: bucket
template: |
apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
annotations:
cnrm.cloud.google.com/force-destroy: "false"
# StorageBucket names must be globally unique
name: {{ context.spec.project }}-{{ crbuckets.metadata.name }}
namespace: config-connector
spec:
lifecycleRule:
- action:
type: Delete
condition:
age: {{ crbuckets.spec.retention }}
withState: ANY
versioning:
enabled: true
uniformBucketLevelAccess: true
{% if crbuckets.spec.corsurl != '' %}
cors:
- origin: ["{{ crbuckets.spec.corsurl }}"]
responseHeader: ["Content-Type"]
method: ["GET", "HEAD", "DELETE"]
maxAgeSeconds: 3600
{% endif %}
---
apiVersion: composition.google.com/v1alpha1
kind: Facade
metadata:
name: crbucket
namespace: default
spec:
facadeKind: CRBucket
openAPIV3Schema:
# Schema for the `spec` field
type: object
required:
- retention
- corsurl
properties:
corsurl:
type: string
retention:
type: integer

0 comments on commit 889f641

Please sign in to comment.