Skip to content

Commit

Permalink
Merge pull request #197 from fiaas/python3-take-2
Browse files Browse the repository at this point in the history
Use python 3.9
  • Loading branch information
oyvindio authored Jan 5, 2023
2 parents c90f246 + f39d226 commit 401e604
Show file tree
Hide file tree
Showing 88 changed files with 283 additions and 261 deletions.
8 changes: 5 additions & 3 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ blocks:
- name: docker
prologue:
commands:
- sem-version python 3.9
- checkout
- docker login --username "${DOCKER_USERNAME}" --password-stdin <<< "${DOCKER_PASSWORD}"
- export PATH="$PATH:$HOME/.local/bin"
- pip install --user .[ci]
- pip install .[ci]
jobs:
- name: "Unit tests + docker build"
commands:
Expand All @@ -44,9 +44,11 @@ blocks:
task:
prologue:
commands:
- sem-version python 3.9
- checkout
- pip install .[ci]
- mkdir -p "$HOME/.local/bin"
- export PATH="$PATH:$HOME/.local/bin"
- pip install --user .[ci]
- curl -Lo $HOME/.local/bin/kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64 && chmod +x $HOME/.local/bin/kind
- cache restore "${SEMAPHORE_PROJECT_NAME}-${SEMAPHORE_WORKFLOW_ID}-build"
jobs:
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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 python:2-alpine3.8 as common
FROM python:3.9-alpine3.16 as common
MAINTAINER [email protected]
# Install any binary package dependencies here
RUN apk --no-cache add \
Expand All @@ -29,9 +29,6 @@ COPY . /fiaas-deploy-daemon
COPY .wheel_cache/*.whl /links/
WORKDIR /fiaas-deploy-daemon

# setuptools needs to be upgraded in order to perform the build of the wheels
# Note: setuptools 45.0.0 will drop the support for python 2
RUN pip install -U setuptools==44.1.1
RUN pip wheel . --no-cache-dir --wheel-dir=/wheels/ --find-links=/links/

FROM common as production
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Useful resources:

- http://docs.python-guide.org/
- http://pytest.org/
- http://www.voidspace.org.uk/python/mock
- http://flask.pocoo.org/

Running fiaas-deploy-daemon against a local `minikube` or `kind` backed Kubernetes cluster
Expand Down
2 changes: 1 addition & 1 deletion bin/ingress_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import, unicode_literals, print_function


import base64
import logging
Expand Down
6 changes: 3 additions & 3 deletions fiaas_deploy_daemon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
# 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 __future__ import absolute_import


import logging
import os
import signal
import sys
import threading
import traceback
from Queue import Queue
from queue import Queue

import pinject
import requests
Expand Down Expand Up @@ -127,7 +127,7 @@ def thread_dump_logger(log):
def _dump_threads(signum, frame):
log.info("Received signal %s, dumping thread stacks", signum)
thread_names = {t.ident: t.name for t in threading.enumerate()}
for thread_ident, frame in sys._current_frames().items():
for thread_ident, frame in list(sys._current_frames().items()):
log.info("Thread ident=0x%x name=%s", thread_ident, thread_names.get(thread_ident, "unknown"))
log.info("".join(traceback.format_stack(frame)))

Expand Down
4 changes: 2 additions & 2 deletions fiaas_deploy_daemon/bootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# 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 __future__ import absolute_import


import logging
import sys
from Queue import Queue
from queue import Queue

import pinject
import requests
Expand Down
13 changes: 6 additions & 7 deletions fiaas_deploy_daemon/bootstrap/bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging
import threading
import time

from blinker import signal
from monotonic import monotonic as time_monotonic
from time import monotonic as time_monotonic
from yaml import YAMLError

from ..config import InvalidConfigurationException
Expand All @@ -48,10 +47,10 @@ def store_status(self, status, app_name, namespace):

def values(self):
with self._statuses_lock:
return self._statuses.values()
return list(self._statuses.values())

def items(self):
for key, status in self._statuses.iteritems():
for key, status in self._statuses.items():
name, namespace = key
yield name, namespace, status

Expand Down Expand Up @@ -131,15 +130,15 @@ def _store_status(self, sender, status, subject):
def _wait_for_readiness(self, wait_time_seconds, timeout_seconds):
start = time_monotonic()
while time_monotonic() < (start + timeout_seconds):
if all(status == STATUS_SUCCESS for status in self._status_collector.values()):
LOG.info("Bootstrapped {} applications".format(len(self._status_collector.values())))
if all(status == STATUS_SUCCESS for status in list(self._status_collector.values())):
LOG.info("Bootstrapped {} applications".format(len(list(self._status_collector.values()))))
return True
else:
time.sleep(wait_time_seconds)

message = "Timed out after waiting {}s for applications to become ready.\n".format(timeout_seconds)
message += "Applications which failed to become ready:\n"
for name, namespace, status in self._status_collector.items():
for name, namespace, status in list(self._status_collector.items()):
message += "{} in namespace {} had final state {}\n".format(name, namespace, status)
LOG.error(message)
return False
4 changes: 2 additions & 2 deletions fiaas_deploy_daemon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _parse_args(self, args):
action="store_true")
parser.add_argument("--deployment-max-surge", help="maximum number of extra pods that can be scheduled above the desired "
"number of pods during an update",
default=u"25%", type=_int_or_unicode)
default="25%", type=_int_or_unicode)
parser.add_argument("--deployment-max-unavailable", help="The maximum number of pods that can be unavailable during an update",
default="0", type=_int_or_unicode)
parser.add_argument("--enable-deprecated-tls-entry-per-host", help=TLS_ENTRY_PER_HOST_HELP,
Expand Down Expand Up @@ -360,4 +360,4 @@ def _int_or_unicode(arg):
try:
return int(arg)
except ValueError:
return unicode(arg)
return str(arg)
2 changes: 1 addition & 1 deletion fiaas_deploy_daemon/crd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


import pinject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging

Expand Down
6 changes: 3 additions & 3 deletions fiaas_deploy_daemon/crd/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging
import struct
Expand All @@ -22,6 +21,7 @@

import pytz
from blinker import signal
from py27hash.hash import hash27
from k8s.client import NotFound
from k8s.models.common import ObjectMeta, OwnerReference

Expand Down Expand Up @@ -85,7 +85,7 @@ def _save_status(result, subject):


def _get_logs(app_name, namespace, deployment_id, result):
return get_running_logs(app_name, namespace, deployment_id) if result in [u"RUNNING", u"INITIATED"] else \
return get_running_logs(app_name, namespace, deployment_id) if result in ["RUNNING", "INITIATED"] else \
get_final_logs(app_name, namespace, deployment_id)


Expand All @@ -110,7 +110,7 @@ def create_name(name, deployment_id):
By convention, the names of Kubernetes resources should be up to maximum length of 253
characters and consist of lower case alphanumeric characters, '-', and '.'.
"""
suffix = b32encode(struct.pack('q', hash(deployment_id))).lower().strip("=")
suffix = b32encode(struct.pack('q', hash27(deployment_id))).decode("utf-8").lower().strip("=")
return "{}-{}".format(name, suffix)


Expand Down
2 changes: 1 addition & 1 deletion fiaas_deploy_daemon/crd/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


import six
from k8s.base import Model
Expand Down
1 change: 0 additions & 1 deletion fiaas_deploy_daemon/crd/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging

Expand Down
2 changes: 1 addition & 1 deletion fiaas_deploy_daemon/deployer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


from collections import namedtuple

Expand Down
1 change: 0 additions & 1 deletion fiaas_deploy_daemon/deployer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging

Expand Down
2 changes: 1 addition & 1 deletion fiaas_deploy_daemon/deployer/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


import pinject

Expand Down
2 changes: 1 addition & 1 deletion fiaas_deploy_daemon/deployer/kubernetes/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import, unicode_literals


import logging

Expand Down
4 changes: 2 additions & 2 deletions fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


import logging

Expand All @@ -41,7 +41,7 @@ def deploy(self, app_spec, labels):
custom_labels = merge_dicts(app_spec.labels.horizontal_pod_autoscaler, labels)
metadata = ObjectMeta(name=app_spec.name, namespace=app_spec.namespace, labels=custom_labels,
annotations=app_spec.annotations.horizontal_pod_autoscaler)
scale_target_ref = CrossVersionObjectReference(kind=u"Deployment", name=app_spec.name, apiVersion="apps/v1")
scale_target_ref = CrossVersionObjectReference(kind="Deployment", name=app_spec.name, apiVersion="apps/v1")
spec = HorizontalPodAutoscalerSpec(scaleTargetRef=scale_target_ref,
minReplicas=app_spec.autoscaler.min_replicas,
maxReplicas=app_spec.autoscaler.max_replicas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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 __future__ import absolute_import


import pinject as pinject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _make_env(self, app_spec):
# fiaas_managed_env overrides global_env overrides legacy_fiaas_env
static_env = merge_dicts(self._legacy_fiaas_env, self._global_env, fiaas_managed_env)

env = [EnvVar(name=name, value=value) for name, value in static_env.items()]
env = [EnvVar(name=name, value=value) for name, value in list(static_env.items())]

# FIAAS managed environment variables using the downward API
env.extend([
Expand Down Expand Up @@ -222,7 +222,7 @@ def _make_probe(check_spec):
if check_spec.http:
probe.httpGet = HTTPGetAction(path=check_spec.http.path, port=check_spec.http.port,
httpHeaders=[HTTPHeader(name=name, value=value)
for name, value in check_spec.http.http_headers.items()])
for name, value in list(check_spec.http.http_headers.items())])
elif check_spec.tcp:
probe.tcpSocket = TCPSocketAction(port=check_spec.tcp.port)
elif check_spec.execute:
Expand Down Expand Up @@ -254,5 +254,5 @@ def _build_global_env(global_env):
global_env key/value are added as is and with the key prefix FIAAS_
"""
_global_env_copy = global_env.copy()
_global_env_copy.update({'FIAAS_{}'.format(k): v for k, v in _global_env_copy.items()})
_global_env_copy.update({'FIAAS_{}'.format(k): v for k, v in list(_global_env_copy.items())})
return _global_env_copy
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _make_secrets_init_container(self, app_spec, image, env_vars=None):
if env_vars is None:
env_vars = {}
env_vars.update({"K8S_DEPLOYMENT": app_spec.name})
environment = [EnvVar(name=k, value=v) for k, v in env_vars.items()]
environment = [EnvVar(name=k, value=v) for k, v in list(env_vars.items())]
container = Container(name=self.SECRETS_INIT_CONTAINER_NAME,
image=image,
imagePullPolicy="IfNotPresent",
Expand Down
Loading

0 comments on commit 401e604

Please sign in to comment.