"use strict";
/*
 * Copyright © 2020 Atomist, Inc.
 *
 * 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.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.k8sSupport = void 0;
const extensionPack_1 = require("../../api-helper/misc/extensionPack");
const kubernetesUndeploy_1 = require("./commands/kubernetesUndeploy");
const config_1 = require("./config");
const kubernetesDeploy_1 = require("./events/kubernetesDeploy");
const goals_1 = require("./sync/goals");
const startup_1 = require("./sync/startup");
const sync_1 = require("./sync/sync");
/**
 * Register Kubernetes deployment support for provided goals.  Any
 * provided `options` are merged with any found in the SDM
 * configuration at `sdm.k8s.options`, i.e.,
 * `sdm.configuration.sdm.k8s.options` if accessing from the SDM
 * object, with those passed in taking precedence.
 *
 * If the merged options result in a truthy `addCommands`, then the
 * [[kubernetesUndeploy]] and [[kubernetesSync]] commands are added to
 * the SDM with intents.
 *
 * The [[kubernetesDeployHandler]] event handler for this SDM is added
 * to the SDM.
 *
 * If `sync.repo` is a valid repo ref, synchronizing Kubernetes
 * resources with a Git repository is enabled.
 *
 * The [[minikubeStartupListener]] is added to the SDM to assist
 * running in local mode against a
 * [minikube](https://kubernetes.io/docs/setup/minikube/) cluster.
 *
 * @param options SDM Pack K8s options, see [[SdmPackK8sOptions]].
 * @returns SDM extension pack.
 */
function k8sSupport(options = {}) {
    return Object.assign(Object.assign({}, extensionPack_1.metadata()), { configure: sdm => {
            config_1.mergeK8sOptions(sdm, options);
            sdm.addCommand(kubernetesUndeploy_1.kubernetesUndeploy(sdm));
            sdm.addCommand(sync_1.kubernetesSync(sdm));
            sdm.addEvent(kubernetesDeploy_1.kubernetesDeployHandler(sdm.configuration.name));
            sdm.addStartupListener(startup_1.syncRepoStartupListener);
            goals_1.syncGoals(sdm);
        } });
}
exports.k8sSupport = k8sSupport;
//# sourceMappingURL=k8s.js.map