UNPKG

integration-operator

Version:
192 lines (155 loc) 8.33 kB
import "core-js/modules/es.array.join.js"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import "regenerator-runtime/runtime.js"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } /** * Copyright 2021 Silicon Hills 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. */ import Operator, { ResourceEventType } from '@dot-i/k8s-operator'; import ora from 'ora'; import ResourceTracker from "./resourceTracker"; import { getGroupName, kind2plural } from "./util"; import { IntegrationPlug, IntegrationSocket } from "./controllers"; var logger = console; var IntegrationOperator = /*#__PURE__*/function (_Operator) { _inherits(IntegrationOperator, _Operator); var _super = _createSuper(IntegrationOperator); function IntegrationOperator(config) { var _this; _classCallCheck(this, IntegrationOperator); _this = _super.call(this, logger); _this.config = config; _this.spinner = ora(); _this.resourceTracker = new ResourceTracker(); return _this; } _createClass(IntegrationOperator, [{ key: "init", value: function () { var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: this.watchController(ResourceKind.IntegrationPlug, new IntegrationPlug(ResourceGroup.Integration, ResourceKind.IntegrationPlug)); this.watchController(ResourceKind.IntegrationSocket, new IntegrationSocket(ResourceGroup.Integration, ResourceKind.IntegrationSocket)); case 2: case "end": return _context.stop(); } } }, _callee, this); })); function init() { return _init.apply(this, arguments); } return init; }() }, { key: "watchController", value: function watchController(resourceKind, controller) { var _this2 = this; this.watchResource(getGroupName(ResourceGroup.Integration), ResourceVersion.V1alpha1, kind2plural(resourceKind), /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(e) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: // spawn as non blocking process _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var _this2$resourceTracke, oldResource, newResource, _err$body, _err$response, _err$response$body; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _this2$resourceTracke = _this2.resourceTracker.rotateResource(e.object), oldResource = _this2$resourceTracke.oldResource, newResource = _this2$resourceTracke.newResource; _context2.prev = 1; _context2.t0 = e.type; _context2.next = _context2.t0 === ResourceEventType.Added ? 5 : _context2.t0 === ResourceEventType.Deleted ? 10 : _context2.t0 === ResourceEventType.Modified ? 14 : 19; break; case 5: _context2.next = 7; return controller.added(newResource, e.meta, oldResource); case 7: _context2.next = 9; return controller.addedOrModified(newResource, e.meta, oldResource); case 9: return _context2.abrupt("return"); case 10: _this2.resourceTracker.resetResource(e.object); _context2.next = 13; return controller.deleted(newResource, e.meta, oldResource); case 13: return _context2.abrupt("return"); case 14: _context2.next = 16; return controller.modified(newResource, e.meta, oldResource); case 16: _context2.next = 18; return controller.addedOrModified(newResource, e.meta, oldResource); case 18: return _context2.abrupt("return"); case 19: _context2.next = 25; break; case 21: _context2.prev = 21; _context2.t1 = _context2["catch"](1); _this2.spinner.fail([_context2.t1.message || '', ((_err$body = _context2.t1.body) === null || _err$body === void 0 ? void 0 : _err$body.message) || ((_err$response = _context2.t1.response) === null || _err$response === void 0 ? void 0 : (_err$response$body = _err$response.body) === null || _err$response$body === void 0 ? void 0 : _err$response$body.message) || ''].join(': ')); if (_this2.config.debug) logger.error(_context2.t1); case 25: case "end": return _context2.stop(); } } }, _callee2, null, [[1, 21]]); }))().catch(logger.error); case 1: case "end": return _context3.stop(); } } }, _callee3); })); return function (_x) { return _ref.apply(this, arguments); }; }()).catch(logger.error); } }]); return IntegrationOperator; }(Operator); export { IntegrationOperator as default }; export var ResourceGroup; (function (ResourceGroup) { ResourceGroup["Integration"] = "integration"; })(ResourceGroup || (ResourceGroup = {})); export var ResourceKind; (function (ResourceKind) { ResourceKind["IntegrationPlug"] = "IntegrationPlug"; ResourceKind["IntegrationSocket"] = "IntegrationSocket"; })(ResourceKind || (ResourceKind = {})); export var ResourceVersion; (function (ResourceVersion) { ResourceVersion["V1alpha1"] = "v1alpha1"; })(ResourceVersion || (ResourceVersion = {})); //# sourceMappingURL=integrationOperator.js.map