Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Fix issues on k8s 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Aug 14, 2018
1 parent f3393a5 commit 79d4b0f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
5 changes: 3 additions & 2 deletions controllers/backend/gateway/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (g *Controller) setGatewayPorts(ns string, ports map[string]bool) error {
existingPorts[strconv.FormatUint(uint64(server.Port.Number), 10)] = true
}

if !set.Changed(ports, existingPorts) {
// can't set a gateway to zero ports, it will cause panics in pilot (v1.0.0)
if !set.Changed(ports, existingPorts) || len(ports) == 0 {
return nil
}

Expand Down Expand Up @@ -308,7 +309,7 @@ func (g *Controller) setHostPorts(ns string, hostPorts bool, ports map[string]bo
return nil
}

if hostPorts && len(toCreate) == 0 {
if hostPorts && len(toCreate) == 0 && len(ports) != 0 {
// For host ports we don't care too much about closing ports. So if all we are doing is deleting ports
// then just skip it for now
return nil
Expand Down
40 changes: 29 additions & 11 deletions controllers/backend/stack/k8s.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package stack

import (
"fmt"
"strings"

"bufio"
"io"

"bytes"

"fmt"
"io"
"reflect"
"strings"

"github.com/rancher/norman/name"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rio/pkg/apply"
"github.com/rancher/rio/types/apis/rio.cattle.io/v1beta1"
"github.com/sirupsen/logrus"
v1beta12 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -23,8 +22,16 @@ import (

func deployK8sResources(stackName, namespace string, stack *v1beta1.InternalStack) error {
var nsObjects []runtime.Object
globalObjects := crdsForCRDDefs(true, stack.Kubernetes.NamespacedCustomResourceDefinitions)
globalObjects = append(globalObjects, crdsForCRDDefs(false, stack.Kubernetes.CustomResourceDefinitions)...)
globalObjects, err := crdsForCRDDefs(true, stack.Kubernetes.NamespacedCustomResourceDefinitions)
if err != nil {
return err
}

globalCRDs, err := crdsForCRDDefs(false, stack.Kubernetes.CustomResourceDefinitions)
if err != nil {
return err
}
globalObjects = append(globalObjects, globalCRDs...)

if stack.Kubernetes.Manifest != "" {
objs, err := readManifest("", stack.Kubernetes.Manifest)
Expand Down Expand Up @@ -59,7 +66,7 @@ func deployK8sResources(stackName, namespace string, stack *v1beta1.InternalStac
return nil
}

func crdsForCRDDefs(namespaced bool, crdDefs []v1beta1.CustomResourceDefinition) []runtime.Object {
func crdsForCRDDefs(namespaced bool, crdDefs []v1beta1.CustomResourceDefinition) ([]runtime.Object, error) {
var objs []runtime.Object
for _, crdDef := range crdDefs {
plural := name.GuessPluralName(strings.ToLower(crdDef.Kind))
Expand Down Expand Up @@ -87,10 +94,21 @@ func crdsForCRDDefs(namespaced bool, crdDefs []v1beta1.CustomResourceDefinition)
crd.Spec.Scope = v1beta12.NamespaceScoped
}

objs = append(objs, crd)
// k8s 1.11 will not accept CRD with status field and marshalling CRD will always put a status field
// so workaround by converting to map
crdObj, err := convert.EncodeToMap(crd)
if err != nil {
logrus.Errorf("failed to marshal CRD %v: %v", crd, err)
return nil, err
}
delete(crdObj, "status")

objs = append(objs, &unstructured.Unstructured{
Object: crdObj,
})
}

return objs
return objs, nil
}

func readManifest(namespace, content string) ([]runtime.Object, error) {
Expand Down
2 changes: 1 addition & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y iptables
apt-get install -y iptables ca-certificates
ENV RIO_IN_CLUSTER=true
COPY rio /
COPY local-proxy /
Expand Down
6 changes: 4 additions & 2 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package apply

import (
"bytes"
"crypto/sha1"
"fmt"
"strconv"
"strings"
"sync"
"time"

"crypto/sha1"

"github.com/docker/docker/pkg/reexec"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
Expand Down Expand Up @@ -93,6 +92,9 @@ func execApply(ns string, whitelist map[string]bool, content []byte, groupID str
cmd.Stderr = errOutput

if err := cmd.Run(); err != nil {
if logrus.GetLevel() >= logrus.DebugLevel {
fmt.Printf("Failed to apply: %v\n%s", errOutput.String(), content)
}
logrus.Errorf("Failed to apply %s: %s", errOutput.String(), string(content))
return fmt.Errorf("failed to apply: %s", errOutput.String())
}
Expand Down
4 changes: 2 additions & 2 deletions stacks/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions stacks/istio-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ kubernetes:
spec:
selector:
gateway: external
servers:
- port:
protocol: "tcp"
number: 80
hosts:
- "*"

0 comments on commit 79d4b0f

Please sign in to comment.