Skip to content

Commit

Permalink
adding generated DeepCopy
Browse files Browse the repository at this point in the history
- Add DeepCopy methods needed for kubernetes CRDs.

Signed-off-by: André Martins <[email protected]>
  • Loading branch information
aanm authored and tgraf committed Nov 10, 2017
1 parent bdfd628 commit c77a7d8
Show file tree
Hide file tree
Showing 10 changed files with 791 additions and 31 deletions.
4 changes: 2 additions & 2 deletions daemon/k8s_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,13 +1259,13 @@ func (d *Daemon) addCiliumNetworkPolicy(obj interface{}) {
cnpns = cilium_crd.CiliumNetworkPolicyNodeStatus{
OK: false,
Error: fmt.Sprintf("%s", err),
LastUpdated: time.Now(),
LastUpdated: cilium_crd.NewTimestamp(),
}
scopedLog.WithError(err).Warn("Unable to add CiliumNetworkPolicy")
} else {
cnpns = cilium_crd.CiliumNetworkPolicyNodeStatus{
OK: true,
LastUpdated: time.Now(),
LastUpdated: cilium_crd.NewTimestamp(),
}
scopedLog.Info("Imported CiliumNetworkPolicy")
}
Expand Down
14 changes: 14 additions & 0 deletions hack/custom-boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2017 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

