Skip to content

Commit

Permalink
Merge pull request #12 from jakub-dzon/add-node-placement-to-example
Browse files Browse the repository at this point in the history
Add node placement support to the sample operator
  • Loading branch information
pkliczewski authored Oct 15, 2020
2 parents 0ec883c + 853184e commit d6d15f4
Show file tree
Hide file tree
Showing 6 changed files with 1,560 additions and 7 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: sample.lifecycle.kubevirt.io/v1alpha1
kind: SampleConfig
metadata:
name: example-sampleconfig
spec: {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (

// SampleConfigSpec defines the desired state of SampleConfig
type SampleConfigSpec struct {
// Rules on which nodes controller pod(s) will be scheduled
// +optional
Infra sdkapi.NodePlacement `json:"infra,omitempty"`
}

// SampleConfigStatus defines the observed state of SampleConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *CrManager) Status(cr runtime.Object) *sdkapi.Status {
}

// GetAllResources provides all resources managed by the cr
func (m *CrManager) GetAllResources(_ runtime.Object) ([]runtime.Object, error) {
func (m *CrManager) GetAllResources(obj runtime.Object) ([]runtime.Object, error) {
namespace := m.operatorArgs.Namespace

serviceAccount := resourceBuilder.CreateServiceAccount(HTTPServerName)
Expand All @@ -66,7 +66,8 @@ func (m *CrManager) GetAllResources(_ runtime.Object) ([]runtime.Object, error)
roleBinding := resourceBuilder.CreateRoleBinding(HTTPServerName, HTTPServerName, HTTPServerName, namespace)
roleBinding.Namespace = namespace

httpDeployment := m.createHTTPServerDeployment()
cr := obj.(*v1alpha1.SampleConfig)
httpDeployment := m.createHTTPServerDeployment(&cr.Spec.Infra)
httpService := m.createHTTPServerService()

return []runtime.Object{
Expand All @@ -88,7 +89,7 @@ func (m *CrManager) createHTTPServerService() *v1.Service {
return httpService
}

func (m *CrManager) createHTTPServerDeployment() *appsv1.Deployment {
func (m *CrManager) createHTTPServerDeployment(placement *sdkapi.NodePlacement) *appsv1.Deployment {
ports := []v1.ContainerPort{
{
Name: "http",
Expand All @@ -102,7 +103,7 @@ func (m *CrManager) createHTTPServerDeployment() *appsv1.Deployment {
*container,
},
}
return resourceBuilder.CreateOperatorDeployment(HTTPServerDeploymentName, m.operatorArgs.Namespace, deploymentMatchKey, HTTPServerName, HTTPServerName, 1, podSpec)
return resourceBuilder.CreateDeployment(HTTPServerDeploymentName, m.operatorArgs.Namespace, deploymentMatchKey, HTTPServerName, HTTPServerName, 1, podSpec, placement)
}

// GetDependantResourcesListObjects returns resource list objects of dependant resources
Expand Down
Loading

0 comments on commit d6d15f4

Please sign in to comment.