Skip to content

Commit

Permalink
Upgrade Kanister CRDs to v1 from v1beta1 (#927)
Browse files Browse the repository at this point in the history
* Add CRDs generated by kubebuilder

We tried to use kubebuilder to generate the CRDs for
go types but that is also not able to process some of
the types, for example `BlueprintPhase.Args`, `Phase.Output`
becauaes of `interface{}` and `Blueprint.Actions` because of
pointer type value.

* Correct CRDs

* Have CRDs in the go source files as strings

* Remove `phases.output` from required fields

* Resolve import cycle, refactor PR

- Remove required fields from CRDs
- Move CR resource names to consts package to resolve import cycle issue
- Remove un-nec logging

* Fix integration test failure by changing types.go

Even though e2e tests were running on my local cluster
tests were failing on the kanister CI, and the reason
was, when we read blueprint to create blueprint type
if a field is not specified in the blueprint, we initialized
the type with null for that field and in that case CRD validation
failed.
This commit tries to fix that by settign `omitemtpy` for those
fields.

I am thinking if we should add `omitempty` for every field in
types.go

* Fix unit tests by adding omitemtpy in types.go

* Change actionset CRD to have kopiaSnapshot field

* Change kopiaSnapshot type to string in actionset crd

* Fix integration test failure

* Fix controller unit test by adding `KopiaSnapshot` in actionset status

* Fix resource unit test failure

In the test `ResourceSuite.TestBlueprintClient` we tried to
create blueprint with empty actions struct and then tried
to make sure that we are able to update the blueprint. And
checked actions after update that its not nil.
Since we are omitting empty field we are not going to get
actions if we pass empty actions, that why I have changed
the action to have some values.

* Remove un nec CRD manifest

* Update CRDs if CRDs are already present in the cluster

Per current implementation we were not silently ignoring the
error if the CRDs are already present in the cluster.
Since we are significantly changing the CRD that wouldn't
work for, so this PR updates the CRDs if they are already
avaialable.

* Address review comments

* Correct permissions of controller Dockerfile

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] committed Jun 25, 2021
1 parent f33c70c commit ea5ff6a
Show file tree
Hide file tree
Showing 10 changed files with 579 additions and 75 deletions.
21 changes: 11 additions & 10 deletions pkg/apis/cr/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ package v1alpha1
import (
"reflect"

apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/kanisterio/kanister/pkg/consts"
customresource "github.com/kanisterio/kanister/pkg/customresource"
)

Expand All @@ -37,31 +38,31 @@ var (

// ActionSetResource is a CRD for actionsets.
var ActionSetResource = customresource.CustomResource{
Name: ActionSetResourceName,
Plural: ActionSetResourceNamePlural,
Name: consts.ActionSetResourceName,
Plural: consts.ActionSetResourceNamePlural,
Group: ResourceGroup,
Version: SchemeVersion,
Scope: apiextensionsv1beta1.NamespaceScoped,
Scope: apiextensionsv1.NamespaceScoped,
Kind: reflect.TypeOf(ActionSet{}).Name(),
}

// BlueprintResource is a CRD for blueprints.
var BlueprintResource = customresource.CustomResource{
Name: BlueprintResourceName,
Plural: BlueprintResourceNamePlural,
Name: consts.BlueprintResourceName,
Plural: consts.BlueprintResourceNamePlural,
Group: ResourceGroup,
Version: SchemeVersion,
Scope: apiextensionsv1beta1.NamespaceScoped,
Scope: apiextensionsv1.NamespaceScoped,
Kind: reflect.TypeOf(Blueprint{}).Name(),
}

// ProfileResource is a CRD for blueprints.
var ProfileResource = customresource.CustomResource{
Name: ProfileResourceName,
Plural: ProfileResourceNamePlural,
Name: consts.ProfileResourceName,
Plural: consts.ProfileResourceNamePlural,
Group: ResourceGroup,
Version: SchemeVersion,
Scope: apiextensionsv1beta1.NamespaceScoped,
Scope: apiextensionsv1.NamespaceScoped,
Kind: reflect.TypeOf(Profile{}).Name(),
}

Expand Down
56 changes: 19 additions & 37 deletions pkg/apis/cr/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const (
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: ResourceGroup, Version: SchemeVersion}

// These names are used to query ActionSet API objects.
const (
ActionSetResourceName = "actionset"
ActionSetResourceNamePlural = "actionsets"
)

// JSONMap contains PodOverride specs.
type JSONMap sp.JSONMap

Expand All @@ -57,7 +51,7 @@ var _ runtime.Object = (*ActionSet)(nil)
type ActionSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec *ActionSetSpec `json:"spec"`
Spec *ActionSetSpec `json:"spec,omitempty"`
Status *ActionSetStatus `json:"status,omitempty"`
}

