Skip to content

Commit 2949a69

Browse files
authored
fix(docgen): strip whitespaces within comment with default
Signed-off-by: Zadkiel Aharonian <zadkiel_aharonian@carrefour.com>
1 parent a269b17 commit 2949a69

4 files changed

Lines changed: 76 additions & 39 deletions

File tree

‎docs/overrides/override.md‎

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ Default: -
9494

9595
### minReadySeconds (int32, optional) {#daemonsetspec-minreadyseconds}
9696

97-
The minimum number of seconds for which a newly created DaemonSet pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready).
97+
The minimum number of seconds for which a newly created DaemonSet pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready).
9898

99-
Default: 0
99+
Default: 0
100100

101101
### revisionHistoryLimit (*int32, optional) {#daemonsetspec-revisionhistorylimit}
102102

103-
The number of old history to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 10.
103+
The number of old history to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 10.
104104

105-
Default: 10
105+
Default: 10
106106

107107

108108
## Deployment
@@ -127,9 +127,9 @@ and [PodTemplateSpec replaced by the local variant](#podtemplatespec).
127127

128128
### replicas (*int32, optional) {#deploymentspec-replicas}
129129

130-
Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
130+
Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
131131

132-
Default: 1
132+
Default: 1
133133

134134
### selector (*metav1.LabelSelector, optional) {#deploymentspec-selector}
135135

@@ -151,15 +151,15 @@ Default: -
151151

152152
### minReadySeconds (int32, optional) {#deploymentspec-minreadyseconds}
153153

154-
Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)
154+
Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)
155155

156-
Default: 0
156+
Default: 0
157157

158158
### revisionHistoryLimit (*int32, optional) {#deploymentspec-revisionhistorylimit}
159159

160-
The number of old ReplicaSets to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 10.
160+
The number of old ReplicaSets to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 10.
161161

162-
Default: 10
162+
Default: 10
163163

164164
### paused (bool, optional) {#deploymentspec-paused}
165165

@@ -169,9 +169,9 @@ Default: -
169169

170170
### progressDeadlineSeconds (*int32, optional) {#deploymentspec-progressdeadlineseconds}
171171

172-
The maximum time in seconds for a deployment to make progress before it is considered to be failed. The deployment controller will continue to process failed deployments and a condition with a ProgressDeadlineExceeded reason will be surfaced in the deployment status. Note that progress will not be estimated during the time a deployment is paused. Defaults to 600s.
172+
The maximum time in seconds for a deployment to make progress before it is considered to be failed. The deployment controller will continue to process failed deployments and a condition with a ProgressDeadlineExceeded reason will be surfaced in the deployment status. Note that progress will not be estimated during the time a deployment is paused. Defaults to 600s.
173173

174-
Default: 600
174+
Default: 600
175175

176176