30 changes: 23 additions & 7 deletions pkg/k8s/apis/cilium.io/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var (
log = logrus.WithField(logfields.LogSubsys, subsysK8s)
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// CiliumNetworkPolicy is a Kubernetes third-party resource with an extended version
// of NetworkPolicy
type CiliumNetworkPolicy struct {
Expand Down Expand Up @@ -71,7 +74,25 @@ type CiliumNetworkPolicyNodeStatus struct {
Error string `json:"error,omitempty"`

// LastUpdated contains the last time this status was updated
LastUpdated time.Time `json:"lastUpdated,omitempty"`
LastUpdated Timestamp `json:"lastUpdated,omitempty"`
}

// NewTimestamp creates a new Timestamp with the current time.Now()
func NewTimestamp() Timestamp {
return Timestamp{time.Now()}
}

// Timestamp is a wrapper of time.Time so that we can create our own
// implementation of DeepCopyInto.
type Timestamp struct {
time.Time
}

// DeepCopyInto creates a deep-copy of the Time value. The underlying time.Time
// type is effectively immutable in the time API, so it is safe to
// copy-by-assign, despite the presence of (unexported) Pointer fields.
func (t *Timestamp) DeepCopyInto(out *Timestamp) {
*out = *t
}

// SetPolicyStatus sets the given policy status for the given nodes' map
Expand Down Expand Up @@ -232,12 +253,7 @@ func (r *CiliumNetworkPolicy) Parse() (api.Rules, error) {
return retRules, nil
}

// DeepCopy will return the same receiver of the DeepCopy function.
// Deprecated
func (cnp *CiliumNetworkPolicy) DeepCopy() *CiliumNetworkPolicy {
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
return cnp
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// CiliumNetworkPolicyList is a list of CiliumNetworkPolicy objects
type CiliumNetworkPolicyList struct {
Expand Down
194 changes: 194 additions & 0 deletions pkg/k8s/apis/cilium.io/v2/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// +build !ignore_autogenerated

// Copyright 2017 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

// This file was autogenerated by deepcopy-gen. Do not edit it manually!

package v2

import (
api "github.com/cilium/cilium/pkg/policy/api"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
reflect "reflect"
)

func init() {
SchemeBuilder.Register(RegisterDeepCopies)
}

// RegisterDeepCopies adds deep-copy functions to the given scheme. Public
// to allow building arbitrary schemes.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func RegisterDeepCopies(scheme *runtime.Scheme) error {
return scheme.AddGeneratedDeepCopyFuncs(
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*CiliumNetworkPolicy).DeepCopyInto(out.(*CiliumNetworkPolicy))
return nil
}, InType: reflect.TypeOf(&CiliumNetworkPolicy{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*CiliumNetworkPolicyList).DeepCopyInto(out.(*CiliumNetworkPolicyList))
return nil
}, InType: reflect.TypeOf(&CiliumNetworkPolicyList{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*CiliumNetworkPolicyNodeStatus).DeepCopyInto(out.(*CiliumNetworkPolicyNodeStatus))
return nil
}, InType: reflect.TypeOf(&CiliumNetworkPolicyNodeStatus{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*CiliumNetworkPolicyStatus).DeepCopyInto(out.(*CiliumNetworkPolicyStatus))
return nil
}, InType: reflect.TypeOf(&CiliumNetworkPolicyStatus{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Timestamp).DeepCopyInto(out.(*Timestamp))
return nil
}, InType: reflect.TypeOf(&Timestamp{})},
)
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CiliumNetworkPolicy) DeepCopyInto(out *CiliumNetworkPolicy) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Spec != nil {
in, out := &in.Spec, &out.Spec
if *in == nil {
*out = nil
} else {
*out = new(api.Rule)
(*in).DeepCopyInto(*out)
}
}
if in.Specs != nil {
in, out := &in.Specs, &out.Specs
*out = make(api.Rules, len(*in))
for i := range *in {
if (*in)[i] == nil {
(*out)[i] = nil
} else {
(*out)[i] = new(api.Rule)
(*in)[i].DeepCopyInto((*out)[i])
}
}
}
in.Status.DeepCopyInto(&out.Status)
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CiliumNetworkPolicy.
func (in *CiliumNetworkPolicy) DeepCopy() *CiliumNetworkPolicy {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicy)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *CiliumNetworkPolicy) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CiliumNetworkPolicyList) DeepCopyInto(out *CiliumNetworkPolicyList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]CiliumNetworkPolicy, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CiliumNetworkPolicyList.
func (in *CiliumNetworkPolicyList) DeepCopy() *CiliumNetworkPolicyList {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicyList)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *CiliumNetworkPolicyList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CiliumNetworkPolicyNodeStatus) DeepCopyInto(out *CiliumNetworkPolicyNodeStatus) {
*out = *in
in.LastUpdated.DeepCopyInto(&out.LastUpdated)
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CiliumNetworkPolicyNodeStatus.
func (in *CiliumNetworkPolicyNodeStatus) DeepCopy() *CiliumNetworkPolicyNodeStatus {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicyNodeStatus)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CiliumNetworkPolicyStatus) DeepCopyInto(out *CiliumNetworkPolicyStatus) {
*out = *in
if in.Nodes != nil {
in, out := &in.Nodes, &out.Nodes
*out = make(map[string]CiliumNetworkPolicyNodeStatus, len(*in))
for key, val := range *in {
newVal := new(CiliumNetworkPolicyNodeStatus)
val.DeepCopyInto(newVal)
(*out)[key] = *newVal
}
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CiliumNetworkPolicyStatus.
func (in *CiliumNetworkPolicyStatus) DeepCopy() *CiliumNetworkPolicyStatus {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicyStatus)
in.DeepCopyInto(out)
return out
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Timestamp.
func (in *Timestamp) DeepCopy() *Timestamp {
if in == nil {
return nil
}
out := new(Timestamp)
in.DeepCopyInto(out)
return out
}
19 changes: 19 additions & 0 deletions pkg/labels/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016-2017 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

// +k8s:deepcopy-gen=package

// Package api defines the API of the Cilium network policy interface
// +groupName=labels
package labels
1 change: 1 addition & 0 deletions pkg/labels/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
)

// LabelPrefix is the cilium's representation of a container label.
// +k8s:deepcopy-gen=false
type LabelPrefix struct {
// Ignore if true will cause this prefix to be ignored insted of being accepted
Ignore bool `json:"invert"`
Expand Down
27 changes: 5 additions & 22 deletions pkg/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ type OpLabels struct {
OrchestrationInfo Labels
}

// DeepCopy returns deep copy of the label.
func (o *OpLabels) DeepCopy() *OpLabels {
return &OpLabels{
Custom: o.Custom.DeepCopy(),
Disabled: o.Disabled.DeepCopy(),
OrchestrationIdentity: o.OrchestrationIdentity.DeepCopy(),
OrchestrationInfo: o.OrchestrationInfo.DeepCopy(),
}
}

// IdentityLabels returns map of labels that are used when determining a
// security identity.
func (o *OpLabels) IdentityLabels() Labels {
Expand Down Expand Up @@ -235,13 +225,6 @@ func NewLabel(key string, value string, source string) *Label {
}
}

// DeepCopy returns a Deep copy of the receiver's label.
func (l *Label) DeepCopy() *Label {
ret := NewLabel(l.Key, l.Value, l.Source)
ret.DeletionMark = l.DeletionMark
return ret
}

// Equals returns true if source, AbsoluteKey() and Value are equal and false otherwise.
func (l *Label) Equals(b *Label) bool {
if !l.IsAnySource() {
Expand Down Expand Up @@ -378,12 +361,12 @@ func Map2Labels(m map[string]string, source string) Labels {

// DeepCopy returns a deep copy of the labels.
func (l Labels) DeepCopy() Labels {
o := Labels{}
o := make(Labels, len(l))
for k, v := range l {
o[k] = &Label{
Key: v.Key,
Value: v.Value,
Source: v.Source,
if v == nil {
o[k] = nil
} else {
o[k] = v.DeepCopy()
}
}
return o
Expand Down
Loading

0 comments on commit c77a7d8

Please sign in to comment.