Skip to content

Commit

Permalink
upgrade decco to k8s v1.16.x APIs (#18)
Browse files Browse the repository at this point in the history
* upgrade decco to k8s v1.16.x APIs

* revert CRD changes because not ready to provide required validation schema

Co-authored-by: Bich Le <leb@platform9.com>
  • Loading branch information
bcle and Bich Le authored Jun 15, 2020
1 parent 420ce4a commit 282f404
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 44 deletions.
5 changes: 2 additions & 3 deletions cmd/operator/operator_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (
"os"
"time"

"github.com/platform9/decco/pkg/k8sutil"
"github.com/platform9/decco/pkg/spacecontroller"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

"github.com/platform9/decco/pkg/k8sutil"
"github.com/platform9/decco/pkg/spacecontroller"
)

func main() {
Expand Down
45 changes: 22 additions & 23 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import (
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"

spec "github.com/platform9/decco/pkg/appspec"
"github.com/platform9/decco/pkg/dns"
"github.com/platform9/decco/pkg/k8sutil"
sspec "github.com/platform9/decco/pkg/spec"
"github.com/platform9/decco/pkg/watcher"
"github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"

spec "github.com/platform9/decco/pkg/appspec"
"github.com/platform9/decco/pkg/dns"
"github.com/platform9/decco/pkg/k8sutil"
sspec "github.com/platform9/decco/pkg/spec"
"github.com/platform9/decco/pkg/watcher"
"reflect"
"strings"
netv1beta1 "k8s.io/api/networking/v1beta1"
)

var (
Expand Down Expand Up @@ -124,7 +123,7 @@ func (ar *AppRuntime) Delete() {
log.Warnf("failed to delete job: %s", err)
}
} else {
deployApi := ar.kubeApi.ExtensionsV1beta1().Deployments(ar.namespace)
deployApi := ar.kubeApi.AppsV1().Deployments(ar.namespace)
err := deployApi.Delete(ar.app.Name, &delOpts)
if err != nil {
log.Warnf("failed to delete deployment: %s", err)
Expand Down Expand Up @@ -545,9 +544,9 @@ func (ar *AppRuntime) createDeployment(
})
return err
} else {
depSpec := &v1beta1.Deployment{
depSpec := &appsv1.Deployment{
ObjectMeta: objMeta,
Spec: v1beta1.DeploymentSpec{
Spec: appsv1.DeploymentSpec{
Replicas: &initialReplicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand All @@ -557,7 +556,7 @@ func (ar *AppRuntime) createDeployment(
Template: podTemplateSpec,
},
}
depApi := ar.kubeApi.ExtensionsV1beta1().Deployments(ar.namespace)
depApi := ar.kubeApi.AppsV1().Deployments(ar.namespace)
_, err := depApi.Create(depSpec)
return err
}
Expand Down Expand Up @@ -689,7 +688,7 @@ func (ar *AppRuntime) createHttpIngress(e *spec.EndpointSpec) error {
// -----------------------------------------------------------------------------

func (ar *AppRuntime) deleteIngress(e *spec.EndpointSpec) error {
ingApi := ar.kubeApi.ExtensionsV1beta1().Ingresses(ar.namespace)
ingApi := ar.kubeApi.NetworkingV1beta1().Ingresses(ar.namespace)
ingName := e.Name
return ingApi.Delete(ingName, &metav1.DeleteOptions{})
}
Expand Down Expand Up @@ -718,8 +717,8 @@ func (ar *AppRuntime) createTcpIngress(
anno[key] = val
}
anno["kubernetes.io/ingress.class"] = "k8sniff"
ingApi := ar.kubeApi.ExtensionsV1beta1().Ingresses(ar.namespace)
ing := v1beta1.Ingress{
ingApi := ar.kubeApi.NetworkingV1beta1().Ingresses(ar.namespace)
ing := netv1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: e.Name,
Labels: map[string]string{
Expand All @@ -728,15 +727,15 @@ func (ar *AppRuntime) createTcpIngress(
},
Annotations: anno,
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
Spec: netv1beta1.IngressSpec{
Rules: []netv1beta1.IngressRule{
{
Host: hostName,
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
IngressRuleValue: netv1beta1.IngressRuleValue{
HTTP: &netv1beta1.HTTPIngressRuleValue{
Paths: []netv1beta1.HTTPIngressPath{
{
Backend: v1beta1.IngressBackend{
Backend: netv1beta1.IngressBackend{
ServiceName: e.Name,
ServicePort: intstr.IntOrString{
Type: intstr.Int,
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func collectDeployments(kubeApi kubernetes.Interface,
isKnownApp func(name string) bool) {

log = log.WithField("func", "collectDeployments")
deplApi := kubeApi.ExtensionsV1beta1().Deployments(namespace)
deplApi := kubeApi.AppsV1().Deployments(namespace)
nses, err := deplApi.List(metav1.ListOptions{
LabelSelector: "decco-derived-from=app",
},
Expand Down Expand Up @@ -86,7 +86,7 @@ func collectIngresses(kubeApi kubernetes.Interface,
isKnownApp func(name string) bool) {

log = log.WithField("func", "collectIngresses")
ingApi := kubeApi.ExtensionsV1beta1().Ingresses(namespace)
ingApi := kubeApi.NetworkingV1beta1().Ingresses(namespace)
ingList, err := ingApi.List(metav1.ListOptions{
LabelSelector: "decco-derived-from=app",
},
Expand Down
24 changes: 12 additions & 12 deletions pkg/k8sutil/ingress.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package k8sutil

import (
"k8s.io/api/extensions/v1beta1"
netv1beta1 "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
Expand All @@ -22,7 +22,7 @@ func CreateHttpIngress(
localhostOnly bool,
additionalAnnotations map[string]string,
) error {
ingApi := kubeApi.ExtensionsV1beta1().Ingresses(ns)
ingApi := kubeApi.NetworkingV1beta1().Ingresses(ns)
annotations := make(map[string]string)
// Copy over additional annotations.
// Note: this works even if additionalAnnotations is nil
Expand All @@ -41,12 +41,12 @@ func CreateHttpIngress(
if encryptHttp {
annotations["nginx.ingress.kubernetes.io/secure-backends"] = "true"
}
ruleValue := v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
ruleValue := netv1beta1.IngressRuleValue{
HTTP: &netv1beta1.HTTPIngressRuleValue{
Paths: []netv1beta1.HTTPIngressPath{
{
Path: path,
Backend: v1beta1.IngressBackend{
Backend: netv1beta1.IngressBackend{
ServiceName: svcName,
ServicePort: intstr.IntOrString{
Type: intstr.Int,
Expand All @@ -57,32 +57,32 @@ func CreateHttpIngress(
},
},
}
var tls []v1beta1.IngressTLS
rules := []v1beta1.IngressRule{
var tls []netv1beta1.IngressTLS
rules := []netv1beta1.IngressRule{
{
Host: "localhost",
IngressRuleValue: ruleValue,
},
}
if !localhostOnly {
rules = append(rules, v1beta1.IngressRule{
rules = append(rules, netv1beta1.IngressRule{
Host: hostName,
IngressRuleValue: ruleValue,
})
tls = append(tls, v1beta1.IngressTLS{
tls = append(tls, netv1beta1.IngressTLS{
Hosts: []string{
hostName,
},
SecretName: secretName,
})
}
ing := v1beta1.Ingress{
ing := netv1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: labels,
Annotations: annotations,
},
Spec: v1beta1.IngressSpec{
Spec: netv1beta1.IngressSpec{
Rules: rules,
TLS: tls,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cenkalti/backoff"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
netv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -415,7 +415,7 @@ func (c *SpaceRuntime) createHttpIngress() error {
// -----------------------------------------------------------------------------

func (c *SpaceRuntime) createDefaultHttpDeploy() error {
depApi := c.kubeApi.ExtensionsV1beta1().Deployments(c.Space.Name)
depApi := c.kubeApi.AppsV1().Deployments(c.Space.Name)
var volumes []v1.Volume
containers := []v1.Container{
{
Expand Down Expand Up @@ -478,14 +478,14 @@ func (c *SpaceRuntime) createDefaultHttpDeploy() error {
{ContainerPort: defaultHttpInternalPort},
}
}
_, err := depApi.Create(&v1beta1.Deployment{
_, err := depApi.Create(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "default-http",
Labels: map[string]string{
"app": "decco",
},
},
Spec: v1beta1.DeploymentSpec{
Spec: appsv1.DeploymentSpec{
Replicas: nil,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand Down

0 comments on commit 282f404

Please sign in to comment.