-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: Move CRD and RBAC generation into bazel
* Add annotations to controllers as required * New controller_gen build rule for generating CRD and RBAC Signed-off-by: Naadir Jeewa <[email protected]>
- Loading branch information
1 parent
65be5b4
commit 5e2dbe5
Showing
13 changed files
with
273 additions
and
29 deletions.
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
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,76 @@ | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
# TODO: Move this to Kubebuilder repository | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
load("@io_kubernetes_build//defs:go.bzl", "go_genrule") | ||
|
||
CONTROLLER_GEN = "//vendor/sigs.k8s.io/controller-tools/cmd/controller-gen" | ||
|
||
def _qualified_genfile(label): | ||
return "$$GO_GENRULE_EXECROOT/$(location %s)" % label | ||
|
||
# controller_gen generates CRD and RBAC manifests for Kubernetes | ||
# controllers based on controller runtime | ||
# (https://github.com/kubernetes-sigs/controller-runtime) given | ||
# Kubebuilder annotations in the Go source code. | ||
# controller_gen will output manifests to config/crds and config/rbac | ||
# within the projects genfiles. | ||
def controller_gen(name, importpath, api, visibility, deps = []): | ||
outs = [ | ||
"rbac/rbac_role.yaml", | ||
"rbac/rbac_role_binding.yaml", | ||
] | ||
|
||
real_deps = [ | ||
"//pkg/apis:go_default_library", | ||
"//pkg/cloud/aws/actuators/cluster:go_default_library", | ||
"//pkg/cloud/aws/actuators/machine:go_default_library", | ||
] + deps | ||
|
||
for g in api: | ||
group = g["group"] | ||
version = g["version"].lower() | ||
types = g["types"] | ||
prefix = group.split(".")[0].lower() | ||
real_deps += [ "//pkg/apis/%s:go_default_library" % prefix] | ||
for t in types: | ||
basename = t.lower() | ||
out = "crds/%s_%s_%s.yaml" % (prefix, version, basename) | ||
outs += [out] | ||
|
||
cmd = """mkdir -p {source_package} && \\ | ||
cd {source_package} && \\ | ||
cp -f {project} {source_package} && \\ | ||
GENDIR=$$(dirname {gendir})/../.. && \\ | ||
{controller_gen} all && \\ | ||
cp -fR config $$GENDIR | ||
""".format( | ||
controller_gen = _qualified_genfile(CONTROLLER_GEN), | ||
project = _qualified_genfile("//:PROJECT"), | ||
gendir = _qualified_genfile(outs[0]), | ||
source_package = "$$GOPATH/src/%s" % importpath | ||
) | ||
|
||
go_genrule( | ||
name = name, | ||
outs = outs, | ||
srcs = ["//:PROJECT"], | ||
cmd = cmd, | ||
go_deps = real_deps, | ||
visibility = visibility, | ||
tools = [CONTROLLER_GEN], | ||
tags = [ "generated" ], | ||
) |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
load("//build:controller_gen.bzl", "controller_gen") | ||
|
||
controller_gen( | ||
name = "config", | ||
api = [ | ||
{ | ||
"group": "awsprovider.k8s.io", | ||
"version": "v1alpha1", | ||
"types": [ | ||
"AWSClusterProviderSpec", | ||
"AWSClusterProviderStatus", | ||
"AWSMachineProviderSpec", | ||
"AWSMachineProviderStatus", | ||
], | ||
}, | ||
], | ||
importpath = "sigs.k8s.io/cluster-api-provider-aws", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
genrule( | ||
name = "aws-provider-yaml", | ||
srcs = [ | ||
"//config/default:kustomization.yaml", | ||
"//config/default:rbac_role_binding_patch.yaml", | ||
"//config/manager:manager.yaml", | ||
"//cmd/clusterctl/examples/aws:out/aws_manager_image_patch.yaml", | ||
"//cmd/clusterctl/examples/aws:test-credentials", | ||
"config", | ||
"//:WORKSPACE", | ||
], | ||
outs = ["aws_provider.yaml"], | ||
cmd = """CONFIG_SRCDIR={root_dir}/config && \\ | ||
cp -R $$CONFIG_SRCDIR/default $(@D)/default && \\ | ||
cp -R $$CONFIG_SRCDIR/manager $(@D)/manager && \\ | ||
{kustomize} build $(@D)/default > $@ | ||
""".format( | ||
kustomize = "$(location @io_k8s_sigs_kustomize//:kustomize)", | ||
root_dir = "$$(dirname $(location //:WORKSPACE))", | ||
), | ||
tools = ["@io_k8s_sigs_kustomize//:kustomize"], | ||
visibility = ["//visibility:public"], | ||
) |
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,21 @@ | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
exports_files( | ||
[ | ||
"kustomization.yaml", | ||
"rbac_role_binding_patch.yaml", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# 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: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: manager-rolebinding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: default | ||
namespace: aws-provider-system |
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,20 @@ | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
exports_files( | ||
[ | ||
"manager.yaml", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ roleRef: | |
subjects: | ||
- kind: ServiceAccount | ||
name: default | ||
namespace: aws-provider-system | ||
namespace: system |
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