Skip to content

Commit 3e8dd17

Browse files
authored
Merge pull request projectcalico#3 from song-jiang/song-api
Added NewXXX functions to each defined v3 resource
2 parents 9c6b35a + 231bd75 commit 3e8dd17

File tree

13 files changed

+133
-2
lines changed

13 files changed

+133
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
k8s.io/api v0.21.0-rc.0
1818
k8s.io/apimachinery v0.21.0-rc.0
1919
k8s.io/client-go v0.21.0-rc.0
20-
k8s.io/code-generator v0.0.0-00010101000000-000000000000 // indirect
20+
k8s.io/code-generator v0.21.0-rc.0
2121
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
2222
)
2323

pkg/apis/projectcalico/v3/bgpconfig.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@ type PrefixAdvertisement struct {
119119
// Where,`aa` is an AS Number, `nn` and `mm` are per-AS identifier.
120120
Communities []string `json:"communities,omitempty" validate:"required"`
121121
}
122+
123+
// New BGPConfiguration creates a new (zeroed) BGPConfiguration struct with the TypeMetadata
124+
// initialized to the current version.
125+
func NewBGPConfiguration() *BGPConfiguration {
126+
return &BGPConfiguration{
127+
TypeMeta: metav1.TypeMeta{
128+
Kind: KindBGPConfiguration,
129+
APIVersion: GroupVersionCurrent,
130+
},
131+
}
132+
}

pkg/apis/projectcalico/v3/bgppeer.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,14 @@ type BGPPassword struct {
107107
// Selects a key of a secret in the node pod's namespace.
108108
SecretKeyRef *k8sv1.SecretKeySelector `json:"secretKeyRef,omitempty"`
109109
}
110+
111+
// NewBGPPeer creates a new (zeroed) BGPPeer struct with the TypeMetadata initialised to the current
112+
// version.
113+
func NewBGPPeer() *BGPPeer {
114+
return &BGPPeer{
115+
TypeMeta: metav1.TypeMeta{
116+
Kind: KindBGPPeer,
117+
APIVersion: GroupVersionCurrent,
118+
},
119+
}
120+
}

pkg/apis/projectcalico/v3/clusterinfo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ type ClusterInformationSpec struct {
5959
// Variant declares which variant of Calico should be active.
6060
Variant string `json:"variant,omitempty"`
6161
}
62+
63+
// New ClusterInformation creates a new (zeroed) ClusterInformation struct with the TypeMetadata
64+
// initialized to the current version.
65+
func NewClusterInformation() *ClusterInformation {
66+
return &ClusterInformation{
67+
TypeMeta: metav1.TypeMeta{
68+
Kind: KindClusterInformation,
69+
APIVersion: GroupVersionCurrent,
70+
},
71+
}
72+
}

pkg/apis/projectcalico/v3/felixconfig.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,14 @@ type ProtoPort struct {
396396
// +optional
397397
Net string `json:"net"`
398398
}
399+
400+
// New FelixConfiguration creates a new (zeroed) FelixConfiguration struct with the TypeMetadata
401+
// initialized to the current version.
402+
func NewFelixConfiguration() *FelixConfiguration {
403+
return &FelixConfiguration{
404+
TypeMeta: metav1.TypeMeta{
405+
Kind: KindFelixConfiguration,
406+
APIVersion: GroupVersionCurrent,
407+
},
408+
}
409+
}

pkg/apis/projectcalico/v3/globalnetworkpolicy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ type GlobalNetworkPolicySpec struct {
116116
// NamespaceSelector is an optional field for an expression used to select a pod based on namespaces.
117117
NamespaceSelector string `json:"namespaceSelector,omitempty" validate:"selector"`
118118
}
119+
120+
// NewGlobalNetworkPolicy creates a new (zeroed) GlobalNetworkPolicy struct with the TypeMetadata initialised to the current
121+
// version.
122+
func NewGlobalNetworkPolicy() *GlobalNetworkPolicy {
123+
return &GlobalNetworkPolicy{
124+
TypeMeta: metav1.TypeMeta{
125+
Kind: KindGlobalNetworkPolicy,
126+
APIVersion: GroupVersionCurrent,
127+
},
128+
}
129+
}

pkg/apis/projectcalico/v3/globalnetworkset.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ type GlobalNetworkSetSpec struct {
5050
// The list of IP networks that belong to this set.
5151
Nets []string `json:"nets,omitempty" validate:"omitempty,dive,cidr"`
5252
}
53+
54+
// NewGlobalNetworkSet creates a new (zeroed) NetworkSet struct with the TypeMetadata initialised to the current
55+
// version.
56+
func NewGlobalNetworkSet() *GlobalNetworkSet {
57+
return &GlobalNetworkSet{
58+
TypeMeta: metav1.TypeMeta{
59+
Kind: KindGlobalNetworkSet,
60+
APIVersion: GroupVersionCurrent,
61+
},
62+
}
63+
}

pkg/apis/projectcalico/v3/hostendpoint.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,14 @@ type EndpointPort struct {
8989
Protocol numorstring.Protocol `json:"protocol"`
9090
Port uint16 `json:"port" validate:"gt=0"`
9191
}
92+
93+
// NewHostEndpoint creates a new (zeroed) HostEndpoint struct with the TypeMetadata initialised to the current
94+
// version.
95+
func NewHostEndpoint() *HostEndpoint {
96+
return &HostEndpoint{
97+
TypeMeta: metav1.TypeMeta{
98+
Kind: KindHostEndpoint,
99+
APIVersion: GroupVersionCurrent,
100+
},
101+
}
102+
}

pkg/apis/projectcalico/v3/ippool.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type IPPoolSpec struct {
7373

7474
// Deprecated: this field is only used for APIv1 backwards compatibility.
7575
// Setting this field is not allowed, this field is for internal use only.
76-
IPIP IPIPConfiguration `json:"ipip,omitempty" validate:"omitempty,mustBeNil"`
76+
IPIP *IPIPConfiguration `json:"ipip,omitempty" validate:"omitempty,mustBeNil"`
7777

7878
// Deprecated: this field is only used for APIv1 backwards compatibility.
7979
// Setting this field is not allowed, this field is for internal use only.
@@ -120,3 +120,14 @@ type IPIPConfiguration struct {
120120
// originating node. The default value (if not specified) is "always".
121121
Mode EncapMode `json:"mode,omitempty" validate:"ipIpMode"`
122122
}
123+
124+
// NewIPPool creates a new (zeroed) IPPool struct with the TypeMetadata initialised to the current
125+
// version.
126+
func NewIPPool() *IPPool {
127+
return &IPPool{
128+
TypeMeta: metav1.TypeMeta{
129+
Kind: KindIPPool,
130+
APIVersion: GroupVersionCurrent,
131+
},
132+
}
133+
}

pkg/apis/projectcalico/v3/kubecontrollersconfig.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,14 @@ type KubeControllersConfigurationStatus struct {
140140
// the RunningConfig.
141141
EnvironmentVars map[string]string `json:"environmentVars,omitempty"`
142142
}
143+
144+
// New KubeControllersConfiguration creates a new (zeroed) KubeControllersConfiguration struct with
145+
// the TypeMetadata initialized to the current version.
146+
func NewKubeControllersConfiguration() *KubeControllersConfiguration {
147+
return &KubeControllersConfiguration{
148+
TypeMeta: metav1.TypeMeta{
149+
Kind: KindKubeControllersConfiguration,
150+
APIVersion: GroupVersionCurrent,
151+
},
152+
}
153+
}

0 commit comments

Comments
 (0)