Skip to content

Commit

Permalink
Multiple problems occured during testing.
Browse files Browse the repository at this point in the history
1: Looks like we are patching VLAN and VxLAN IDs as string for TenantNetworks.
This resulted in netwatcher not being able to handle host interfaces, as decoding failed.
We have defined "value" in the Patch struct as RawMessage, which implicitly resulted in always creating "string" patches.
Changed the type to "interface{}" to mimic the official, upstream type, and let json.Marshal take care of creating the appropriate byte[] representation.
2: For some reason ClusterNetworks and TenantNetworks Informers complain during DELETE... but not DanmNet Informer.
Trying to use separate clients and factories per API, maybe it is a multi-treading issue?
Update: turned out these items are tombstone items! We need to handle them gracefully, they might hold our objects.
3: We also unfortunetaly can't avoid separate handlers for each API due to static type correctness.
4: We need to make sure that we only try to create and start an Informer, if its respective API is present in the cluster.
We solve this by doing a "List" first, and only create the Informer if listing was successful.
  • Loading branch information
Levovar committed Jun 18, 2019
1 parent 1ccee00 commit 78a2380
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 111 deletions.
8 changes: 6 additions & 2 deletions crd/apis/danm/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&DanmEp{},
&DanmEpList{},
&DanmNet{},
&DanmNetList{},
// &DanmNet{},
// &DanmNetList{},
&ClusterNetwork{},
&ClusterNetworkList{},
&TenantNetwork{},
&TenantNetworkList{},
)
meta_v1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
4 changes: 2 additions & 2 deletions crd/apis/danm/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type TenantNetwork struct {
type TenantNetworkList struct {
meta_v1.TypeMeta `json:",inline"`
meta_v1.ListMeta `json:"metadata"`
Items []DanmNet `json:"items"`
Items []TenantNetwork `json:"items"`
}

// VERY IMPORTANT NOT TO CHANGE THIS, INCLUDING THE EMPTY LINE BETWEEN THE ANNOTATIONS!!!
Expand All @@ -156,5 +156,5 @@ type ClusterNetwork struct {
type ClusterNetworkList struct {
meta_v1.TypeMeta `json:",inline"`
meta_v1.ListMeta `json:"metadata"`
Items []DanmNet `json:"items"`
Items []ClusterNetwork `json:"items"`
}
2 changes: 2 additions & 0 deletions integration/manifests/netwatcher/0netwatcher_rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ rules:
- "danm.k8s.io"
resources:
- danmnets
- clusternetworks
- tenantnetworks
verbs:
- get
- list
Expand Down
26 changes: 12 additions & 14 deletions pkg/admit/netadmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"reflect"
"strings"
"strconv"
"time"
"encoding/json"
"math/rand"
Expand Down Expand Up @@ -217,33 +216,32 @@ func createPatchListFromNetChanges(origNetwork danmtypes.DanmNet, changedNetwork
patchList := make([]Patch, 0)
if origNetwork.Spec.Options.Alloc != changedNetwork.Spec.Options.Alloc {
//TODO: Could (?) use some reflecting here to determine name of the struct field
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Alloc"],
json.RawMessage(`"` + changedNetwork.Spec.Options.Alloc + `"`)))
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Alloc"], changedNetwork.Spec.Options.Alloc))
}
if origNetwork.Spec.NetworkType != changedNetwork.Spec.NetworkType {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["NetworkType"],
json.RawMessage(`"` + changedNetwork.Spec.NetworkType + `"`)))
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["NetworkType"], changedNetwork.Spec.NetworkType))
}
if origNetwork.Spec.NetworkID != changedNetwork.Spec.NetworkID {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["NetworkID"],
json.RawMessage(`"` + changedNetwork.Spec.NetworkID + `"`)))
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["NetworkID"], changedNetwork.Spec.NetworkID))
}
if !reflect.DeepEqual(origNetwork.Spec.Options.Pool, changedNetwork.Spec.Options.Pool) {
/* if !reflect.DeepEqual(origNetwork.Spec.Options.Pool, changedNetwork.Spec.Options.Pool) {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Pool"],
json.RawMessage(`{"Start":"` + changedNetwork.Spec.Options.Pool.Start +
`","End":"` + changedNetwork.Spec.Options.Pool.End + `"}`)))
}*/
if !reflect.DeepEqual(origNetwork.Spec.Options.Pool, changedNetwork.Spec.Options.Pool) {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Pool"], changedNetwork.Spec.Options.Pool))
}
if origNetwork.Spec.Options.Device != changedNetwork.Spec.Options.Device {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Device"],
json.RawMessage(`"` + changedNetwork.Spec.Options.Device + `"`)))
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Device"], changedNetwork.Spec.Options.Device))
}
if origNetwork.Spec.Options.Vlan != changedNetwork.Spec.Options.Vlan {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Vlan"],
json.RawMessage(`"` + strconv.Itoa(changedNetwork.Spec.Options.Vlan) + `"`)))
// vlanMarshalled,_ := json.Marshal(changedNetwork.Spec.Options.Vlan)
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Vlan"], changedNetwork.Spec.Options.Vlan))
}
if origNetwork.Spec.Options.Vxlan != changedNetwork.Spec.Options.Vxlan {
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Vxlan"],
json.RawMessage(`"` + strconv.Itoa(changedNetwork.Spec.Options.Vxlan) + `"`)))
// vxlanMarshalled,_ := json.Marshal(changedNetwork.Spec.Options.Vxlan)
patchList = append(patchList, CreateGenericPatchFromChange(NetworkPatchPaths["Vxlan"], changedNetwork.Spec.Options.Vxlan))
}
return patchList
}
6 changes: 3 additions & 3 deletions pkg/admit/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type Patch struct {
Op string `json:"op"`
Path string `json:"path"`
Value json.RawMessage `json:"value"`
Value interface{} `json:"value,omitempty"`
}

func DecodeAdmissionReview(httpRequest *http.Request) (*v1beta1.AdmissionReview,error) {
Expand Down Expand Up @@ -77,14 +77,14 @@ func CreateReviewResponseFromPatches(patchList []Patch) *v1beta1.AdmissionRespon
}
}
if len(patches) > 0 {
reviewResponse.Patch = []byte(patches)
reviewResponse.Patch = patches
pt := v1beta1.PatchTypeJSONPatch
reviewResponse.PatchType = &pt
}
return &reviewResponse
}

func CreateGenericPatchFromChange(path string, value []byte ) Patch {
func CreateGenericPatchFromChange(path string, value interface{} ) Patch {
patch := Patch {
Op: "replace",
Path: path,
Expand Down
Loading

0 comments on commit 78a2380

Please sign in to comment.