-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from burmanm/tasks
Add usable interfaces to create new tasks
- Loading branch information
Showing
14 changed files
with
12,544 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
controlapi "github.com/k8ssandra/cass-operator/apis/control/v1alpha1" | ||
k8ssandrataskapi "github.com/k8ssandra/k8ssandra-operator/apis/control/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func CreateClusterTask(ctx context.Context, kubeClient client.Client, command controlapi.CassandraCommand, namespace, kcName string, datacenters []string, args *controlapi.JobArguments) (*k8ssandrataskapi.K8ssandraTask, error) { | ||
if kcName == "" || namespace == "" { | ||
return nil, fmt.Errorf("clusterName and namespace must be specified") | ||
} | ||
|
||
task := &k8ssandrataskapi.K8ssandraTask{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: createName(kcName, string(command)), | ||
Namespace: namespace, | ||
}, | ||
Spec: k8ssandrataskapi.K8ssandraTaskSpec{ | ||
Cluster: corev1.ObjectReference{ | ||
Name: kcName, | ||
Namespace: namespace, | ||
}, | ||
Template: controlapi.CassandraTaskTemplate{ | ||
Jobs: []controlapi.CassandraJob{ | ||
{ | ||
Command: command, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if len(datacenters) > 0 { | ||
task.Spec.Datacenters = datacenters | ||
} | ||
|
||
if args != nil { | ||
task.Spec.Template.Jobs[0].Arguments = *args | ||
} | ||
|
||
if err := kubeClient.Create(ctx, task); err != nil { | ||
return nil, err | ||
} | ||
|
||
return task, nil | ||
} |
Oops, something went wrong.