Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anggao committed Oct 14, 2020
1 parent ab3a11c commit 6d39daa
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 30 deletions.
24 changes: 18 additions & 6 deletions operator/hack/create_graph_openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
import sys
import copy


def getOpts(cmd_line_args):
parser = argparse.ArgumentParser(description="Create graph OpenAPI schema patch. Takes an input template and output Kustomize path for given number of levels")
parser = argparse.ArgumentParser(
description="Create graph OpenAPI schema patch. Takes an input template and output Kustomize path for given number of levels"
)
parser.add_argument("template", help="the yaml template for 1 level of the graph")
parser.add_argument("path", help="the output path to save result")
parser.add_argument("--levels", help="the number of levels to create", type=int, default=10)
parser.add_argument(
"--levels", help="the number of levels to create", type=int, default=10
)
opts = parser.parse_args(cmd_line_args)
return opts


def expand_tmpl(filename, levels):
with open(filename, "r") as stream:
y = yaml.safe_load(stream)
Expand All @@ -19,15 +25,20 @@ def expand_tmpl(filename, levels):
child = copy.deepcopy(tmpl)
tmpl["properties"]["children"]["items"] = child
tmpl = child
if i == levels-1:
if i == levels - 1:
del tmpl["properties"]["children"]
# add replace for second and third schema version
y.append(copy.deepcopy(y[0]))
y[1]["path"] = "/spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/predictors/items/properties/graph"
y[1][
"path"
] = "/spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/predictors/items/properties/graph"
y.append(copy.deepcopy(y[0]))
y[2]["path"] = "/spec/versions/2/schema/openAPIV3Schema/properties/spec/properties/predictors/items/properties/graph"
y[2][
"path"
] = "/spec/versions/2/schema/openAPIV3Schema/properties/spec/properties/predictors/items/properties/graph"
return y


def main(argv):
opts = getOpts(argv[1:])
print(opts)
Expand All @@ -36,5 +47,6 @@ def main(argv):
with open(opts.path, "w") as outfile:
outfile.write(fdata)


if __name__ == "__main__":
main(sys.argv)
main(sys.argv)
11 changes: 7 additions & 4 deletions operator/hack/csv_hack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
import argparse
import sys


def getOpts(cmd_line_args):
parser = argparse.ArgumentParser(description="remove csv CRD versions")
parser.add_argument("path", help="the output path to save result")
opts = parser.parse_args(cmd_line_args)
return opts


def remove_versions(filename):
with open(filename, "r") as stream:
y = yaml.safe_load(stream)
del y["spec"]["customresourcedefinitions"]["owned"][2]
del y["spec"]["customresourcedefinitions"]["owned"][1]
return y


def str_presenter(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)


def main(argv):
Expand All @@ -32,4 +35,4 @@ def main(argv):

if __name__ == "__main__":
yaml.add_representer(str, str_presenter)
main(sys.argv)
main(sys.argv)
53 changes: 38 additions & 15 deletions operator/helm/split_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
HELM_CERTMANAGER_IF_START = "{{- if .Values.certManager.enabled -}}\n"
HELM_NOT_CERTMANAGER_IF_START = "{{- if not .Values.certManager.enabled -}}\n"
HELM_VERSION_IF_START = (
'{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.GitVersion }}\n'
'{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.GitVersion }}\n'
)
HELM_KUBEFLOW_IF_START = "{{- if .Values.kubeflow }}\n"
HELM_KUBEFLOW_IF_NOT_START = "{{- if not .Values.kubeflow }}\n"
Expand Down Expand Up @@ -95,10 +95,21 @@ def helm_release(value: str):
filename = args.folder + "/" + (kind + "_" + name).lower() + ".yaml"
print(filename)
print(version)
if filename == (args.folder + "/" + "customresourcedefinition_seldondeployments.machinelearning.seldon.io.yaml") \
and version == "apiextensions.k8s.io/v1":
if (
filename
== (
args.folder
+ "/"
+ "customresourcedefinition_seldondeployments.machinelearning.seldon.io.yaml"
)
and version == "apiextensions.k8s.io/v1"
):
print("MATCH")
filename = args.folder + "/" + "customresourcedefinition_v1_seldondeployments.machinelearning.seldon.io.yaml"
filename = (
args.folder
+ "/"
+ "customresourcedefinition_v1_seldondeployments.machinelearning.seldon.io.yaml"
)

print("Processing ", file)
# Update common labels
Expand Down Expand Up @@ -368,16 +379,28 @@ def helm_release(value: str):
fdata = HELM_CERTMANAGER_IF_START + fdata + HELM_IF_END
elif name == "seldon-webhook-server-cert" and kind == "secret":
fdata = HELM_NOT_CERTMANAGER_IF_START + fdata + HELM_IF_END
elif name == "seldondeployments.machinelearning.seldon.io" and \
version == "apiextensions.k8s.io/v1beta1":
fdata = HELM_CRD_IF_START + \
HELM_K8S_V1BETA1_CRD_IF_START + fdata + \
HELM_IF_END + HELM_IF_END
elif name == "seldondeployments.machinelearning.seldon.io" and \
version == "apiextensions.k8s.io/v1":
fdata = HELM_CRD_IF_START + \
HELM_K8S_V1_CRD_IF_START + fdata + \
HELM_IF_END + HELM_IF_END
elif (
name == "seldondeployments.machinelearning.seldon.io"
and version == "apiextensions.k8s.io/v1beta1"
):
fdata = (
HELM_CRD_IF_START
+ HELM_K8S_V1BETA1_CRD_IF_START
+ fdata
+ HELM_IF_END
+ HELM_IF_END
)
elif (
name == "seldondeployments.machinelearning.seldon.io"
and version == "apiextensions.k8s.io/v1"
):
fdata = (
HELM_CRD_IF_START
+ HELM_K8S_V1_CRD_IF_START
+ fdata
+ HELM_IF_END
+ HELM_IF_END
)
elif kind == "service" and name == "seldon-webhook-service":
fdata = HELM_CREATERESOURCES_IF_START + fdata + HELM_IF_END
elif kind == "configmap" and name == "seldon-config":
Expand Down Expand Up @@ -468,7 +491,7 @@ def helm_release(value: str):
)
webhookData = webhookData + "\n" + HELM_IF_END

print("Webhook data len",len(webhookData))
print("Webhook data len", len(webhookData))

filename = args.folder + "/" + "webhook.yaml"
with open(filename, "w") as outfile:
Expand Down
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ setup_linter:

fmt:
black \
./ ../testing ../operator/helm ../operator/seldon-operator/hack \
./ ../testing ../operator/helm ../operator/hack \
--exclude "(testing/scripts/proto|seldon_core/proto/|.eggs|.tox)"

lint: licenses
Expand Down
5 changes: 1 addition & 4 deletions python/seldon_core/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ def main():
)

parser.add_argument(
"--pidfile",
type=str,
default=None,
help="A file path to use for the PID file",
"--pidfile", type=str, default=None, help="A file path to use for the PID file",
)

args = parser.parse_args()
Expand Down

0 comments on commit 6d39daa

Please sign in to comment.