Skip to content

Commit d516579

Browse files
authored
feat: pass resources to deployment'
* pass resources to deployment * generate fn and crd fields
1 parent 0676956 commit d516579

File tree

6 files changed

+186
-38
lines changed

6 files changed

+186
-38
lines changed

config/crd/bases/vpn.wireguard-operator.io_wireguardpeers.yaml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.8.0
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.14.0
87
name: wireguardpeers.vpn.wireguard-operator.io
98
spec:
109
group: vpn.wireguard-operator.io
@@ -21,14 +20,19 @@ spec:
2120
description: WireguardPeer is the Schema for the wireguardpeers API
2221
properties:
2322
apiVersion:
24-
description: 'APIVersion defines the versioned schema of this representation
25-
of an object. Servers should convert recognized schemas to the latest
26-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2728
type: string
2829
kind:
29-
description: 'Kind is a string value representing the REST resource this
30-
object represents. Servers may infer this from the endpoint the client
31-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3236
type: string
3337
metadata:
3438
type: object
@@ -46,8 +50,10 @@ spec:
4650
a valid secret key.
4751
type: string
4852
name:
49-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
50-
TODO: Add other useful fields. apiVersion, kind, uid?'
53+
description: |-
54+
Name of the referent.
55+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
56+
TODO: Add other useful fields. apiVersion, kind, uid?
5157
type: string
5258
optional:
5359
description: Specify whether the Secret or its key must be
@@ -56,13 +62,15 @@ spec:
5662
required:
5763
- key
5864
type: object
65+
x-kubernetes-map-type: atomic
5966
required:
6067
- secretKeyRef
6168
type: object
6269
address:
63-
description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
70+
description: |-
71+
INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
6472
Important: Run "make" to regenerate code after modifying this file
65-
The address of the peer.'
73+
The address of the peer.
6674
type: string
6775
disabled:
6876
description: Set to true to temporarily disable the peer.
@@ -148,10 +156,10 @@ spec:
148156
of the peer.
149157
properties:
150158
config:
151-
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
152-
of cluster Important: Run "make" to regenerate code after modifying
153-
this file A string field that contains the current configuration
154-
for the Wireguard peer.'
159+
description: |-
160+
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
161+
Important: Run "make" to regenerate code after modifying this file
162+
A string field that contains the current configuration for the Wireguard peer.
155163
type: string
156164
message:
157165
description: A string field that provides additional information about
@@ -169,9 +177,3 @@ spec:
169177
storage: true
170178
subresources:
171179
status: {}
172-
status:
173-
acceptedNames:
174-
kind: ""
175-
plural: ""
176-
conditions: []
177-
storedVersions: []

config/crd/bases/vpn.wireguard-operator.io_wireguards.yaml

