Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the unmanaged cluster CRD for adopting existing k8s clusters #623

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactored the service spec into a common struct
kylewuolle committed Nov 13, 2024
commit 199a194fdaec6e2fa2bea81619e7cd13dd2222d1
22 changes: 22 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
@@ -52,3 +52,25 @@ const (
// Provider Sveltos
ProviderSveltosName = "projectsveltos"
)

type ServicesType struct {
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
// the one with higher priority will get to deploy its services.
ServicesPriority int32 `json:"servicesPriority,omitempty"`
// DryRun specifies whether the template should be applied after validation or only validated.
// DryRun bool `json:"dryRun,omitempty"`

// +kubebuilder:default:=false

// StopOnConflict specifies what to do in case of a conflict.
// E.g. If another object is already managing a service.
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`
}
22 changes: 2 additions & 20 deletions api/v1alpha1/managedcluster_types.go
Original file line number Diff line number Diff line change
@@ -65,29 +65,11 @@ type ManagedClusterSpec struct {
Template string `json:"template"`
// Name reference to the related Credentials object.
Credential string `json:"credential,omitempty"`
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// +kubebuilder:default:=100
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2147483646

// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
// the one with higher priority will get to deploy its services.
ServicesPriority int32 `json:"servicesPriority,omitempty"`

// DryRun specifies whether the template should be applied after validation or only validated.
DryRun bool `json:"dryRun,omitempty"`

// +kubebuilder:default:=false

// StopOnConflict specifies what to do in case of a conflict.
// E.g. If another object is already managing a service.
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`
ServicesType `json:",inline"`
}

// ManagedClusterStatus defines the observed state of ManagedCluster
22 changes: 1 addition & 21 deletions api/v1alpha1/multiclusterservice_types.go
Original file line number Diff line number Diff line change
@@ -63,27 +63,7 @@ type ServiceSpec struct {
type MultiClusterServiceSpec struct {
// ClusterSelector identifies target clusters to manage services on.
ClusterSelector metav1.LabelSelector `json:"clusterSelector,omitempty"`
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// +kubebuilder:default:=100
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2147483646

// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
// the one with higher priority will get to deploy its services.
ServicesPriority int32 `json:"servicesPriority,omitempty"`

// +kubebuilder:default:=false

// StopOnConflict specifies what to do in case of a conflict.
// E.g. If another object is already managing a service.
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`
ServicesType `json:",inline"`
}

// ServiceStatus contains details for the state of services.
20 changes: 1 addition & 19 deletions api/v1alpha1/unmanagedcluster_types.go
Original file line number Diff line number Diff line change
@@ -28,25 +28,7 @@ const (

// UnmanagedClusterSpec defines the desired state of UnmanagedCluster
type UnmanagedClusterSpec struct {
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
// the one with higher priority will get to deploy its services.
ServicesPriority int32 `json:"servicesPriority,omitempty"`
// DryRun specifies whether the template should be applied after validation or only validated.
// DryRun bool `json:"dryRun,omitempty"`

// +kubebuilder:default:=false

// StopOnConflict specifies what to do in case of a conflict.
// E.g. If another object is already managing a service.
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`
ServicesType `json:",inline"`
}

// UnmanagedClusterStatus defines the observed state of UnmanagedCluster
46 changes: 25 additions & 21 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -103,15 +103,12 @@ spec:
type: object
type: array
servicesPriority:
default: 100
description: |-
ServicesPriority sets the priority for the services defined in this spec.
Higher value means higher priority and lower means lower.
In case of conflict with another object managing the service,
the one with higher priority will get to deploy its services.
format: int32
maximum: 2147483646
minimum: 1
type: integer
stopOnConflict:
default: false
Original file line number Diff line number Diff line change
@@ -121,15 +121,12 @@ spec:
type: object
type: array
servicesPriority:
default: 100
description: |-
ServicesPriority sets the priority for the services defined in this spec.
Higher value means higher priority and lower means lower.
In case of conflict with another object managing the service,
the one with higher priority will get to deploy its services.
format: int32
maximum: 2147483646
minimum: 1
type: integer
stopOnConflict:
default: false

Unchanged files with check annotations Beta

Spec: hmc.ManagedClusterSpec{
Template: templateName,
Credential: credentialName,
Services: []hmc.ServiceSpec{

Check failure on line 183 in internal/controller/managedcluster_controller_test.go

GitHub Actions / Build and Unit Test

unknown field Services in struct literal of type "github.com/Mirantis/hmc/api/v1alpha1".ManagedClusterSpec
{
Template: svcTemplateName,
Name: "test-svc-name",
},
},
Spec: hmc.MultiClusterServiceSpec{
Services: []hmc.ServiceSpec{

Check failure on line 179 in internal/controller/multiclusterservice_controller_test.go

GitHub Actions / Build and Unit Test

unknown field Services in struct literal of type "github.com/Mirantis/hmc/api/v1alpha1".MultiClusterServiceSpec
{
Template: serviceTemplateName,
Name: helmChartReleaseName,
Namespace: unmanagedClusterNamespace,
},
Spec: hmc.UnmanagedClusterSpec{
Services: nil,

Check failure on line 80 in internal/controller/unmanagedcluster_controller_test.go

GitHub Actions / Build and Unit Test

unknown field Services in struct literal of type "github.com/Mirantis/hmc/api/v1alpha1".UnmanagedClusterSpec
ServicesPriority: 1,

Check failure on line 81 in internal/controller/unmanagedcluster_controller_test.go

GitHub Actions / Build and Unit Test

unknown field ServicesPriority in struct literal of type "github.com/Mirantis/hmc/api/v1alpha1".UnmanagedClusterSpec
StopOnConflict: true,

Check failure on line 82 in internal/controller/unmanagedcluster_controller_test.go

GitHub Actions / Build and Unit Test

unknown field StopOnConflict in struct literal of type "github.com/Mirantis/hmc/api/v1alpha1".UnmanagedClusterSpec (typecheck)
},
}
Expect(k8sClient.Create(ctx, resource)).To(Succeed())