Skip to content

Commit

Permalink
Package conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Oct 13, 2022
1 parent a727de1 commit 1e5a45b
Show file tree
Hide file tree
Showing 25 changed files with 1,197 additions and 95 deletions.
30 changes: 30 additions & 0 deletions pkg/api/kptfile/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type KptFile struct {

// Inventory contains parameters for the inventory object used in apply.
Inventory *Inventory `yaml:"inventory,omitempty" json:"inventory,omitempty"`

Status *Status `yaml:"status,omitempty" json:"status,omitempty"`
}

// OriginType defines the type of origin for a package.
Expand Down Expand Up @@ -192,6 +194,12 @@ type PackageInfo struct {

// Man is the path to documentation about the package
Man string `yaml:"man,omitempty" json:"man,omitempty"`

ReadinessGates []ReadinessGate `yaml:"readinessGates,omitempty" json:"readinessGates,omitempty"`
}

type ReadinessGate struct {
ConditionType string `yaml:"conditionType" json:"conditionType"`
}

// Subpackages declares a local or remote subpackage.
Expand Down Expand Up @@ -341,3 +349,25 @@ func (i Inventory) IsValid() bool {
// Name, Namespace InventoryID are required inventory fields, so we check these 3 fields.
return i.Name != "" && i.Namespace != "" && i.InventoryID != ""
}

type Status struct {
Conditions []Condition `yaml:"conditions,omitempty" json:"conditions,omitempty"`
}

type Condition struct {
Type string `yaml:"type" json:"type"`

Status ConditionStatus `yaml:"status" json:"status"`

Reason string `yaml:"reason,omitempty" json:"reason,omitempty"`

Message string `yaml:"message,omitempty" json:"message,omitempty"`
}

type ConditionStatus string

const (
ConditionTrue ConditionStatus = "True"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"
)
1 change: 1 addition & 0 deletions pkg/kptfile/kptfileutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func merge(localKf, updatedKf, originalKf *kptfilev1.KptFile) error {
localKf.Info = mergedKf.Info
localKf.Pipeline = mergedKf.Pipeline
localKf.Inventory = mergedKf.Inventory
localKf.Status = mergedKf.Status
return nil
}

Expand Down
248 changes: 248 additions & 0 deletions pkg/kptfile/kptfileutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,254 @@ kind: Kptfile
metadata:
name: foo
pipeline: {}
`,
},
"first readinessGate and condition added in upstream": {
origin: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
`,
updated: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
local: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
`,
updateUpstream: false,
expected: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
},
"additional readinessGate and condition added in upstream": {
origin: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
updated: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
- conditionType: bar
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
- type: bar
status: "False"
reason: reason
message: message
`,
local: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
updateUpstream: false,
expected: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
- conditionType: bar
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
- type: bar
status: "False"
reason: reason
message: message
`,
},
"readinessGate added removed in upstream": {
origin: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
updated: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
`,
local: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
`,
updateUpstream: false,
expected: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info: {}
status: {}
`,
},
"readinessGates removed and added in both upstream and local": {
origin: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
- conditionType: bar
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
- type: bar
status: "False"
reason: reason
message: message
`,
updated: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
- conditionType: zork
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
- type: zork
status: "Unknown"
reason: reason
message: message
`,
local: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: xandar
- conditionType: foo
status:
conditions:
- type: xandar
status: "True"
reason: reason
message: message
- type: foo
status: "True"
reason: reason
message: message
`,
updateUpstream: false,
expected: `
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: foo
info:
readinessGates:
- conditionType: foo
- conditionType: zork
status:
conditions:
- type: foo
status: "True"
reason: reason
message: message
- type: zork
status: Unknown
reason: reason
message: message
`,
},
}
Expand Down
14 changes: 7 additions & 7 deletions porch/api/generated/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions porch/api/generated/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e5a45b

Please sign in to comment.