Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package conditions #3614

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading