-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
471 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"fmt" | ||
|
||
"volcano.sh/volcano/pkg/client/clientset/versioned" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type deleteFlags struct { | ||
commonFlags | ||
|
||
// Name is name of queue | ||
Name string | ||
} | ||
|
||
var deleteQueueFlags = &deleteFlags{} | ||
|
||
// InitDeleteFlags is used to init all flags during queue deleting | ||
func InitDeleteFlags(cmd *cobra.Command) { | ||
initFlags(cmd, &deleteQueueFlags.commonFlags) | ||
|
||
cmd.Flags().StringVarP(&deleteQueueFlags.Name, "name", "n", "", "the name of queue") | ||
} | ||
|
||
// DeleteQueue delete queue | ||
func DeleteQueue() error { | ||
config, err := buildConfig(deleteQueueFlags.Master, deleteQueueFlags.Kubeconfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(deleteQueueFlags.Name) == 0 { | ||
return fmt.Errorf("Queue name must be specified") | ||
} | ||
|
||
queueClient := versioned.NewForConfigOrDie(config) | ||
return queueClient.SchedulingV1alpha2().Queues().Delete(deleteQueueFlags.Name, &metav1.DeleteOptions{}) | ||
} |
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,87 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"reflect" | ||
"testing" | ||
|
||
"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestDeleteQueue(t *testing.T) { | ||
response := v1alpha2.Queue{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-queue", | ||
}, | ||
} | ||
|
||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
val, err := json.Marshal(response) | ||
if err == nil { | ||
w.Write(val) | ||
} | ||
}) | ||
|
||
server := httptest.NewServer(handler) | ||
defer server.Close() | ||
|
||
deleteQueueFlags.Master = server.URL | ||
testCases := []struct { | ||
Name string | ||
QueueName string | ||
ExpectValue error | ||
}{ | ||
{ | ||
Name: "Normal Case Delete Queue Succeed", | ||
QueueName: "normal-case", | ||
ExpectValue: nil, | ||
}, | ||
{ | ||
Name: "Abnormal Case Delete Queue Failed For Name Not Specified", | ||
QueueName: "", | ||
ExpectValue: fmt.Errorf("Queue name must be specified"), | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
deleteQueueFlags.Name = testCase.QueueName | ||
|
||
err := DeleteQueue() | ||
if false == reflect.DeepEqual(err, testCase.ExpectValue) { | ||
t.Errorf("Case '%s' failed, expected: '%v', got '%v'", testCase.Name, testCase.ExpectValue, err) | ||
} | ||
} | ||
} | ||
|
||
func TestInitDeleteFlags(t *testing.T) { | ||
var cmd cobra.Command | ||
InitDeleteFlags(&cmd) | ||
|
||
if cmd.Flag("name") == nil { | ||
t.Errorf("Could not find the flag name") | ||
} | ||
} |
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
Oops, something went wrong.