Skip to content
Open
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
35 changes: 35 additions & 0 deletions examples/open-component-model/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: ocm-cli-demo
spec:
components:
- name: ocm-cli
type: ocm-component
properties:
repository:
type: OCIRegistry
baseUrl: ghcr.io/open-component-model
component: ocm.software/cli
semver: 0.23.0
- name: ocm-cli-image
type: ocm-resource
dependsOn: [ocm-cli]
properties:
componentRef: ocm-cli
resource:
name: image
additionalStatusFields:
image: resource.access.imageReference
outputs:
- name: image
valueFrom: output.status.additional.image
- name: ocm-version
type: task
dependsOn: [ocm-cli-image]
inputs:
- from: image
parameterKey: image
properties:
image: placeholder
cmd: ["/ocm", "version"]
88 changes: 88 additions & 0 deletions experimental/addons/open-component-model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# open-component-model

[Open Component Model (OCM)](https://ocm.software) packages software as signed, location-independent component versions.
This addon installs the [OCM controller](https://github.com/open-component-model/open-component-model/tree/main/bindings/go/kubernetes/controller),
which resolves, verifies and replicates component versions in the cluster. KubeVela then orchestrates the delivered resources.

Not to be confused with the `ocm-cluster-manager` addon, which is Open Cluster Management.

## Install

```shell
vela addon registry add experimental --type helm --endpoint=https://kubevela.github.io/catalog/experimental
vela addon enable experimental/open-component-model
```

Install into a different namespace:

```shell
vela addon enable experimental/open-component-model namespace=my-ocm
```

## Usage

The addon provides two component types:

- `ocm-component` resolves a component version from an OCM repository.
- `ocm-resource` resolves and verifies one resource of that component version.
`additionalStatusFields` publishes values from the resource under `status.additional`, so other components can consume them.

This application ([examples/open-component-model/app.yaml](../../../examples/open-component-model/app.yaml)) resolves the published OCM CLI component and runs its image as a job.
The job's `image` comes from the verified, digest-pinned reference in the component version.

```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: ocm-cli-demo
spec:
components:
- name: ocm-cli
type: ocm-component
properties:
repository:
type: OCIRegistry
baseUrl: ghcr.io/open-component-model
component: ocm.software/cli
semver: 0.23.0
- name: ocm-cli-image
type: ocm-resource
dependsOn: [ocm-cli]
properties:
componentRef: ocm-cli
resource:
name: image
additionalStatusFields:
image: resource.access.imageReference
outputs:
- name: image
valueFrom: output.status.additional.image
- name: ocm-version
type: task
dependsOn: [ocm-cli-image]
inputs:
- from: image
parameterKey: image
properties:
image: placeholder
cmd: ["/ocm", "version"]
```

```shell
$ vela status ocm-cli-demo
...
- Name: ocm-cli-image
Type: ocm-resource
Health: ✅
Message: image from ocm.software/cli:0.23.0
...
$ kubectl logs job/ocm-cli-demo-ocm-version
OCM CLI (Open Component Model v2)
Version: 0.23.0
```

Use `vela show ocm-component` and `vela show ocm-resource` for all parameters.

## Requirements

KubeVela v1.11.0 or later, for the native `helmchart` component.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"ocm-component": {
type: "component"
description: "Resolves an OCM component version from an OCM repository."
labels: {}
annotations: {}
attributes: {
workload: type: "autodetects.core.oam.dev"
status: {
healthPolicy: #"""
_ready: [ for o in [context.output, context.outputs.repository] {
*false | bool
if o.status.conditions != _|_ {
len([ for c in o.status.conditions if c.type == "Ready" && c.status == "True" {c}]) > 0
}
}]
isHealth: len([ for r in _ready if !r {r}]) == 0
"""#
customStatus: #"""
message: *"Resolving" | string
if context.output.status.component.version != _|_ {
message: context.output.status.component.component + ":" + context.output.status.component.version
}
"""#
}
}
}

template: {
output: {
apiVersion: "delivery.ocm.software/v1alpha1"
kind: "Component"
metadata: name: context.name
spec: {
repositoryRef: name: context.name
component: parameter.component
semver: parameter.semver
downgradePolicy: parameter.downgradePolicy
interval: parameter.interval
if parameter.semverFilter != _|_ {
semverFilter: parameter.semverFilter
}
if parameter.ocmConfig != _|_ {
ocmConfig: parameter.ocmConfig
}
}
}

outputs: repository: {
apiVersion: "delivery.ocm.software/v1alpha1"
kind: "Repository"
metadata: name: context.name
spec: {
repositorySpec: parameter.repository
interval: parameter.interval
if parameter.ocmConfig != _|_ {
ocmConfig: parameter.ocmConfig
}
}
}

parameter: {
// +usage=The OCM repository specification, for example {type: "OCIRegistry", baseUrl: "ghcr.io/my-org"}
repository: {...}
// +usage=The name of the OCM component, for example "ocm.software/my-app"
component: string
// +usage=The semver constraint the component version must match, for example ">=1.0.0"
semver: string
// +usage=A regex that further filters the versions matching the semver constraint
semverFilter?: string
// +usage=Whether the component may be downgraded to a lower version
downgradePolicy: *"Deny" | "Allow"
// +usage=How often the repository is checked for new component versions
interval: *"10m" | string
// +usage=References to objects that can provide ocm configuration data to the referring object. These can be secrets, config maps, or other OCM objects that have configuration to propagate.
ocmConfig?: [...{
kind: "Secret" | "ConfigMap" | "Repository" | "Component" | "Resource"
name: string
apiVersion?: string
namespace?: string
policy?: *"Propagate" | "DoNotPropagate"
}]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"ocm-resource": {
type: "component"
description: "Resolves and verifies a resource of an OCM component version resolved by an ocm-component."
labels: {}
annotations: {}
attributes: {
workload: type: "autodetects.core.oam.dev"
status: {
healthPolicy: #"""
isHealth: *false | bool
if context.output.status.conditions != _|_ {
isHealth: len([ for c in context.output.status.conditions if c.type == "Ready" && c.status == "True" {c}]) > 0
}
"""#
customStatus: #"""
message: *"Resolving" | string
if context.output.status.resource.name != _|_ && context.output.status.component.version != _|_ {
message: context.output.status.resource.name + " from " + context.output.status.component.component + ":" + context.output.status.component.version
}
"""#
}
}
}

template: {
output: {
apiVersion: "delivery.ocm.software/v1alpha1"
kind: "Resource"
metadata: name: context.name
spec: {
componentRef: name: parameter.componentRef
resource: byReference: {
resource: parameter.resource
if parameter.referencePath != _|_ {
referencePath: parameter.referencePath
}
}
verificationPolicy: parameter.verificationPolicy
if parameter.additionalStatusFields != _|_ {
additionalStatusFields: parameter.additionalStatusFields
}
if parameter.ocmConfig != _|_ {
ocmConfig: parameter.ocmConfig
}
}
}

parameter: {
// +usage=The name of the ocm-component in this application that resolves the component version
componentRef: string
// +usage=The identity of the resource in the component version, for example {name: "chart"}
resource: {
name: string
[string]: string
}
// +usage=Identities of component references to follow to reach the resource
referencePath?: [...{[string]: string}]
// +usage=Whether to verify the resource digest
verificationPolicy: *"Always" | "Never"
// +usage=CEL expressions evaluated against the resource, published under status.additional, for example {image: "resource.access.imageReference"}
additionalStatusFields?: {...}
Comment thread
Skarlso marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with your reply to cubic, the CRD takes free JSON. If you fancy it, [string]: string matches how it's used (CEL strings) and gives VelaUX a nicer form. Not a blocker.

// +usage=References to objects that can provide ocm configuration data to the referring object. These can be secrets, config maps, or other OCM objects that have configuration to propagate.
Comment thread
Skarlso marked this conversation as resolved.
Resolved
ocmConfig?: [...{
kind: "Secret" | "ConfigMap" | "Repository" | "Component" | "Resource"
Comment thread
Skarlso marked this conversation as resolved.
Resolved
name: string
apiVersion?: string
namespace?: string
policy?: *"Propagate" | "DoNotPropagate"
}]
}
}
16 changes: 16 additions & 0 deletions experimental/addons/open-component-model/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: open-component-model
version: 0.1.0
description: Deliver Open Component Model (OCM) component versions to KubeVela applications.
icon: https://raw.githubusercontent.com/open-component-model/open-component-model/main/website/assets/logo-image.png
url: https://ocm.software

tags:
- experimental
- Delivery

deployTo:
controlPlane: true
runtimeCluster: false

system:
vela: ">=v1.11.0"
10 changes: 10 additions & 0 deletions experimental/addons/open-component-model/parameter.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameter: {
// +usage=The namespace to install the OCM controller into
namespace: *"ocm-system" | string
// +usage=Helm values for the OCM controller chart. fullnameOverride is fixed to "ocm-k8s-toolkit".
values?: {
// The addon health check looks the controller Deployment up by this name.
fullnameOverride?: "ocm-k8s-toolkit"
...
}
Comment on lines +5 to +9

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On KubeVela 1.11 the addon loader generates an OpenAPI schema from this file before enabling, and the encoder fails on error(), so vela addon enable stops with fail to generate openAPIschema. How about forcing the name rather than rejecting the field? Something like:

values?: {
	// The addon health check looks the controller Deployment up by this name.
	fullnameOverride?: "ocm-k8s-toolkit"
	...
}

With fullnameOverride always set (see controller.cue), the Deployment is ocm-k8s-toolkit-controller-manager whatever nameOverride says, so that one can go through.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

ocmController: {
name: "ocm-controller"
type: "helmchart"
properties: {
chart: {
source: "oci://ghcr.io/open-component-model/kubernetes/controller/chart"
version: "0.23.0"
}
release: {
name: "ocm-k8s-toolkit"
namespace: parameter.namespace
}
values: {
if parameter.values != _|_ {
parameter.values
}
fullnameOverride: "ocm-k8s-toolkit"
}
// KubeVela 1.11's helmchart health check needs the resource name; fullnameOverride is fixed so this one is stable.
healthStatus: [{
resource: {
kind: "Deployment"
name: "ocm-k8s-toolkit-controller-manager"
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
}
condition: type: "Available"
}]
}
}
10 changes: 10 additions & 0 deletions experimental/addons/open-component-model/template.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

output: {
apiVersion: "core.oam.dev/v1beta1"
kind: "Application"
spec: {
components: [ocmController]
policies: []
}
}
Loading