Skip to content

Commit 4140ea4

Browse files
authored
Package conditions (#3614)
1 parent b7174fd commit 4140ea4

23 files changed

+1261
-86
lines changed

pkg/api/kptfile/v1/types.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type KptFile struct {
7575

7676
// Inventory contains parameters for the inventory object used in apply.
7777
Inventory *Inventory `yaml:"inventory,omitempty" json:"inventory,omitempty"`
78+
79+
Status *Status `yaml:"status,omitempty" json:"status,omitempty"`
7880
}
7981

8082
// OriginType defines the type of origin for a package.
@@ -210,6 +212,12 @@ type PackageInfo struct {
210212

211213
// Man is the path to documentation about the package
212214
Man string `yaml:"man,omitempty" json:"man,omitempty"`
215+
216+
ReadinessGates []ReadinessGate `yaml:"readinessGates,omitempty" json:"readinessGates,omitempty"`
217+
}
218+
219+
type ReadinessGate struct {
220+
ConditionType string `yaml:"conditionType" json:"conditionType"`
213221
}
214222

215223
// Subpackages declares a local or remote subpackage.
@@ -359,3 +367,25 @@ func (i Inventory) IsValid() bool {
359367
// Name, Namespace InventoryID are required inventory fields, so we check these 3 fields.
360368
return i.Name != "" && i.Namespace != "" && i.InventoryID != ""
361369
}
370+
371+
type Status struct {
372+
Conditions []Condition `yaml:"conditions,omitempty" json:"conditions,omitempty"`
373+
}
374+
375+
type Condition struct {
376+
Type string `yaml:"type" json:"type"`
377+
378+
Status ConditionStatus `yaml:"status" json:"status"`
379+
380+
Reason string `yaml:"reason,omitempty" json:"reason,omitempty"`
381+
382+
Message string `yaml:"message,omitempty" json:"message,omitempty"`
383+
}
384+
385+
type ConditionStatus string
386+
387+
const (
388+
ConditionTrue ConditionStatus = "True"
389+
ConditionFalse ConditionStatus = "False"
390+
ConditionUnknown ConditionStatus = "Unknown"
391+
)

pkg/kptfile/kptfileutil/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ func merge(localKf, updatedKf, originalKf *kptfilev1.KptFile) error {
271271
localKf.Info = mergedKf.Info
272272
localKf.Pipeline = mergedKf.Pipeline
273273
localKf.Inventory = mergedKf.Inventory
274+
localKf.Status = mergedKf.Status
274275
return nil
275276
}
276277

pkg/kptfile/kptfileutil/util_test.go

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,254 @@ kind: Kptfile
321321
metadata:
322322
name: foo
323323
pipeline: {}
324+
`,
325+
},
326+
"first readinessGate and condition added in upstream": {
327+
origin: `
328+
apiVersion: kpt.dev/v1
329+
kind: Kptfile
330+
metadata:
331+
name: foo
332+
`,
333+
updated: `
334+
apiVersion: kpt.dev/v1
335+
kind: Kptfile
336+
metadata:
337+
name: foo
338+
info:
339+
readinessGates:
340+
- conditionType: foo
341+
status:
342+
conditions:
343+
- type: foo
344+
status: "True"
345+
reason: reason
346+
message: message
347+
`,
348+
local: `
349+
apiVersion: kpt.dev/v1
350+
kind: Kptfile
351+
metadata:
352+
name: foo
353+
`,
354+
updateUpstream: false,
355+
expected: `
356+
apiVersion: kpt.dev/v1
357+
kind: Kptfile
358+
metadata:
359+
name: foo
360+
info:
361+
readinessGates:
362+
- conditionType: foo
363+
status:
364+
conditions:
365+
- type: foo
366+
status: "True"
367+
reason: reason
368+
message: message
369+
`,
370+
},
371+
"additional readinessGate and condition added in upstream": {
372+
origin: `
373+
apiVersion: kpt.dev/v1
374+
kind: Kptfile
375+
metadata:
376+
name: foo
377+
info:
378+
readinessGates:
379+
- conditionType: foo
380+
status:
381+
conditions:
382+
- type: foo
383+
status: "True"
384+
reason: reason
385+
message: message
386+
`,
387+
updated: `
388+
apiVersion: kpt.dev/v1
389+
kind: Kptfile
390+
metadata:
391+
name: foo
392+
info:
393+
readinessGates:
394+
- conditionType: foo
395+
- conditionType: bar
396+
status:
397+
conditions:
398+
- type: foo
399+
status: "True"
400+
reason: reason
401+
message: message
402+
- type: bar
403+
status: "False"
404+
reason: reason
405+
message: message
406+
`,
407+
local: `
408+
apiVersion: kpt.dev/v1
409+
kind: Kptfile
410+
metadata:
411+
name: foo
412+
info:
413+
readinessGates:
414+
- conditionType: foo
415+
status:
416+
conditions:
417+
- type: foo
418+
status: "True"
419+
reason: reason
420+
message: message
421+
`,
422+
updateUpstream: false,
423+
expected: `
424+
apiVersion: kpt.dev/v1
425+
kind: Kptfile
426+
metadata:
427+
name: foo
428+
info:
429+
readinessGates:
430+
- conditionType: foo
431+
- conditionType: bar
432+
status:
433+
conditions:
434+
- type: foo
435+
status: "True"
436+
reason: reason
437+
message: message
438+
- type: bar
439+
status: "False"
440+
reason: reason
441+
message: message
442+
`,
443+
},
444+
"readinessGate added removed in upstream": {
445+
origin: `
446+
apiVersion: kpt.dev/v1
447+
kind: Kptfile
448+
metadata:
449+
name: foo
450+
info:
451+
readinessGates:
452+
- conditionType: foo
453+
status:
454+
conditions:
455+
- type: foo
456+
status: "True"
457+
reason: reason
458+
message: message
459+
`,
460+
updated: `
461+
apiVersion: kpt.dev/v1
462+
kind: Kptfile
463+
metadata:
464+
name: foo
465+
`,
466+
local: `
467+
apiVersion: kpt.dev/v1
468+
kind: Kptfile
469+
metadata:
470+
name: foo
471+
info:
472+
readinessGates:
473+
- conditionType: foo
474+
status:
475+
conditions:
476+
- type: foo
477+
status: "True"
478+
reason: reason
479+
message: message
480+
`,
481+
updateUpstream: false,
482+
expected: `
483+
apiVersion: kpt.dev/v1
484+
kind: Kptfile
485+
metadata:
486+
name: foo
487+
info: {}
488+
status: {}
489+
`,
490+
},
491+
"readinessGates removed and added in both upstream and local": {
492+
origin: `
493+
apiVersion: kpt.dev/v1
494+
kind: Kptfile
495+
metadata:
496+
name: foo
497+
info:
498+
readinessGates:
499+
- conditionType: foo
500+
- conditionType: bar
501+
status:
502+
conditions:
503+
- type: foo
504+
status: "True"
505+
reason: reason
506+
message: message
507+
- type: bar
508+
status: "False"
509+
reason: reason
510+
message: message
511+
`,
512+
updated: `
513+
apiVersion: kpt.dev/v1
514+
kind: Kptfile
515+
metadata:
516+
name: foo
517+
info:
518+
readinessGates:
519+
- conditionType: foo
520+
- conditionType: zork
521+
status:
522+
conditions:
523+
- type: foo
524+
status: "True"
525+
reason: reason
526+
message: message
527+
- type: zork
528+
status: "Unknown"
529+
reason: reason
530+
message: message
531+
`,
532+
local: `
533+
apiVersion: kpt.dev/v1
534+
kind: Kptfile
535+
metadata:
536+
name: foo
537+
info:
538+
readinessGates:
539+
- conditionType: xandar
540+
- conditionType: foo
541+
status:
542+
conditions:
543+
- type: xandar
544+
status: "True"
545+
reason: reason
546+
message: message
547+
- type: foo
548+
status: "True"
549+
reason: reason
550+
message: message
551+
`,
552+
updateUpstream: false,
553+
expected: `
554+
apiVersion: kpt.dev/v1
555+
kind: Kptfile
556+
metadata:
557+
name: foo
558+
info:
559+
readinessGates:
560+
- conditionType: foo
561+
- conditionType: zork
562+
status:
563+
conditions:
564+
- type: foo
565+
status: "True"
566+
reason: reason
567+
message: message
568+
- type: zork
569+
status: Unknown
570+
reason: reason
571+
message: message
324572
`,
325573
},
326574
}

0 commit comments

Comments
 (0)