From c14e0537315b174443c3ce1f829b7cd093eef662 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Tue, 4 Aug 2020 15:40:12 +0800
Subject: [PATCH 1/2] chore(charts): upgrade k8s newer API versions

---
 charts/controller/templates/controller-deployment.yaml | 2 +-
 charts/controller/templates/controller-ingress.yaml    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/charts/controller/templates/controller-deployment.yaml b/charts/controller/templates/controller-deployment.yaml
index a5983dfdf..ab2ec47fd 100644
--- a/charts/controller/templates/controller-deployment.yaml
+++ b/charts/controller/templates/controller-deployment.yaml
@@ -1,4 +1,4 @@
-apiVersion: extensions/v1beta1
+apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: drycc-controller
diff --git a/charts/controller/templates/controller-ingress.yaml b/charts/controller/templates/controller-ingress.yaml
index 4accedc68..df98e6324 100644
--- a/charts/controller/templates/controller-ingress.yaml
+++ b/charts/controller/templates/controller-ingress.yaml
@@ -1,4 +1,4 @@
-apiVersion: extensions/v1beta1
+apiVersion: networking.k8s.io/v1beta1
 kind: Ingress
 metadata:
   namespace: "{{ .Release.Namespace }}"

From 2fcb15fd6c3bd76d06a43df719b941de6196eafa Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Thu, 6 Aug 2020 09:15:57 +0800
Subject: [PATCH 2/2] chore(Certificate)change cluster-issuer location

---
 .../templates/controller-certificate.yaml     | 14 ++++++-------
 .../templates/controller-cluster-issuer.yaml  | 15 ++++++++++++++
 rootfs/scheduler/resources/certificate.py     | 20 +++++++++++--------
 3 files changed, 34 insertions(+), 15 deletions(-)
 create mode 100644 charts/controller/templates/controller-cluster-issuer.yaml

diff --git a/charts/controller/templates/controller-certificate.yaml b/charts/controller/templates/controller-certificate.yaml
index 9fac3e762..a2c3a66b2 100644
--- a/charts/controller/templates/controller-certificate.yaml
+++ b/charts/controller/templates/controller-certificate.yaml
@@ -1,5 +1,5 @@
 {{ if .Values.cert_manager_enabled }}
-apiVersion: certmanager.k8s.io/v1alpha1
+apiVersion: cert-manager.io/v1alpha2
 kind: Certificate
 metadata:
   name: drycc-controller
@@ -11,10 +11,10 @@ spec:
     kind: ClusterIssuer
   dnsNames:
   - drycc.{{ .Values.platform_domain }}
-  acme:
-    config:
-    - http01:
-        ingressClass: "{{ .Values.global.ingress_class }}"
-      domains:
-      - drycc.{{ .Values.platform_domain }}
+  # acme:
+  #   config:
+  #   - http01:
+  #       ingressClass: "{{ .Values.global.ingress_class }}"
+  #     domains:
+  #     - drycc.{{ .Values.platform_domain }}
 {{- end }}
diff --git a/charts/controller/templates/controller-cluster-issuer.yaml b/charts/controller/templates/controller-cluster-issuer.yaml
new file mode 100644
index 000000000..a3cebc7d6
--- /dev/null
+++ b/charts/controller/templates/controller-cluster-issuer.yaml
@@ -0,0 +1,15 @@
+apiVersion: cert-manager.io/v1alpha2
+kind: ClusterIssuer
+metadata:
+  name: drycc-letsencrypt
+spec:
+  acme:
+    # The ACME server URL
+    server: https://acme-v02.api.letsencrypt.org/directory
+    # Email address used for ACME registration
+    email: "{{ .Values.global.email }}"
+    # Name of a secret used to store the ACME account private key
+    privateKeySecretRef:
+      name: drycc-letsencrypt
+    # Enable HTTP01 validations
+    # http01: {}
diff --git a/rootfs/scheduler/resources/certificate.py b/rootfs/scheduler/resources/certificate.py
index 8c3ea7444..453193708 100644
--- a/rootfs/scheduler/resources/certificate.py
+++ b/rootfs/scheduler/resources/certificate.py
@@ -3,10 +3,12 @@
 
 
 class Certificate(Resource):
+    api_version = 'certmanager.k8s.io/v1alpha1'
+    api_prefix = 'apis'
 
-    def manifest(self, namespace, name, ingress_class, hosts, version=None):
+    def manifest(self, api_version, namespace, name, ingress_class, hosts, version=None):
         data = {
-            "apiVersion": "certmanager.k8s.io/v1alpha1",
+            "apiVersion": api_version,
             "kind": "Certificate",
             "metadata": {
                 "name": name,
@@ -42,9 +44,10 @@ def get(self, namespace, name=None, **kwargs):
         if name is not None:
             url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (
                 namespace, name)
+            url = self.api('/namespaces/{}/certificates/{}', namespace, name)
             message = 'get certificate ' + name
         else:
-            url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates" % namespace
+            url = self.api('/namespaces/{}/certificates', namespace)
             message = 'get certificates'
         response = self.http_get(url)
         if self.unhealthy(response.status_code):
@@ -53,8 +56,9 @@ def get(self, namespace, name=None, **kwargs):
         return response
 
     def create(self, namespace, name, ingress_class, hosts):
-        url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates" % namespace
-        data = self.manifest(namespace, name, ingress_class, hosts)
+
+        url = self.api('/namespaces/{}/certificates', namespace)
+        data = self.manifest(self.api_version, namespace, name, ingress_class, hosts)
         response = self.http_post(url, json=data)
 
         if not response.status_code == 201:
@@ -63,8 +67,8 @@ def create(self, namespace, name, ingress_class, hosts):
         return response
 
     def put(self, namespace, name, ingress_class, hosts, version):
-        url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (namespace, name)
-        data = self.manifest(namespace, name, ingress_class, hosts, version)
+        url = self.api('/namespaces/{}/certificates/{}', namespace, name)
+        data = self.manifest(self.api_version, namespace, name, ingress_class, hosts, version)
         response = self.http_put(url, json=data)
 
         if self.unhealthy(response.status_code):
@@ -75,7 +79,7 @@ def delete(self, namespace, name):
         """
         Delete certificate
         """
-        url = "/apis/certmanager.k8s.io/v1alpha1/namespaces/%s/certificates/%s" % (namespace, name)
+        url = self.api('/namespaces/{}/certificates/{}', namespace, name)
         response = self.http_delete(url)
         if self.unhealthy(response.status_code):
             raise KubeHTTPException(response, 'delete certificate ' + name)
