Skip to content

Commit

Permalink
Add common types
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed Dec 2, 2024
1 parent 6a46d95 commit bc2bff6
Show file tree
Hide file tree
Showing 35 changed files with 338 additions and 579 deletions.
80 changes: 80 additions & 0 deletions apis/common/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package common

import (
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ManagementSpec struct defines the component's management configuration.
// +kubebuilder:object:generate=true
type ManagementSpec struct {
// Set to one of the following values:
//
// - "Managed" : the operator is actively managing the component and trying to keep it active.
// It will only upgrade the component if it is safe to do so
//
// - "Removed" : the operator is actively managing the component and will not install it,
// or if it is installed, the operator will try to remove it
//
// +kubebuilder:validation:Enum=Managed;Removed
ManagementState operatorv1.ManagementState `json:"managementState,omitempty"`
}

// DevFlags defines list of fields that can be used by developers to test customizations. This is not recommended
// to be used in production environment.
// +kubebuilder:object:generate=true
type DevFlags struct {
// List of custom manifests for the given component
// +optional
Manifests []ManifestsConfig `json:"manifests,omitempty"`
}

// DevFlagsSpec struct defines the component's dev flags configuration.
// +kubebuilder:object:generate=true
type DevFlagsSpec struct {
// Add developer fields
// +optional
DevFlags *DevFlags `json:"devFlags,omitempty"`
}

type ManifestsConfig struct {
// uri is the URI point to a git repo with tag/branch. e.g. https://github.com/org/repo/tarball/<tag/branch>
// +optional
// +kubebuilder:default:=""
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
URI string `json:"uri,omitempty"`

// contextDir is the relative path to the folder containing manifests in a repository, default value "manifests"
// +optional
// +kubebuilder:default:="manifests"
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=2
ContextDir string `json:"contextDir,omitempty"`

// sourcePath is the subpath within contextDir where kustomize builds start. Examples include any sub-folder or path: `base`, `overlays/dev`, `default`, `odh` etc.
// +optional
// +kubebuilder:default:=""
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=3
SourcePath string `json:"sourcePath,omitempty"`
}

// +kubebuilder:object:generate=true
type Status struct {
Phase string `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

type WithStatus interface {
GetStatus() *Status
}

type WithDevFlags interface {
GetDevFlags() *DevFlags
}

type BaseObject interface {
client.Object
WithStatus
WithDevFlags
}
102 changes: 102 additions & 0 deletions apis/common/zz_generated.deepcopy.go

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

81 changes: 3 additions & 78 deletions apis/components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,12 @@
package components

import (
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
)

// ManagementSpec struct defines the component's management configuration.
// +kubebuilder:object:generate=true
type ManagementSpec struct {
// Set to one of the following values:
//
// - "Managed" : the operator is actively managing the component and trying to keep it active.
// It will only upgrade the component if it is safe to do so
//
// - "Removed" : the operator is actively managing the component and will not install it,
// or if it is installed, the operator will try to remove it
//
// +kubebuilder:validation:Enum=Managed;Removed
ManagementState operatorv1.ManagementState `json:"managementState,omitempty"`
}

// DevFlagsSpec struct defines the component's dev flags configuration.
// +kubebuilder:object:generate=true
type DevFlagsSpec struct {
// Add developer fields
// +optional
DevFlags *DevFlags `json:"devFlags,omitempty"`
}

// Component struct defines the basis for each OpenDataHub component configuration.
// +kubebuilder:object:generate=true
type Component struct {
ManagementSpec `json:",inline"`
DevFlagsSpec `json:",inline"`
}

// DevFlags defines list of fields that can be used by developers to test customizations. This is not recommended
// to be used in production environment.
// +kubebuilder:object:generate=true
type DevFlags struct {
// List of custom manifests for the given component
// +optional
Manifests []ManifestsConfig `json:"manifests,omitempty"`
}

type ManifestsConfig struct {
// uri is the URI point to a git repo with tag/branch. e.g. https://github.com/org/repo/tarball/<tag/branch>
// +optional
// +kubebuilder:default:=""
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
URI string `json:"uri,omitempty"`

// contextDir is the relative path to the folder containing manifests in a repository, default value "manifests"
// +optional
// +kubebuilder:default:="manifests"
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=2
ContextDir string `json:"contextDir,omitempty"`

// sourcePath is the subpath within contextDir where kustomize builds start. Examples include any sub-folder or path: `base`, `overlays/dev`, `default`, `odh` etc.
// +optional
// +kubebuilder:default:=""
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=3
SourcePath string `json:"sourcePath,omitempty"`
}

// +kubebuilder:object:generate=true
type Status struct {
Phase string `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

type WithStatus interface {
GetStatus() *Status
}

type WithDevFlags interface {
GetDevFlags() *DevFlags
}

type ComponentObject interface {
client.Object
WithDevFlags
WithStatus
common.ManagementSpec `json:",inline"`
common.DevFlagsSpec `json:",inline"`
}
14 changes: 7 additions & 7 deletions apis/components/v1/codeflare_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -30,7 +30,7 @@ const (

// CodeFlareStatus defines the observed state of CodeFlare
type CodeFlareStatus struct {
components.Status `json:",inline"`
common.Status `json:",inline"`
}

// +kubebuilder:object:root=true
Expand All @@ -54,14 +54,14 @@ type CodeFlareSpec struct {
}

type CodeFlareCommonSpec struct {
components.DevFlagsSpec `json:",inline"`
common.DevFlagsSpec `json:",inline"`
}

func (c *CodeFlare) GetDevFlags() *components.DevFlags {
func (c *CodeFlare) GetDevFlags() *common.DevFlags {
return c.Spec.DevFlags
}

func (c *CodeFlare) GetStatus() *components.Status {
func (c *CodeFlare) GetStatus() *common.Status {
return &c.Status.Status
}

Expand All @@ -83,6 +83,6 @@ func init() {
}

type DSCCodeFlare struct {
components.ManagementSpec `json:",inline"`
CodeFlareCommonSpec `json:",inline"`
common.ManagementSpec `json:",inline"`
CodeFlareCommonSpec `json:",inline"`
}
12 changes: 6 additions & 6 deletions apis/components/v1/dashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -32,7 +32,7 @@ const (
// DashboardCommonSpec spec defines the shared desired state of Dashboard
type DashboardCommonSpec struct {
// dashboard spec exposed to DSC api
components.DevFlagsSpec `json:",inline"`
common.DevFlagsSpec `json:",inline"`
// dashboard spec exposed only to internal api
}

Expand All @@ -45,7 +45,7 @@ type DashboardSpec struct {

// DashboardStatus defines the observed state of Dashboard
type DashboardStatus struct {
components.Status `json:",inline"`
common.Status `json:",inline"`

URL string `json:"url,omitempty"`
}
Expand All @@ -67,11 +67,11 @@ type Dashboard struct {
Status DashboardStatus `json:"status,omitempty"`
}

func (c *Dashboard) GetDevFlags() *components.DevFlags {
func (c *Dashboard) GetDevFlags() *common.DevFlags {
return c.Spec.DevFlags
}

func (c *Dashboard) GetStatus() *components.Status {
func (c *Dashboard) GetStatus() *common.Status {
return &c.Status.Status
}

Expand All @@ -91,7 +91,7 @@ func init() {
// DSCDashboard contains all the configuration exposed in DSC instance for Dashboard component
type DSCDashboard struct {
// configuration fields common across components
components.ManagementSpec `json:",inline"`
common.ManagementSpec `json:",inline"`
// dashboard specific field
DashboardCommonSpec `json:",inline"`
}
Loading

0 comments on commit bc2bff6

Please sign in to comment.