Skip to content

Commit

Permalink
Add KudoOperator task types (#1515)
Browse files Browse the repository at this point in the history
to help parallelize upcoming work on KEP-29.

Signed-off-by: Aleksey Dukhovniy alex.dukhovniy@googlemail.com

Fixes: #1509
  • Loading branch information
Aleksey Dukhovniy committed May 15, 2020
1 parent 5a4cdc5 commit f3183ae
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 299 deletions.
64 changes: 14 additions & 50 deletions config/crds/kudo.dev_operatorversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
dependencies:
description: Dependencies a list of all dependencies of the operator.
items:
description: OperatorDependency references a defined operator.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of
an entire object, this string should contain a valid JSON/Go
field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part of
an object. TODO: this design is not final and this field is
subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
referenceName:
description: Name specifies the name of the dependency. Referenced
via defaults.config.
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
version:
description: "Version captures the requirements for what versions
of the above object are allowed. \n Example: ^3.1.4"
type: string
required:
- referenceName
- version
type: object
type: array
operator:
description: ObjectReference contains enough information to let you
inspect or modify the referred object.
Expand Down Expand Up @@ -223,10 +173,24 @@ spec:
parser. We might revisit this approach in the future should
this become an issue.
properties:
appVersion:
description: a specific app version in the official repo,
defaults to the most recent
type: string
done:
type: boolean
fatal:
type: boolean
instanceName:
type: string
operatorVersion:
description: a specific operator version in the official repo,
defaults to the most recent one
type: string
package:
description: either repo package name, local package folder
or an URL to package tarball
type: string
parameter:
type: string
pipe:
Expand Down
2 changes: 1 addition & 1 deletion keps/0029-operator-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The `zookeeper-operator` task specification is equivalent to `kudo install zooke
```yaml
tasks:
- name: demo
kind: Operator
kind: KudoOperator
spec:
package: # required, either repo package name, local package folder or an URL to package tarball
appVersion: # optional, a specific app version in the official repo, defaults to the most recent one
Expand Down
40 changes: 20 additions & 20 deletions pkg/apis/kudo/v1beta1/operatorversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ type OperatorVersionSpec struct {
// +optional
ConnectionString string `json:"connectionString,omitempty"`

// Dependencies a list of all dependencies of the operator.
Dependencies []OperatorDependency `json:"dependencies,omitempty"`

// UpgradableFrom lists all OperatorVersions that can upgrade to this OperatorVersion.
UpgradableFrom []corev1.ObjectReference `json:"upgradableFrom,omitempty"`
}
Expand Down Expand Up @@ -149,10 +146,11 @@ type Task struct {
// with the same json names as it would become ambiguous for the default parser. We might revisit this approach in the
// future should this become an issue.
type TaskSpec struct {
ResourceTaskSpec `json:",inline"`
DummyTaskSpec `json:",inline"`
PipeTaskSpec `json:",inline"`
ToggleTaskSpec `json:",inline"`
ResourceTaskSpec `json:",inline"`
DummyTaskSpec `json:",inline"`
PipeTaskSpec `json:",inline"`
ToggleTaskSpec `json:",inline"`
KudoOperatorTaskSpec `json:",inline"`
}

// ResourceTaskSpec is referencing a list of resources
Expand Down Expand Up @@ -199,6 +197,21 @@ type PipeSpec struct {
Key string `json:"key"`
}

// KudoOperatorSpec specifies how a KUDO operator is installed
type KudoOperatorTaskSpec struct {
// either repo package name, local package folder or an URL to package tarball
// +optional
Package string `json:"package,omitempty"`
// +optional
InstanceName string `json:"instanceName,omitempty"`
// a specific app version in the official repo, defaults to the most recent
// +optional
AppVersion string `json:"appVersion,omitempty"`
// a specific operator version in the official repo, defaults to the most recent one
// +optional
OperatorVersion string `json:"operatorVersion,omitempty"`
}

// OperatorVersionStatus defines the observed state of OperatorVersion.
type OperatorVersionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down Expand Up @@ -230,16 +243,3 @@ type OperatorVersionList struct {
func init() {
SchemeBuilder.Register(&OperatorVersion{}, &OperatorVersionList{})
}

// OperatorDependency references a defined operator.
type OperatorDependency struct {
// Name specifies the name of the dependency. Referenced via defaults.config.
ReferenceName string `json:"referenceName"`
corev1.ObjectReference `json:",inline"`

// Version captures the requirements for what versions of the above object
// are allowed.
//
// Example: ^3.1.4
Version string `json:"version"`
}
39 changes: 17 additions & 22 deletions pkg/apis/kudo/v1beta1/zz_generated.deepcopy.go

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

28 changes: 23 additions & 5 deletions pkg/engine/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ type Tasker interface {

// Available tasks kinds
const (
ApplyTaskKind = "Apply"
DeleteTaskKind = "Delete"
DummyTaskKind = "Dummy"
PipeTaskKind = "Pipe"
ToggleTaskKind = "Toggle"
ApplyTaskKind = "Apply"
DeleteTaskKind = "Delete"
DummyTaskKind = "Dummy"
PipeTaskKind = "Pipe"
ToggleTaskKind = "Toggle"
KudoOperatorTaskKind = "KudoOperator"
)

var (
Expand All @@ -69,6 +70,8 @@ func Build(task *v1beta1.Task) (Tasker, error) {
return newPipe(task)
case ToggleTaskKind:
return newToggle(task)
case KudoOperatorTaskKind:
return newKudoOperator(task)
default:
return nil, fmt.Errorf("unknown task kind %s", task.Kind)
}
Expand Down Expand Up @@ -181,3 +184,18 @@ func fatalExecutionError(cause error, eventName string, meta renderer.Metadata)
EventName: eventName,
}
}

func newKudoOperator(task *v1beta1.Task) (Tasker, error) {
// validate KudoOperatorTask
if len(task.Spec.KudoOperatorTaskSpec.Package) == 0 {
return nil, fmt.Errorf("task validation error: kudo operator task '%s' has an empty package name", task.Name)
}

return KudoOperatorTask{
Name: task.Name,
Package: task.Spec.KudoOperatorTaskSpec.Package,
InstanceName: task.Spec.KudoOperatorTaskSpec.InstanceName,
AppVersion: task.Spec.KudoOperatorTaskSpec.AppVersion,
OperatorVersion: task.Spec.KudoOperatorTaskSpec.OperatorVersion,
}, nil
}
19 changes: 19 additions & 0 deletions pkg/engine/task/task_kudo_operator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package task

import (
"errors"
)

// KudoOperatorTask installs an instance of a KUDO operator in a cluster
type KudoOperatorTask struct {
Name string
Package string
InstanceName string
AppVersion string
OperatorVersion string
}

// Run method for the KudoOperatorTask. Not yet implemented
func (dt KudoOperatorTask) Run(ctx Context) (bool, error) {
return false, errors.New("kudo-operator task is not yet implemented. Stay tuned though ;)")
}
19 changes: 19 additions & 0 deletions pkg/engine/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ spec:
want: nil,
wantErr: true,
},
{
name: "kudo-operator task",
taskYaml: `
name: deploy-zk
kind: KudoOperator
spec:
package: zookeeper
appVersion: 0.0.3
operatorVersion: 0.0.4
instanceName: zk`,
want: KudoOperatorTask{
Name: "deploy-zk",
Package: "zookeeper",
AppVersion: "0.0.3",
OperatorVersion: "0.0.4",
InstanceName: "zk",
},
wantErr: false,
},
{
name: "unknown task",
taskYaml: `
Expand Down
64 changes: 14 additions & 50 deletions pkg/kudoctl/cmd/testdata/deploy-kudo-ns.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -112,56 +112,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
dependencies:
description: Dependencies a list of all dependencies of the operator.
items:
description: OperatorDependency references a defined operator.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of
an entire object, this string should contain a valid JSON/Go
field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part of
an object. TODO: this design is not final and this field is
subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
referenceName:
description: Name specifies the name of the dependency. Referenced
via defaults.config.
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
version:
description: "Version captures the requirements for what versions
of the above object are allowed. \n Example: ^3.1.4"
type: string
required:
- referenceName
- version
type: object
type: array
operator:
description: ObjectReference contains enough information to let you
inspect or modify the referred object.
Expand Down Expand Up @@ -295,10 +245,24 @@ spec:
parser. We might revisit this approach in the future should
this become an issue.
properties:
appVersion:
description: a specific app version in the official repo,
defaults to the most recent
type: string
done:
type: boolean
fatal:
type: boolean
instanceName:
type: string
operatorVersion:
description: a specific operator version in the official repo,
defaults to the most recent one
type: string
package:
description: either repo package name, local package folder
or an URL to package tarball
type: string
parameter:
type: string
pipe:
Expand Down
Loading

0 comments on commit f3183ae

Please sign in to comment.