blob: 5138c6cdba84df834a545eee48ee985e7fdb9d92 [file] [log] [blame]
# Copyright 2017-present Open Networking Foundation
#
# 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.
from xossynchronizer.steps.syncstep import SyncStep
from xossynchronizer.modelaccessor import KubernetesService
from xosconfig import Config
from multistructlog import create_logger
log = create_logger(Config().get('logging'))
class SyncK8Service(SyncStep):
provides = [KubernetesService]
observes = KubernetesService
max_version = "1.14"
[expected_major, expected_minor] = max_version.split(".")
def __init__(self, *args, **kwargs):
super(SyncK8Service, self).__init__(*args, **kwargs)
self.init_kubernetes_client()
def init_kubernetes_client(self):
from kubernetes.client.rest import ApiException
from kubernetes import client as kubernetes_client, config as kubernetes_config
kubernetes_config.load_incluster_config()
self.api_instance = kubernetes_client.VersionApi(kubernetes_client.ApiClient())
self.ApiException = ApiException
def sync_record(self, o):
log.info("[K8Service SyncStep] Sync'ing model", model=o, name=o.name)
res = self.api_instance.get_code()
major = res.major
minor = res.minor
log.info("[K8Service SyncStep] API Code", major=major, minor=minor,
expected_major=self.expected_major, expected_minor=self.expected_minor)
if major != int(self.expected_major) or minor > int(self.expected_minor):
raise Exception("Kubernetes cluster of version %s is not supported by the kubernetes-services" % res.git_version+
"the maximum supported version is %s" % self.max_version)
def delete_record(self, o):
pass