Skip to content

Commit a7bb744

Browse files
remove: unused functions
1 parent 3ca4405 commit a7bb744

File tree

4 files changed

+0
-338
lines changed

4 files changed

+0
-338
lines changed

controllers/machineset.go

-110
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ const (
2525
timeThirtySeconds = 30 * time.Second
2626
)
2727

28-
func (r *AppWrapperReconciler) checkExistingMachineSet(ctx context.Context, machineSetName string) bool {
29-
// Set up the Object key with the requested app wrapper name and requested type
30-
key := client.ObjectKey{
31-
Name: machineSetName,
32-
Namespace: namespaceToList,
33-
}
34-
35-
machineSet := &machinev1beta1.MachineSet{}
36-
err := r.Get(ctx, key, machineSet)
37-
if err != nil {
38-
// Check if the error is due to the MachineSet not existing
39-
if client.IgnoreNotFound(err) != nil {
40-
// return error if it there is a different error for not getting the MachineSet
41-
klog.Infof("Error getting MachineSet: %s", err)
42-
}
43-
// MachineSet does not exist
44-
return false
45-
}
46-
// The MachineSet exists
47-
return true
48-
}
49-
5028
func (r *AppWrapperReconciler) reconcileCreateMachineSet(ctx context.Context, aw *arbv1.AppWrapper, demandMapPerInstanceType map[string]int) (ctrl.Result, error) {
5129

5230
allMachineSet := machinev1beta1.MachineSetList{}
@@ -498,94 +476,6 @@ func (r *AppWrapperReconciler) annotateToDeleteMachine(ctx context.Context, aw *
498476
return nil
499477
}
500478

501-
/*
502-
func (r *AppWrapperReconciler) annotateToDeleteMachine(ctx context.Context, aw *arbv1.AppWrapper) error {
503-
label := fmt.Sprintf("%s-%s", aw.Name, aw.Namespace)
504-
// We get a list of Nodes with the AppWrapper name and correct instance type
505-
labelSelector := labels.SelectorFromSet(labels.Set(map[string]string{
506-
label: label,
507-
}))
508-
listOptions := &metav1.ListOptions{
509-
LabelSelector: labelSelector.String(),
510-
}
511-
// List nodes with the AppWrapper name
512-
nodes, _ := r.kubeClient.CoreV1().Nodes().List(ctx, *listOptions)
513-
for _, node := range nodes.Items {
514-
klog.Infof("Filtered node name is %v", aw.Name)
515-
for k, v := range node.Annotations {
516-
if k == "machine.openshift.io/machine" {
517-
machineName := strings.Split(v, "/")
518-
klog.Infof("The machine name to be annotated %v", machineName[1])
519-
allMachines := machinev1beta1.MachineList{}
520-
errm := r.List(ctx, &allMachines)
521-
if errm != nil {
522-
klog.Infof("Error listing machines: %v", errm)
523-
return errm
524-
}
525-
for _, aMachine := range allMachines.Items {
526-
//remove index hardcoding
527-
if aMachine.Name == machineName[1] {
528-
updateMachine := aMachine.DeepCopy()
529-
updateMachine.Annotations["machine.openshift.io/cluster-api-delete-machine"] = "true"
530-
if err := r.Update(ctx, updateMachine); err != nil {
531-
return err
532-
}
533-
var updateMachineset string = ""
534-
for k, v := range updateMachine.Labels {
535-
if k == "machine.openshift.io/cluster-api-machineset" {
536-
updateMachineset = v
537-
klog.Infof("Machineset to update is %v", updateMachineset)
538-
}
539-
}
540-
if updateMachineset != "" {
541-
allMachineSet := machinev1beta1.MachineSetList{}
542-
err := r.List(ctx, &allMachineSet)
543-
if err != nil {
544-
klog.Infof("Machineset retrieval error")
545-
return err
546-
}
547-
for _, aMachineSet := range allMachineSet.Items {
548-
if aMachineSet.Name == updateMachineset {
549-
klog.Infof("Existing machineset replicas %v", &aMachineSet.Spec.Replicas)
550-
//scale down is harded coded to 1??
551-
newReplicas := *aMachineSet.Spec.Replicas - int32(1)
552-
updateMsReplicas := aMachineSet.DeepCopy()
553-
updateMsReplicas.Spec.Replicas = &newReplicas
554-
err := r.Update(ctx, updateMsReplicas)
555-
if err != nil {
556-
klog.Infof("Error updating MachineSet: %s", err)
557-
return err
558-
}
559-
err = r.Get(ctx, types.NamespacedName{Namespace: namespaceToList}, updateMsReplicas)
560-
if err != nil {
561-
klog.Infof("Error updating MachineSet: %s", err)
562-
return err
563-
}
564-
if updateMsReplicas.Labels[fmt.Sprintf("instascale.codeflare.dev-%s-%s", aw.Name, aw.Namespace)] != "" {
565-
if err := r.removeMachineSetLabel(ctx, aw, aMachineSet.Name); err != nil {
566-
return err
567-
}
568-
}
569-
klog.Infof("Replica update successful")
570-
}
571-
}
572-
}
573-
}
574-
}
575-
}
576-
}
577-
}
578-
579-
for machineSetName := range machineSetNames {
580-
if updateMsReplicas.Labels[fmt.Sprintf("instascale.codeflare.dev-%s-%s", aw.Name, aw.Namespace)] != "" {
581-
if err := r.removeMachineSetLabel(ctx, aw, aMachineSet.Name); err != nil {
582-
return err
583-
}
584-
}
585-
}
586-
return nil
587-
}
588-
*/
589479
func (r *AppWrapperReconciler) patchMachineLabels(ctx context.Context, oldAw *arbv1.AppWrapper, newAw *arbv1.AppWrapper, machineName string) error {
590480
// Retrieve the machine object
591481
machine := &machinev1beta1.Machine{}

controllers/utils.go

-93
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,15 @@ package controllers
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
7-
"math"
86
"math/rand"
97
"time"
108

119
machinev1 "github.com/openshift/api/machine/v1beta1"
12-
mapiclientset "github.com/openshift/client-go/machine/clientset/versioned"
13-
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
14-
clusterstateapi "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/clusterstate/api"
1510
"k8s.io/apimachinery/pkg/runtime"
16-
"k8s.io/client-go/rest"
17-
"k8s.io/client-go/tools/clientcmd"
1811
"k8s.io/klog"
1912
)
2013

21-
// ClientBuilder can create a variety of kubernetes client interface
22-
// with its embeded rest.Config.
23-
type ClientBuilder struct {
24-
config *rest.Config
25-
}
26-
27-
func getPodResourcesWithReplicas(pod arbv1.CustomPodResourceTemplate) (resource *clusterstateapi.Resource, count int) {
28-
replicas := pod.Replicas
29-
req := clusterstateapi.NewResource(pod.Requests)
30-
limit := clusterstateapi.NewResource(pod.Limits)
31-
tolerance := 0.001
32-
33-
// Use limit if request is 0
34-
if diff := math.Abs(req.MilliCPU - float64(0.0)); diff < tolerance {
35-
req.MilliCPU = limit.MilliCPU
36-
}
37-
38-
if diff := math.Abs(req.Memory - float64(0.0)); diff < tolerance {
39-
req.Memory = limit.Memory
40-
}
41-
42-
if req.GPU <= 0 {
43-
req.GPU = limit.GPU
44-
}
45-
46-
return req, replicas
47-
}
48-
49-
// MachineClientOrDie returns the machine api client interface for machine api objects.
50-
func (cb *ClientBuilder) MachineClientOrDie(name string) mapiclientset.Interface {
51-
return mapiclientset.NewForConfigOrDie(rest.AddUserAgent(cb.config, name))
52-
}
53-
5414
func resyncPeriod() func() time.Duration {
5515
return func() time.Duration {
5616
factor := rand.Float64() + 1
@@ -73,59 +33,6 @@ func ProviderSpecFromRawExtension(rawExtension *runtime.RawExtension) (*machinev
7333
return spec, nil
7434
}
7535

76-
// NewClientBuilder returns a *ClientBuilder with the given kubeconfig.
77-
func NewClientBuilder(kubeconfig string) (*ClientBuilder, error) {
78-
config, err := getRestConfig(kubeconfig)
79-
if err != nil {
80-
return nil, err
81-
}
82-
83-
return &ClientBuilder{
84-
config: config,
85-
}, nil
86-
}
87-
88-
// This function is changed from genericresource.go file as we force to look for resources under custompodresources.
89-
func GetListOfPodResourcesFromOneGenericItem(awr *arbv1.AppWrapperGenericResource) (resource []*clusterstateapi.Resource, er error) {
90-
var podResourcesList []*clusterstateapi.Resource
91-
92-
podTotalresource := clusterstateapi.EmptyResource()
93-
var replicas int
94-
var res *clusterstateapi.Resource
95-
if awr.GenericTemplate.Raw != nil {
96-
podresources := awr.CustomPodResources
97-
for _, item := range podresources {
98-
res, replicas = getPodResourcesWithReplicas(item)
99-
podTotalresource = podTotalresource.Add(res)
100-
}
101-
klog.V(8).Infof("[GetListOfPodResourcesFromOneGenericItem] Requested total allocation resource from 1 pod `%v`.\n", podTotalresource)
102-
103-
// Addd individual pods to results
104-
var replicaCount int = int(replicas)
105-
for i := 0; i < replicaCount; i++ {
106-
podResourcesList = append(podResourcesList, podTotalresource)
107-
}
108-
}
109-
110-
return podResourcesList, nil
111-
}
112-
113-
func getRestConfig(kubeconfig string) (*rest.Config, error) {
114-
var config *rest.Config
115-
var err error
116-
if kubeconfig != "" {
117-
klog.V(10).Infof("Loading kube client config from path %q", kubeconfig)
118-
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
119-
} else {
120-
klog.V(4).Infof("Using in-cluster kube client config")
121-
config, err = rest.InClusterConfig()
122-
if err == rest.ErrNotInCluster {
123-
return nil, errors.New("Not running in-cluster? Try using --kubeconfig")
124-
}
125-
}
126-
return config, err
127-
}
128-
12936
func contains(s []string, str string) bool {
13037
for _, v := range s {
13138
if v == str {

controllers/utils_test.go

-121
Original file line numberDiff line numberDiff line change
@@ -7,130 +7,9 @@ import (
77
"github.com/onsi/gomega"
88
machinev1 "github.com/openshift/api/machine/v1beta1"
99

10-
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
11-
clusterstateapi "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/clusterstate/api"
12-
v1 "k8s.io/api/core/v1"
13-
"k8s.io/apimachinery/pkg/api/resource"
1410
"k8s.io/apimachinery/pkg/runtime"
1511
)
1612

17-
func TestGetPodResourcesWithReplicas(t *testing.T) {
18-
g := gomega.NewGomegaWithT(t)
19-
20-
tests := []struct {
21-
name string
22-
pod arbv1.CustomPodResourceTemplate
23-
wantRes *clusterstateapi.Resource
24-
wantRep int
25-
}{
26-
{
27-
name: "Empty requests and limits",
28-
pod: arbv1.CustomPodResourceTemplate{
29-
Replicas: 0,
30-
Requests: v1.ResourceList{},
31-
Limits: v1.ResourceList{},
32-
},
33-
wantRes: &clusterstateapi.Resource{
34-
MilliCPU: 0,
35-
Memory: 0,
36-
GPU: 0,
37-
},
38-
wantRep: 0,
39-
},
40-
{
41-
name: "Requests and limits",
42-
pod: arbv1.CustomPodResourceTemplate{
43-
Replicas: 3,
44-
Requests: v1.ResourceList{
45-
v1.ResourceCPU: resource.MustParse("1"),
46-
v1.ResourceMemory: resource.MustParse("2Gi"),
47-
v1.ResourceName(clusterstateapi.GPUResourceName): resource.MustParse("1"),
48-
},
49-
Limits: v1.ResourceList{
50-
v1.ResourceCPU: resource.MustParse("2"),
51-
v1.ResourceMemory: resource.MustParse("2Gi"),
52-
v1.ResourceName(clusterstateapi.GPUResourceName): resource.MustParse("2"),
53-
},
54-
},
55-
wantRes: &clusterstateapi.Resource{
56-
MilliCPU: 1000,
57-
Memory: 2 * 1024 * 1024 * 1024,
58-
GPU: 1,
59-
},
60-
wantRep: 3,
61-
},
62-
}
63-
64-
for _, tt := range tests {
65-
t.Run(tt.name, func(t *testing.T) {
66-
res, rep := getPodResourcesWithReplicas(tt.pod)
67-
g.Expect(res).To(gomega.Equal(tt.wantRes))
68-
g.Expect(rep).To(gomega.Equal(tt.wantRep))
69-
})
70-
}
71-
}
72-
73-
func TestGetListOfPodResourcesFromOneGenericItem(t *testing.T) {
74-
g := gomega.NewGomegaWithT(t)
75-
76-
tests := []struct {
77-
name string
78-
awr *arbv1.AppWrapperGenericResource
79-
want []*clusterstateapi.Resource
80-
}{
81-
{
82-
name: "Empty requests and limits",
83-
awr: &arbv1.AppWrapperGenericResource{
84-
CustomPodResources: []arbv1.CustomPodResourceTemplate{
85-
{
86-
Replicas: 0,
87-
Requests: v1.ResourceList{},
88-
Limits: v1.ResourceList{},
89-
},
90-
},
91-
},
92-
want: []*clusterstateapi.Resource{},
93-
},
94-
{
95-
name: "Request and Limits",
96-
awr: &arbv1.AppWrapperGenericResource{
97-
GenericTemplate: runtime.RawExtension{
98-
Raw: []byte(`{"customPodResources": [{"replicas": 1, "requests": {"gpu": "0", "memory": "1Gi"}, "limits": {"gpu": "0.5", "memory": "2Gi"}}]}`),
99-
},
100-
CustomPodResources: []arbv1.CustomPodResourceTemplate{
101-
{
102-
Replicas: 1,
103-
Requests: v1.ResourceList{
104-
v1.ResourceMemory: resource.MustParse("2Gi"),
105-
v1.ResourceName(clusterstateapi.GPUResourceName): resource.MustParse("1"),
106-
},
107-
Limits: v1.ResourceList{
108-
v1.ResourceMemory: resource.MustParse("2Gi"),
109-
v1.ResourceName(clusterstateapi.GPUResourceName): resource.MustParse("2"),
110-
},
111-
},
112-
},
113-
},
114-
want: []*clusterstateapi.Resource{
115-
{
116-
GPU: 1,
117-
Memory: 2 * 1024 * 1024 * 1024,
118-
},
119-
},
120-
},
121-
}
122-
123-
for _, tt := range tests {
124-
t.Run(tt.name, func(t *testing.T) {
125-
result, _ := GetListOfPodResourcesFromOneGenericItem(tt.awr)
126-
g.Expect(len(result)).To(gomega.Equal(len(tt.want)))
127-
for i := range result {
128-
g.Expect(result[i]).To(gomega.Equal(tt.want[i]))
129-
}
130-
})
131-
}
132-
}
133-
13413
func TestProviderSpecFromRawExtension(t *testing.T) {
13514
g := gomega.NewGomegaWithT(t)
13615

go.sum

-14
Original file line numberDiff line numberDiff line change
@@ -408,20 +408,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
408408
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
409409
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
410410
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
411-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1-0.20230831150053-05b1af83014c h1:LjCgRcjtkd9byePczvxGBLjdM22M2BCTB76FoEk2fkU=
412-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1-0.20230831150053-05b1af83014c/go.mod h1:gtTl8Tsl+X+bGhqVudLoveINR6IkN+sVvH0J+VZIP40=
413-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1 h1:ZNQ/JPdjS6CtaAzt6SNqaoWcpwS1PyVdgZlmIYikPLI=
414-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
415-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.35.0 h1:7Ks2+6Jd8tnwymSmSrwNb/CpAPmgS0lNIhMlj6DrT+o=
416-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.35.0/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
417-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.36.0 h1:QSc16Kd4OBidGY4rQivMrUX9B9cNKttfZIRKsR4BX9E=
418-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.36.0/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
419-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.0 h1:oyhdLdc4BgA4zcH1zlRrSrYpzuVxV5QLDbyIXrwnQqs=
420-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.0/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
421-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.1 h1:hZhGwKTPeHYYhNbvO27NOjozVpy7m3I3apKf81u9U3A=
422-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.1/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
423-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.38.0 h1:dU2Ev0SijdNm30Y9mjdKJL1Fp6l07rnRBKhSbx1kX9g=
424-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.38.0/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
425411
github.com/project-codeflare/multi-cluster-app-dispatcher v1.38.1 h1:6ILHYAFxDkAnQu3CJebGQPQGcmcy7/E/AhRiea6yOTc=
426412
github.com/project-codeflare/multi-cluster-app-dispatcher v1.38.1/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
427413
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=

0 commit comments

Comments
 (0)