-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add usable interfaces to create new tasks #16
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ad0f75a
Implement new CassandraTasks as client features to allow simpler crea…
burmanm 919e5e6
Update cass-operator, add k8ssandra-operator dependency
burmanm 55053a6
Implement the basic tasks in a reuseable API, not as cmd line yet
burmanm 5e1050a
Rename kcName to cluster
burmanm 63da254
Add tests, remove :latest tag, update base version to 0.3.0, add envt…
burmanm 39ca7fc
Fix compaction task name
burmanm 9b62ced
Update task name creation to keep the random part but cut the static one
burmanm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,58 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
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") | ||
} | ||
|
||
generatedName := fmt.Sprintf("%s-%s-%d-%d", kcName, command, time.Now().Unix(), rand.Int31()) | ||
if len(generatedName) > 63 { | ||
generatedName = generatedName[:63] | ||
} | ||
task := &k8ssandrataskapi.K8ssandraTask{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: generatedName, | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[thought] When the K8ssandraTask controller creates
CassandraTask
instances, it uses the naming pattern:So we should account for that. Although we don't necessarily have all the existing datacenter names here, so it's probably better to do it in k8ssandra-operator (there's no length check right now).
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both places will need a cutting function. Even here, I'm wondering if I should rather cut the kcName instead of the randomized parts, since if someone has kcName with length 63, this would always create the same name and we end up with problems. I'll modify this functionality (and I can send a PR to k8ssandra-operator to cut the name there too).
I'd say the randomized part is the most important one (just have to be careful that it doesn't start with a number), we can control the output with
kubectl get k8ssandratasks
to include the DC+Cluster information.