177177
## StatefulSet
@@ -194,9 +194,9 @@ and [PodTemplateSpec](#podtemplatespec) and [PersistentVolumeClaim replaced by t
194194

195195
### replicas (*int32, optional) {#statefulsetspec-replicas}
196196

197-
Replicas is the desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1. +optional
197+
Replicas is the desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1. +optional
198198

199-
Default: 1
199+
Default: 1
200200

201201
### selector (*metav1.LabelSelector, optional) {#statefulsetspec-selector}
202202

@@ -224,9 +224,9 @@ Default: -
224224

225225
### podManagementPolicy (appsv1.PodManagementPolicyType, optional) {#statefulsetspec-podmanagementpolicy}
226226

227-
podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once. +optional
227+
podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once. +optional
228228

229-
Default: OrderedReady
229+
Default: OrderedReady
230230

231231
### updateStrategy (appsv1.StatefulSetUpdateStrategy, optional) {#statefulsetspec-updatestrategy}
232232

@@ -236,9 +236,9 @@ Default: -
236236

237237
### revisionHistoryLimit (*int32, optional) {#statefulsetspec-revisionhistorylimit}
238238

239-
revisionHistoryLimit is the maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10.
239+
revisionHistoryLimit is the maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10.
240240

241-
Default: 10
241+
Default: 10
242242

243243

244244
## PersistentVolumeClaim
@@ -317,15 +317,15 @@ Default: -
317317

318318
### restartPolicy (v1.RestartPolicy, optional) {#podspec-restartpolicy}
319319

320-
Restart policy for all containers within the pod. One of Always, OnFailure, Never. Default to Always.
320+
Restart policy for all containers within the pod. One of Always, OnFailure, Never. Default to Always.
321321

322-
Default: Always
322+
Default: Always
323323

324324
### terminationGracePeriodSeconds (*int64, optional) {#podspec-terminationgraceperiodseconds}
325325

326-
Optional duration in seconds the pod needs to terminate gracefully. Defaults to 30 seconds.
326+
Optional duration in seconds the pod needs to terminate gracefully. Defaults to 30 seconds.
327327

328-
Default: 30
328+
Default: 30
329329

330330
### activeDeadlineSeconds (*int64, optional) {#podspec-activedeadlineseconds}
331331

@@ -335,9 +335,9 @@ Default: -
335335

336336
### dnsPolicy (v1.DNSPolicy, optional) {#podspec-dnspolicy}
337337

338-
Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
338+
Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
339339

340-
Default: ClusterFirst
340+
Default: ClusterFirst
341341

342342
### nodeSelector (map[string]string, optional) {#podspec-nodeselector}
343343

@@ -365,27 +365,27 @@ Default: -
365365

366366
### hostNetwork (bool, optional) {#podspec-hostnetwork}
367367

368-
Host networking requested for this pod. Use the host's network namespace. If this option is set, the ports that will be used must be specified. Default to false.
368+
Host networking requested for this pod. Use the host's network namespace. If this option is set, the ports that will be used must be specified. Default to false.
369369

370-
Default: false
370+
Default: false
371371

372372
### hostPID (bool, optional) {#podspec-hostpid}
373373

374-
Use the host's pid namespace. Optional: Default to false.
374+
Use the host's pid namespace. Optional: Default to false.
375375

376-
Default: false
376+
Default: false
377377

378378
### hostIPC (bool, optional) {#podspec-hostipc}
379379

380-
Use the host's ipc namespace. Optional: Default to false.
380+
Use the host's ipc namespace. Optional: Default to false.
381381

382-
Default: false
382+
Default: false
383383

384384
### shareProcessNamespace (*bool, optional) {#podspec-shareprocessnamespace}
385385

386-
Share a single process namespace between all of the containers in a pod. HostPID and ShareProcessNamespace cannot both be set. Optional: Default to false.
386+
Share a single process namespace between all of the containers in a pod. HostPID and ShareProcessNamespace cannot both be set. Optional: Default to false.
387387

388-
Default: false
388+
Default: false
389389

390390
### securityContext (*v1.PodSecurityContext, optional) {#podspec-securitycontext}
391391

@@ -467,15 +467,15 @@ Default: -
467467

468468
### enableServiceLinks (*bool, optional) {#podspec-enableservicelinks}
469469

470-
EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links. Optional: Defaults to true.
470+
EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links. Optional: Defaults to true.
471471

472-
Default: true
472+
Default: true
473473

474474
### preemptionPolicy (*v1.PreemptionPolicy, optional) {#podspec-preemptionpolicy}
475475

476-
PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.
476+
PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.
477477

478-
Default: PreemptLowerPriority
478+
Default: PreemptLowerPriority
479479

480480
### overhead (v1.ResourceList, optional) {#podspec-overhead}
481481

@@ -491,9 +491,9 @@ Default: -
491491

492492
### setHostnameAsFQDN (*bool, optional) {#podspec-sethostnameasfqdn}
493493

494-
If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default). Default to false. +optional
494+
If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default). Default to false. +optional
495495

496-
Default: false
496+
Default: false
497497

498498

499499
## ServiceAccount

‎pkg/docgen/docgen.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ func (d *Doc) getValuesFromItem(item *ast.Field) (name, comment, def, required s
289289
result := GetPrefixedValue(commentWithDefault, `\(default:(.*)\)`)
290290
if result != "" {
291291
ignore := fmt.Sprintf("(default:%s)", result)
292-
comment = strings.Replace(commentWithDefault, ignore, "", 1)
292+
comment = strings.TrimSpace(strings.Replace(commentWithDefault, ignore, "", 1))
293+
result = strings.TrimSpace(result)
293294
return nameResult, comment, getLink(result), required, nil
294295
}
295296

‎pkg/docgen/docgen_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ func TestGenParse(t *testing.T) {
7373
Default: testval
7474
`),
7575
},
76+
{
77+
docItem: docgen.DocItem{
78+
Name: "sample-default-comment",
79+
SourcePath: filepath.Join(currentDir, "testdata", "sample_default_comment.go"),
80+
DestPath: filepath.Join(currentDir, "../../build/_test/docgen"),
81+
},
82+
expected: heredoc.Doc(`
83+
## SampleDefaultComment
84+
85+
### field1 (string, optional) {#sampledefaultcomment-field1}
86+
87+
Field1 is a good field.
88+
89+
Default: testval
90+
`),
91+
},
7692
{
7793
docItem: docgen.DocItem{
7894
Name: "sample-codeblock",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright © 2020 Banzai Cloud
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package testdata
16+
17+
type SampleDefaultComment struct {
18+
// Field1 is a good field. (default: testval)
19+
Field1 string `json:"field1,omitempty"`
20+
}

0 commit comments

Comments
 (0)