Skip to content

Commit

Permalink
Allow using different charts and/or deploy different Dapr versions #46
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Burgazzoli <[email protected]>
  • Loading branch information
lburgazzoli committed Nov 14, 2023
1 parent 9c9cda7 commit be3f791
Show file tree
Hide file tree
Showing 94 changed files with 5,118 additions and 720 deletions.
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ test: manifests generate fmt vet ## Run tests.

.PHONY: test/e2e/operator
test/e2e/operator: manifests generate fmt vet ## Run e2e operator tests.
go test -ldflags="$(GOLDFLAGS)" -v ./test/e2e/operator/...
go test -ldflags="$(GOLDFLAGS)" -p 1 -v ./test/e2e/operator/...

.PHONY: test/e2e/olm
test/e2e/olm: ## Run e2e catalog tests.
go test -ldflags="$(GOLDFLAGS)" -v ./test/e2e/olm/...
go test -ldflags="$(GOLDFLAGS)" -p 1 -v ./test/e2e/olm/...

##@ Build

Expand All @@ -135,11 +135,19 @@ build: manifests generate fmt vet ## Build manager binary.

.PHONY: run
run: ## Run a controller from your host.
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run --leader-election=false --zap-devel
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run \
--leader-election=false \
--zap-devel \
--health-probe-bind-address ":0" \
--metrics-bind-address ":0"

.PHONY: run/local
run/local: install ## Install and Run a controller from your host.
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run --leader-election=false --zap-devel
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run \
--leader-election=false \
--zap-devel \
--health-probe-bind-address ":0" \
--metrics-bind-address ":0"


.PHONY: deps
Expand Down
16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ resources:
kind: DaprControlPlane
path: github.com/dapr-sandbox/dapr-kubernetes-operator/api/operator/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: dapr.io
group: operator
kind: DaprInstance
path: github.com/dapr-sandbox/dapr-kubernetes-operator/api/operator/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: dapr.io
group: operator
kind: DaprCruiseControl
path: github.com/dapr-sandbox/dapr-kubernetes-operator/api/operator/v1alpha1
version: v1alpha1
version: "3"
17 changes: 17 additions & 0 deletions api/operator/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ func (m *RawMessage) String() string {

var _ json.Marshaler = (*RawMessage)(nil)
var _ json.Unmarshaler = (*RawMessage)(nil)

type ChartSpec struct {
// +kubebuilder:default:="https://dapr.github.io/helm-charts"
Repo string `json:"repo,omitempty"`

// +kubebuilder:default:="dapr"
Name string `json:"name,omitempty"`

// +kubebuilder:validation:Optional
Version string `json:"version,omitempty"`
}

type ChartMeta struct {
Repo string `json:"repo,omitempty"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
}
13 changes: 5 additions & 8 deletions api/operator/v1alpha1/dapr_control_plane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

type DaprControlPlaneSpec struct {
Expand All @@ -30,6 +29,7 @@ type DaprControlPlaneStatus struct {
Phase string `json:"phase"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Chart *ChartMeta `json:"chart,omitempty"`
}

// +genclient
Expand All @@ -39,9 +39,10 @@ type DaprControlPlaneStatus struct {
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The phase"
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="Reason"
// +kubebuilder:printcolumn:name="Reconciled",type=string,JSONPath=`.status.conditions[?(@.type=="Reconcile")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reconciled Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Reconcile")].reason`,description="Reason"
// +kubebuilder:printcolumn:name="Reconciled",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reconciled Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].reason`,description="Reason"
// +kubebuilder:resource:path=daprcontrolplanes,scope=Namespaced,shortName=dcp,categories=dapr
// +kubebuilder:deprecatedversion:warning="v1alpha1.DaprControlPlane is deprecated, please, use v1alpha1.DaprInstance instead"

type DaprControlPlane struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -51,7 +52,7 @@ type DaprControlPlane struct {
Status DaprControlPlaneStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

type DaprControlPlaneList struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -62,7 +63,3 @@ type DaprControlPlaneList struct {
func init() {
SchemeBuilder.Register(&DaprControlPlane{}, &DaprControlPlaneList{})
}

func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
66 changes: 66 additions & 0 deletions api/operator/v1alpha1/dapr_cruise_control_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DaprCruiseControlSpec defines the desired state of DaprCruiseControl.
type DaprCruiseControlSpec struct {
}

// DaprCruiseControlStatus defines the observed state of DaprCruiseControl.
type DaprCruiseControlStatus struct {
Phase string `json:"phase"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Chart *ChartMeta `json:"chart,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The phase"
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="Reason"
// +kubebuilder:printcolumn:name="Reconciled",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reconciled Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].reason`,description="Reason"
// +kubebuilder:resource:path=daprcruiscontrols,scope=Namespaced,shortName=dcc,categories=dapr

// DaprCruiseControl is the Schema for the daprcruisecontrols API.
type DaprCruiseControl struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DaprCruiseControlSpec `json:"spec,omitempty"`
Status DaprCruiseControlStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// DaprCruiseControlList contains a list of DaprCruiseControl.
type DaprCruiseControlList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DaprCruiseControl `json:"items"`
}

func init() {
SchemeBuilder.Register(&DaprCruiseControl{}, &DaprCruiseControlList{})
}
71 changes: 71 additions & 0 deletions api/operator/v1alpha1/dapr_instance_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DaprInstanceSpec defines the desired state of DaprInstance.
type DaprInstanceSpec struct {
// +kubebuilder:validation:Optional
Chart *ChartSpec `json:"chart,omitempty"`

// +kubebuilder:validation:Optional
Values *JSON `json:"values"`
}

// DaprInstanceStatus defines the observed state of DaprInstance.
type DaprInstanceStatus struct {
Phase string `json:"phase"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Chart *ChartMeta `json:"chart,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The phase"
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="Reason"
// +kubebuilder:printcolumn:name="Reconciled",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reconciled Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Reconciled")].reason`,description="Reason"
// +kubebuilder:resource:path=daprinstances,scope=Namespaced,shortName=di,categories=dapr

// DaprInstance is the Schema for the daprinstances API.
type DaprInstance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DaprInstanceSpec `json:"spec,omitempty"`
Status DaprInstanceStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// DaprInstanceList contains a list of DaprInstance.
type DaprInstanceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DaprInstance `json:"items"`
}

func init() {
SchemeBuilder.Register(&DaprInstance{}, &DaprInstanceList{})
}
4 changes: 4 additions & 0 deletions api/operator/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ var (
// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Loading

0 comments on commit be3f791

Please sign in to comment.