# 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": "azureprovider.k8s.io",
            "version": "v1alpha1",
            "types": [
                "AzureClusterProviderSpec",
                "AzureClusterProviderStatus",
                "AzureMachineProviderSpec",
                "AzureMachineProviderStatus",
            ],
        },
    ],
    importpath = "sigs.k8s.io/cluster-api-provider-azure",
    visibility = ["//visibility:public"],
)

genrule(
    name = "azure-provider-yaml",
    srcs = [
        "//config/default:kustomization.yaml",
        "//config/default:rbac_role_binding_patch.yaml",
        "//config/manager:manager.yaml",
        "//cmd/clusterctl/examples/azure:out/azure_manager_image_patch.yaml",
        "//cmd/clusterctl/examples/azure:test-credentials",
        "config",
        "//:WORKSPACE",
    ],
    outs = ["azure_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"],
)
