fgerlits commented on a change in pull request #1257: URL: https://github.com/apache/nifi-minifi-cpp/pull/1257#discussion_r802888145
########## File path: extensions/kubernetes/controllerservice/KubernetesControllerService.cpp ########## @@ -0,0 +1,205 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include "KubernetesControllerService.h" + +#include <vector> + +extern "C" { +#include "config/incluster_config.h" +#include "config/kube_config.h" +#include "include/apiClient.h" +#include "api/CoreV1API.h" +} + +#include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" +#include "Exception.h" + +namespace org::apache::nifi::minifi::controllers { + +class KubernetesControllerService::APIClient { + public: + explicit APIClient(core::logging::Logger& logger); + ~APIClient(); + apiClient_t* getClient() { return api_client_; } + + private: + char* base_path_ = nullptr; + sslConfig_t* ssl_config_ = nullptr; + list_t* api_keys_ = nullptr; + apiClient_t* api_client_ = nullptr; +}; + +KubernetesControllerService::APIClient::APIClient(core::logging::Logger& logger) { + int rc = load_incluster_config(&base_path_, &ssl_config_, &api_keys_); + if (rc != 0) { + logger.log_error("Cannot load kubernetes configuration in cluster"); + return; + } + api_client_ = apiClient_create_with_base_path(base_path_, ssl_config_, api_keys_); + if (!api_client_) { + logger.log_error("Cannot create a kubernetes client"); + } +} + +KubernetesControllerService::APIClient::~APIClient() { + if (api_client_) { + apiClient_free(api_client_); + api_client_ = nullptr; + } + + free_client_config(base_path_, ssl_config_, api_keys_); + base_path_ = nullptr; + ssl_config_ = nullptr; + api_keys_ = nullptr; + + apiClient_unsetupGlobalEnv(); +} + +core::Property KubernetesControllerService::NamespaceFilter{ + core::PropertyBuilder::createProperty("Namespace Filter") + ->withDescription("Limit the output to pods in namespaces which match this regular expression") + ->withDefaultValue<std::string>("default") + ->build()}; +core::Property KubernetesControllerService::PodNameFilter{ + core::PropertyBuilder::createProperty("Pod Name Filter") + ->withDescription("If present, limit the output to pods the name of which matches this regular expression") + ->build()}; +core::Property KubernetesControllerService::ContainerNameFilter{ + core::PropertyBuilder::createProperty("Container Name Filter") + ->withDescription("If present, limit the output to containers the name of which matches this regular expression") + ->build()}; + +KubernetesControllerService::KubernetesControllerService(const std::string& name, const utils::Identifier& uuid) + : AttributeProviderService(name, uuid), + logger_{core::logging::LoggerFactory<KubernetesControllerService>::getLogger()}, + api_client_{std::make_unique<APIClient>(*logger_)} { +} + +KubernetesControllerService::KubernetesControllerService(const std::string& name, const std::shared_ptr<Configure>& configuration) + : KubernetesControllerService{name} { + setConfiguration(configuration); + initialize(); +} + +void KubernetesControllerService::initialize() { + if (initialized_) { return; } + + std::lock_guard<std::mutex> lock(initialization_mutex_); + ControllerService::initialize(); + setSupportedProperties({NamespaceFilter, PodNameFilter, ContainerNameFilter}); + initialized_ = true; Review comment: True; I copied this from some other controller service without thinking about it. I have made the change you suggested in https://github.com/apache/nifi-minifi-cpp/pull/1257/commits/6a78423ecffedfbc6747fe0b6a80122245c3c6c1. I have also opened a Jira to fix this in other controller services: https://issues.apache.org/jira/browse/MINIFICPP-1753 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