Lines changed: 134 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.8.0
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.14.0
87
name: wireguards.vpn.wireguard-operator.io
98
spec:
109
group: vpn.wireguard-operator.io
@@ -21,14 +20,19 @@ spec:
2120
description: Wireguard is the Schema for the wireguards API
2221
properties:
2322
apiVersion:
24-
description: 'APIVersion defines the versioned schema of this representation
25-
of an object. Servers should convert recognized schemas to the latest
26-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2728
type: string
2829
kind:
29-
description: 'Kind is a string value representing the REST resource this
30-
object represents. Servers may infer this from the endpoint the client
31-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3236
type: string
3337
metadata:
3438
type: object
@@ -40,6 +44,67 @@ spec:
4044
VPN server. This is the public IP address or hostname that peers
4145
will use to connect to the VPN.
4246
type: string
47+
agent:
48+
description: WireguardPodSpec defines spec for respective containers
49+
created for Wireguard
50+
properties:
51+
resources:
52+
description: ResourceRequirements describes the compute resource
53+
requirements.
54+
properties:
55+
claims:
56+
description: |-
57+
Claims lists the names of resources, defined in spec.resourceClaims,
58+
that are used by this container.
59+
60+
61+
This is an alpha field and requires enabling the
62+
DynamicResourceAllocation feature gate.
63+
64+
65+
This field is immutable. It can only be set for containers.
66+
items:
67+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
68+
properties:
69+
name:
70+
description: |-
71+
Name must match the name of one entry in pod.spec.resourceClaims of
72+
the Pod where this field is used. It makes that resource available
73+
inside a container.
74+
type: string
75+
required:
76+
- name
77+
type: object
78+
type: array
79+
x-kubernetes-list-map-keys:
80+
- name
81+
x-kubernetes-list-type: map
82+
limits:
83+
additionalProperties:
84+
anyOf:
85+
- type: integer
86+
- type: string
87+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
88+
x-kubernetes-int-or-string: true
89+
description: |-
90+
Limits describes the maximum amount of compute resources allowed.
91+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
92+
type: object
93+
requests:
94+
additionalProperties:
95+
anyOf:
96+
- type: integer
97+
- type: string
98+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
99+
x-kubernetes-int-or-string: true
100+
description: |-
101+
Requests describes the minimum amount of compute resources required.
102+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
103+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
104+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
105+
type: object
106+
type: object
107+
type: object
43108
dns:
44109
description: A string field that specifies the DNS server(s) to be
45110
used by the peers.
@@ -50,6 +115,67 @@ spec:
50115
be useful to enable if the peers are having problems with sending
51116
traffic to the internet.
52117
type: boolean
118+
metric:
119+
description: WireguardPodSpec defines spec for respective containers
120+
created for Wireguard
121+
properties:
122+
resources:
123+
description: ResourceRequirements describes the compute resource
124+
requirements.
125+
properties:
126+
claims:
127+
description: |-
128+
Claims lists the names of resources, defined in spec.resourceClaims,
129+
that are used by this container.
130+
131+
132+
This is an alpha field and requires enabling the
133+
DynamicResourceAllocation feature gate.
134+
135+
136+
This field is immutable. It can only be set for containers.
137+
items:
138+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
139+
properties:
140+
name:
141+
description: |-
142+
Name must match the name of one entry in pod.spec.resourceClaims of
143+
the Pod where this field is used. It makes that resource available
144+
inside a container.
145+
type: string
146+
required:
147+
- name
148+
type: object
149+
type: array
150+
x-kubernetes-list-map-keys:
151+
- name
152+
x-kubernetes-list-type: map
153+
limits:
154+
additionalProperties:
155+
anyOf:
156+
- type: integer
157+
- type: string
158+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
159+
x-kubernetes-int-or-string: true
160+
description: |-
161+
Limits describes the maximum amount of compute resources allowed.
162+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
163+
type: object
164+
requests:
165+
additionalProperties:
166+
anyOf:
167+
- type: integer
168+
- type: string
169+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
170+
x-kubernetes-int-or-string: true
171+
description: |-
172+
Requests describes the minimum amount of compute resources required.
173+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
174+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
175+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
176+
type: object
177+
type: object
178+
type: object
53179
mtu:
54180
description: A string field that specifies the maximum transmission
55181
unit (MTU) size for Wireguard packets for all peers.
@@ -102,9 +228,3 @@ spec:
102228
storage: true
103229
subresources:
104230
status: {}
105-
status:
106-
acceptedNames:
107-
kind: ""
108-
plural: ""
109-
conditions: []
110-
storedVersions: []

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRole
44
metadata:
5-
creationTimestamp: null
65
name: manager-role
76
rules:
87
- apiGroups:

pkg/api/v1alpha1/wireguard_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ type WireguardSpec struct {
5353
EnableIpForwardOnPodInit bool `json:"enableIpForwardOnPodInit,omitempty"`
5454
// A boolean field that specifies whether to use the userspace implementation of Wireguard instead of the kernel one.
5555
UseWgUserspaceImplementation bool `json:"useWgUserspaceImplementation,omitempty"`
56+
57+
Agent WireguardPodSpec `json:"agent,omitempty"`
58+
Metric WireguardPodSpec `json:"metric,omitempty"`
59+
}
60+
61+
// WireguardPodSpec defines spec for respective containers created for Wireguard
62+
type WireguardPodSpec struct {
63+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
5664
}
5765

5866
// WireguardStatus defines the observed state of Wireguard

pkg/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controllers/wireguard_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ func (r *WireguardReconciler) deploymentForWireguard(m *v1alpha1.Wireguard) *app
736736
MountPath: "/var/run/wireguard/",
737737
},
738738
},
739+
Resources: m.Spec.Metric.Resources,
739740
},
740741
{
741742
SecurityContext: &corev1.SecurityContext{
@@ -765,6 +766,7 @@ func (r *WireguardReconciler) deploymentForWireguard(m *v1alpha1.Wireguard) *app
765766
Name: "config",
766767
MountPath: "/tmp/wireguard/",
767768
}},
769+
Resources: m.Spec.Agent.Resources,
768770
}},
769771
},
770772
},

0 commit comments

Comments
 (0)