-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for index-based label and minimal service (#181)
* add support for index-based label and minimal service The minimal service setup only creates the headless service for the main broker pod, decreasing the networking overhead. In addition, I have needed to have a label to identify the broker several times, so it makes sense to add that. Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
229 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
/* | ||
Copyright 2022-2023 Lawrence Livermore National Security, LLC | ||
(c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
This is part of the Flux resource manager framework. | ||
For details, see https://github.com/flux-framework. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
api "flux-framework/flux-operator/api/v1alpha1" | ||
"fmt" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/kubernetes" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
type patchPayload struct { | ||
Operation string `json:"op"` | ||
Path string `json:"path"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func (r *MiniClusterReconciler) addBrokerLabel( | ||
ctx context.Context, | ||
cluster *api.MiniCluster, | ||
) (ctrl.Result, error) { | ||
|
||
// creates the clientset | ||
clientset, err := kubernetes.NewForConfig(r.RESTConfig) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// List pods, and only get ones with undefined labels | ||
pods, err := clientset.CoreV1().Pods(cluster.Namespace).List(ctx, metav1.ListOptions{LabelSelector: "!job-index"}) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
for _, pod := range pods.Items { | ||
|
||
// Add labels to all pods to indicate job-index | ||
prefix := fmt.Sprintf("%s-", cluster.Name) | ||
podName := strings.Replace(pod.GetName(), prefix, "", 1) | ||
podIndex := strings.SplitN(podName, "-", 2)[0] | ||
|
||
payload := []patchPayload{{ | ||
Operation: "add", | ||
Path: "/metadata/labels/job-index", | ||
Value: podIndex, | ||
}} | ||
payloadBytes, _ := json.Marshal(payload) | ||
|
||
_, err = clientset.CoreV1().Pods(pod.GetNamespace()).Patch(ctx, pod.GetName(), types.JSONPatchType, payloadBytes, metav1.PatchOptions{}) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
} | ||
return ctrl.Result{}, nil | ||
} |
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,21 @@ | ||
apiVersion: flux-framework.org/v1alpha1 | ||
kind: MiniCluster | ||
metadata: | ||
name: flux-sample | ||
namespace: flux-operator | ||
spec: | ||
# Number of pods to create for MiniCluster | ||
size: 4 | ||
tasks: 4 | ||
|
||
logging: | ||
quiet: true | ||
|
||
# Minimal service for Flux means only the lead broker gets an address | ||
flux: | ||
minimalService: true | ||
|
||
# This is a list because a pod can support multiple containers | ||
containers: | ||
- image: ghcr.io/flux-framework/flux-restful-api:latest | ||
command: echo hello-world |
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,4 @@ | ||
hello-world | ||
hello-world | ||
hello-world | ||
hello-world |
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