iSulad/src/services/cri/cri_helpers.h

116 lines
5.0 KiB
C
Raw Normal View History

2019-09-30 10:53:41 -04:00
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* Author: tanyifeng
* Create: 2017-11-22
* Description: provide cri helpers functions
*********************************************************************************/
#ifndef _CRI_HELPERS_H_
#define _CRI_HELPERS_H_
#include <string>
#include <memory>
#include <vector>
#include <map>
#include "api.pb.h"
#include "errors.h"
#include "container_def.h"
#include "host_config.h"
#include "callback.h"
2019-12-25 15:50:34 +08:00
#include "docker_seccomp.h"
2019-09-30 10:53:41 -04:00
#include "cri_pod_network.h"
#include "checkpoint_handler.h"
2019-12-25 15:50:34 +08:00
#include "image.h"
2019-09-30 10:53:41 -04:00
namespace CRIHelpers {
class Constants {
public:
static const std::string DEFAULT_RUNTIME_NAME;
static const std::string POD_NETWORK_ANNOTATION_KEY;
static const std::string CONTAINER_TYPE_LABEL_KEY;
static const std::string CONTAINER_TYPE_LABEL_SANDBOX;
static const std::string CONTAINER_TYPE_LABEL_CONTAINER;
static const std::string CONTAINER_LOGPATH_LABEL_KEY;
static const std::string CONTAINER_HUGETLB_ANNOTATION_KEY;
static const std::string SANDBOX_ID_LABEL_KEY;
static const std::string KUBERNETES_CONTAINER_NAME_LABEL;
// DOCKER_IMAGEID_PREFIX is the prefix of image id in container status.
static const std::string DOCKER_IMAGEID_PREFIX;
// DOCKER_PULLABLE_IMAGEID_PREFIX is the prefix of pullable image id in container status.
static const std::string DOCKER_PULLABLE_IMAGEID_PREFIX;
static const std::string RUNTIME_READY;
static const std::string NETWORK_READY;
static const std::string POD_CHECKPOINT_KEY;
static const size_t MAX_CHECKPOINT_KEY_LEN { 250 };
};
std::string GetDefaultSandboxImage(Errors &err);
json_map_string_string *MakeLabels(const google::protobuf::Map<std::string, std::string> &mapLabels, Errors &error);
json_map_string_string *MakeAnnotations(const google::protobuf::Map<std::string, std::string> &mapAnnotations,
Errors &error);
void ExtractLabels(json_map_string_string *input, google::protobuf::Map<std::string, std::string> &labels);
void ExtractAnnotations(json_map_string_string *input, google::protobuf::Map<std::string, std::string> &annotations);
int FiltersAdd(defs_filters *filters, const std::string &key, const std::string &value);
int FiltersAddLabel(defs_filters *filters, const std::string &key, const std::string &value);
void ProtobufAnnoMapToStd(const google::protobuf::Map<std::string, std::string> &annotations,
std::map<std::string, std::string> &newAnnos);
2019-12-25 15:50:34 +08:00
runtime::v1alpha2::ContainerState ContainerStatusToRuntime(Container_Status status);
2019-09-30 10:53:41 -04:00
char **StringVectorToCharArray(std::vector<std::string> &path);
imagetool_image *InspectImageByID(const std::string &imageID, Errors &err);
std::string ToPullableImageID(const std::string &id, imagetool_image *image);
bool IsContainerNotFoundError(const std::string &err);
bool IsImageNotFoundError(const std::string &err);
std::string sha256(const char *val);
cri_pod_network_element **GetNetworkPlaneFromPodAnno(const google::protobuf::Map<std::string, std::string> &annotations,
size_t *len, Errors &error);
2019-12-25 15:50:34 +08:00
std::unique_ptr<runtime::v1alpha2::PodSandbox> CheckpointToSandbox(const std::string &id,
const cri::PodSandboxCheckpoint &checkpoint);
2019-09-30 10:53:41 -04:00
std::string StringsJoin(const std::vector<std::string> &vec, const std::string &sep);
2019-12-25 15:50:34 +08:00
void UpdateCreateConfig(container_custom_config *createConfig, host_config *hc,
const runtime::v1alpha2::ContainerConfig &config, const std::string &podSandboxID,
Errors &error);
2019-09-30 10:53:41 -04:00
2019-12-25 15:50:34 +08:00
void GenerateMountBindings(const google::protobuf::RepeatedPtrField<runtime::v1alpha2::Mount> &mounts,
host_config *hostconfig, Errors &err);
2019-09-30 10:53:41 -04:00
2019-12-25 15:50:34 +08:00
std::vector<std::string>
GenerateEnvList(const ::google::protobuf::RepeatedPtrField<::runtime::v1alpha2::KeyValue> &envs);
2019-09-30 10:53:41 -04:00
bool ValidateCheckpointKey(const std::string &key, Errors &error);
2019-12-25 15:50:34 +08:00
std::string ToIsuladContainerStatus(const runtime::v1alpha2::ContainerStateValue &state);
2019-09-30 10:53:41 -04:00
std::vector<std::string> GetSecurityOpts(const std::string &seccompProfile, const char &separator, Errors &error);
std::string CreateCheckpoint(cri::PodSandboxCheckpoint &checkpoint, Errors &error);
void GetCheckpoint(const std::string &jsonCheckPoint, cri::PodSandboxCheckpoint &checkpoint, Errors &error);
2019-12-25 15:50:34 +08:00
}; // namespace CRIHelpers
2019-09-30 10:53:41 -04:00
#endif /* _CRI_HELPERS_H_ */