Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 97d7f56

Browse files
BrianPitrodgeocsigmorgante
authored
feat: Add Config Connector Solutions + project-hierarchy (GoogleCloudPlatform#598)
* copied samples from kcc * ran kpt pkg init . * Remove helper script from commit * deleted create-setters from repo * added untracked files * made kpt directory seperate * added setter for org-id * created more setters, fixed descriptions * rearraged directories for better kpt packaging * added more setters * rearranged directories again * added script for two-step process, added placeholders and setter * Config Connector README Update * Replace script with README steps * Redirect README links * Change Kptfile descriptions, project setter * Add Google licenses * Consistent wording for main README * README Nitfixes * Fix License Links * Config Connector YAML configurations It makes sense for Config Connector YAML files to be called 'configurations', right? * Fix misnamed setter * README - morgante feedback * Fully qualify kpt package link * match project-name setter to project-id * Match folder-name to folder-id * Remove redundant project-hierarchy setters Co-authored-by: Thomas Rodgers <thomasrodgers@google.com> Co-authored-by: Adam Ocsvari <ocsi@google.com> Co-authored-by: Morgante Pell <morgantep@google.com>
1 parent 101f8c1 commit 97d7f56

File tree

7 files changed

+234
-0
lines changed

7 files changed

+234
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The Cloud Foundation toolkit (henceforth, CFT) includes the following parts:
1212
single or multiple CFT-compliant config files - see:
1313
- The CFT source Python files (the `src/` directory)
1414
- The [CFT DM User Guide](dm/docs/userguide.md)
15+
- A growing set of sample [Config
16+
Connector](https://cloud.google.com/config-connector/docs/overview)
17+
YAML configurations - see [the solutions directory](config-connector/solutions/)
1518

1619
In addition, the CFT repository includes a sample pipeline that enables running
1720
CFT deployment operations from Jenkins - see the

config-connector/solutions/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Config Connector Solutions
2+
3+
## Overview
4+
5+
Config Connector Solutions provides best practice solutions
6+
to common cloud applications, formatted as YAML definitions
7+
for Config Connector CRDs. These YAMLs can be applied to
8+
clusters running [Config
9+
Connector](https://cloud.google.com/config-connector/docs/how-to/getting-started).
10+
11+
## Structure
12+
13+
Folders under this directory denote general solution areas.
14+
In each solution area folder, there are folders for each package
15+
& customization tool (currently only kpt), under which are nested all available solutions in
16+
that solution area and package format.
17+
18+
## Usage
19+
20+
### kpt
21+
22+
Samples are consumable as [kpt
23+
packages](https://googlecontainertools.github.io/kpt/).
24+
Common targets for modification are provided kpt setters,
25+
and can be listed with `kpt cfg list-setters`.
26+
27+
## License
28+
29+
Apache 2.0 - See [LICENSE](/LICENSE) for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Kpt Project Solutions
2+
3+
## Installing kpt
4+
5+
Follow the instructions on [the kpt
6+
GitHub](https://github.com/GoogleContainerTools/kpt).
7+
8+
## Listing setters
9+
10+
See which values are available for kpt to change
11+
`kpt cfg list-setters`
12+
13+
## Setting setters
14+
15+
`kpt cfg set DIR NAME VALUE --set-by NAME`
16+
17+
## SEE ALSO
18+
19+
Comprehensive documentation at
20+
[https://googlecontainertools.github.io/kpt/](https://googlecontainertools.github.io/kpt/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: kpt.dev/v1alpha1
2+
kind: Kptfile
3+
metadata:
4+
name: project-hierarchy
5+
packageMetadata:
6+
shortDescription: Deploy a project under a folder within an organization
7+
openAPI:
8+
definitions:
9+
io.k8s.cli.setters.org-id:
10+
description: organization ID for associated services
11+
x-k8s-cli:
12+
setter:
13+
name: org-id
14+
value: "${ORG_ID}"
15+
setBy: PLACEHOLDER
16+
io.k8s.cli.setters.project-id:
17+
description: ID of project
18+
x-k8s-cli:
19+
setter:
20+
name: project-id
21+
value: project-hierarchy-project
22+
setBy: package-default
23+
io.k8s.cli.setters.folder-name:
24+
description: name of folder
25+
x-k8s-cli:
26+
setter:
27+
name: folder-name
28+
value: project-hierarchy-folder
29+
setBy: package-default
30+
io.k8s.cli.setters.billing-account:
31+
description: ID of billing account
32+
x-k8s-cli:
33+
setter:
34+
name: billing-account
35+
value: ${BILLING_ACCOUNT_ID?}
36+
setBy: PLACEHOLDER
37+
io.k8s.cli.setters.folder-number:
38+
description: numeric GCP ID of folder
39+
x-k8s-cli:
40+
setter:
41+
name: folder-number
42+
value: "${FOLDER_NUMBER?}"
43+
setBy: PLACEHOLDER
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Project Hierarchy
2+
==================================================
3+
4+
# NAME
5+
6+
project-hierarchy
7+
8+
# SYNOPSIS
9+
10+
Config Connector compatible YAML files to create
11+
a folder in an organization, and a project
12+
beneath it.
13+
14+
# CONSUMPTION
15+
16+
Using [kpt](https://googlecontainertools.github.io/kpt/):
17+
18+
Run `kpt pkg get https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit.git/config-connector/solutions/projects/kpt/project-hierarchy project-hierarchy`.
19+
20+
# REQUIREMENTS
21+
22+
A working Config Connector cluster using a
23+
service account with the following roles in
24+
the organization:
25+
- roles/resourcemanager.folderCreator
26+
- roles/resourcemanager.projectCreator
27+
28+
# USAGE
29+
30+
Replace the
31+
`${BILLING_ACCOUNT_ID?}` and `${ORG_ID?}` values:
32+
33+
From within this directory, run
34+
```
35+
kpt cfg set . billing-account VALUE
36+
```
37+
and
38+
```
39+
kpt cfg set . org-id VALUE
40+
```
41+
replacing `VALUE` with your billing account
42+
and organization ID respectively.
43+
44+
You will also need to reset the project ID,
45+
since a project with the given ID already exists.
46+
```
47+
kpt cfg set . project-id VALUE
48+
```
49+
50+
51+
Currently, to create a project under a
52+
folder, you must supply a numeric folder ID,
53+
which is only available after the folder is
54+
created. An issue outlining this shortfall in
55+
Config Connector functionality is filed on the
56+
project's GitHub,
57+
https://github.com/GoogleCloudPlatform/k8s-config-connector/issues/104.
58+
59+
60+
To be nested beneath it, the project still needs
61+
a folder number. This can only be found after
62+
creating the folder. You can do so with
63+
```
64+
kubectl apply -f folder.yaml
65+
```
66+
67+
Wait for GCP to generate the folder.
68+
```
69+
kubectl wait --for=condition=Ready -f folder.yaml
70+
```
71+
72+
Now extract the folder number.
73+
```
74+
FOLDER_NUMBER=$(kubectl describe -f folder.yaml | grep Name:\ *folders\/ | sed "s/.*folders\///")
75+
```
76+
You can set the folder number using the
77+
following command:
78+
```
79+
kpt cfg set . folder-number $FOLDER_NUMBER --set-by "README-instructions"
80+
```
81+
82+
83+
Now you can fully apply this solution.
84+
```
85+
kubectl apply -f .
86+
```
87+
88+
# LICENSE
89+
90+
Apache 2.0 - See [LICENSE](/LICENSE) for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
16+
kind: Folder
17+
metadata:
18+
annotations:
19+
# Replace "${ORG_ID?}" with the numeric ID for your organization
20+
cnrm.cloud.google.com/organization-id: "${ORG_ID}" # {"$ref":"#/definitions/io.k8s.cli.setters.org-id"}
21+
name: project-hierarchy-folder # {"$ref":"#/definitions/io.k8s.cli.setters.folder-name"}
22+
spec:
23+
displayName: project-hierarchy-folder # {"$ref":"#/definitions/io.k8s.cli.setters.folder-name"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
16+
kind: Project
17+
metadata:
18+
annotations:
19+
# Set this field after finding the folder number.
20+
cnrm.cloud.google.com/folder-id: "${FOLDER_NUMBER?}" # {"$ref":"#/definitions/io.k8s.cli.setters.folder-number"}
21+
name: project-hierarchy-project # {"$ref":"#/definitions/io.k8s.cli.setters.project-id"}
22+
spec:
23+
name: project-hierarchy-project # {"$ref":"#/definitions/io.k8s.cli.setters.project-id"}
24+
billingAccountRef:
25+
# Replace "${BILLING_ACCOUNT_ID?}" with the numeric ID for your billing account
26+
external: "${BILLING_ACCOUNT_ID?}" # {"$ref":"#/definitions/io.k8s.cli.setters.billing-account"}

0 commit comments

Comments
 (0)