Expand All @@ -82,7 +76,7 @@ type ObjectReference struct {

// ActionSetSpec is the specification for the actionset.
type ActionSetSpec struct {
Actions []ActionSpec `json:"actions"`
Actions []ActionSpec `json:"actions,omitempty"`
}

// ActionSpec is the specification for a single Action.
Expand All @@ -96,18 +90,18 @@ type ActionSpec struct {
// Artifacts will be passed as inputs into this phase.
Artifacts map[string]Artifact `json:"artifacts,omitempty"`
// ConfigMaps that we'll get and pass into the blueprint.
ConfigMaps map[string]ObjectReference `json:"configMaps"`
ConfigMaps map[string]ObjectReference `json:"configMaps,omitempty"`
// Secrets that we'll get and pass into the blueprint.
Secrets map[string]ObjectReference `json:"secrets"`
Secrets map[string]ObjectReference `json:"secrets,omitempty"`
// Profile is use to specify the location where store artifacts and the
// credentials authorized to access them.
Profile *ObjectReference `json:"profile"`
Profile *ObjectReference `json:"profile,omitempty"`
// PodOverride is used to specify pod specs that will override the
// default pod specs
PodOverride JSONMap `json:"podOverride,omitempty"`
// Options will be used to specify additional values
// to be used in the Blueprint.
Options map[string]string `json:"options"`
Options map[string]string `json:"options,omitempty"`
// PreferredVersion will be used to select the preferred version of Kanister functions
// to be executed for this action
PreferredVersion string `json:"preferredVersion"`
Expand All @@ -116,7 +110,7 @@ type ActionSpec struct {
// ActionSetStatus is the status for the actionset. This should only be updated by the controller.
type ActionSetStatus struct {
State State `json:"state"`
Actions []ActionStatus `json:"actions"`
Actions []ActionStatus `json:"actions,omitempty"`
Error Error `json:"error,omitempty"`
}

Expand All @@ -129,9 +123,9 @@ type ActionStatus struct {
// Blueprint with instructions on how to execute this action.
Blueprint string `json:"blueprint"`
// Phases are sub-actions an are executed sequentially.
Phases []Phase `json:"phases"`
Phases []Phase `json:"phases,omitempty"`
// Artifacts created by this phase.
Artifacts map[string]Artifact `json:"artifacts"`
Artifacts map[string]Artifact `json:"artifacts,omitempty"`
}

// State is the current state of a phase of execution.
Expand All @@ -156,17 +150,17 @@ type Error struct {
type Phase struct {
Name string `json:"name"`
State State `json:"state"`
Output map[string]interface{} `json:"output"`
Output map[string]interface{} `json:"output,omitempty"`
}

// k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Artifact tracks objects produced by an action.
type Artifact struct {
KeyValue map[string]string `json:"keyValue"`
KeyValue map[string]string `json:"keyValue,omitempty"`
// KopiaSnapshot captures the kopia snapshot information
// produced as a JSON string by kando command in phases of an action.
KopiaSnapshot string `json:"kopiaSnapshot"`
KopiaSnapshot string `json:"kopiaSnapshot,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -178,12 +172,6 @@ type ActionSetList struct {
Items []*ActionSet `json:"items"`
}

// These names are used to query Blueprint API objects.
const (
BlueprintResourceName = "blueprint"
BlueprintResourceNamePlural = "blueprints"
)

var _ runtime.Object = (*Blueprint)(nil)

// +genclient
Expand All @@ -194,25 +182,25 @@ var _ runtime.Object = (*Blueprint)(nil)
type Blueprint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Actions map[string]*BlueprintAction `json:"actions"`
Actions map[string]*BlueprintAction `json:"actions,omitempty"`
}

// BlueprintAction describes the set of phases that constitute an action.
type BlueprintAction struct {
Name string `json:"name"`
Kind string `json:"kind"`
ConfigMapNames []string `json:"configMapNames"`
SecretNames []string `json:"secretNames"`
InputArtifactNames []string `json:"inputArtifactNames"`
OutputArtifacts map[string]Artifact `json:"outputArtifacts"`
Phases []BlueprintPhase `json:"phases"`
ConfigMapNames []string `json:"configMapNames,omitempty"`
SecretNames []string `json:"secretNames,omitempty"`
InputArtifactNames []string `json:"inputArtifactNames,omitempty"`
OutputArtifacts map[string]Artifact `json:"outputArtifacts,omitempty"`
Phases []BlueprintPhase `json:"phases,omitempty"`
}

// BlueprintPhase is a an individual unit of execution.
type BlueprintPhase struct {
Func string `json:"func"`
Name string `json:"name"`
ObjectRefs map[string]ObjectReference `json:"objects"`
ObjectRefs map[string]ObjectReference `json:"objects,omitempty"`
Args map[string]interface{} `json:"args"`
}

Expand All @@ -225,12 +213,6 @@ type BlueprintList struct {
Items []*Blueprint `json:"items"`
}

// These names are used to query Profile API objects.
const (
ProfileResourceName = "profile"
ProfileResourceNamePlural = "profiles"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
10 changes: 10 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ const (
LabelKeyCreatedBy = "createdBy"
LabelValueKanister = "kanister"
)

// These names are used to query ActionSet API objects.
const (
ActionSetResourceName = "actionset"
ActionSetResourceNamePlural = "actionsets"
BlueprintResourceName = "blueprint"
BlueprintResourceNamePlural = "blueprints"
ProfileResourceName = "profile"
ProfileResourceNamePlural = "profiles"
)
Loading

0 comments on commit ea5ff6a

Please sign in to comment.