Merge pull request #59964 from nikhiljindal/kubemciComments

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Updating code to use TempDir in manifest test

Follow up based on comments in https://github.com/kubernetes/kubernetes/pull/59234

```release-note
NONE
```

cc @MrHohn @madhusudancs @G-Harmon
This commit is contained in:
Kubernetes Submit Queue 2018-02-16 16:23:50 -08:00 committed by GitHub
commit b544314c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View File

@ -1128,12 +1128,12 @@ func (j *IngressTestJig) CreateIngress(manifestPath, ns string, ingAnnotations m
j.Ingress.Annotations[k] = v
}
j.Logger.Infof(fmt.Sprintf("creating" + j.Ingress.Name + " ingress"))
j.Ingress, err = j.RunCreate(j.Ingress)
j.Ingress, err = j.runCreate(j.Ingress)
ExpectNoError(err)
}
// RunCreate runs the required command to create the given ingress.
func (j *IngressTestJig) RunCreate(ing *extensions.Ingress) (*extensions.Ingress, error) {
// runCreate runs the required command to create the given ingress.
func (j *IngressTestJig) runCreate(ing *extensions.Ingress) (*extensions.Ingress, error) {
if j.Class != MulticlusterIngressClassValue {
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Create(ing)
}
@ -1146,8 +1146,8 @@ func (j *IngressTestJig) RunCreate(ing *extensions.Ingress) (*extensions.Ingress
return ing, err
}
// RunUpdate runs the required command to update the given ingress.
func (j *IngressTestJig) RunUpdate(ing *extensions.Ingress) (*extensions.Ingress, error) {
// runUpdate runs the required command to update the given ingress.
func (j *IngressTestJig) runUpdate(ing *extensions.Ingress) (*extensions.Ingress, error) {
if j.Class != MulticlusterIngressClassValue {
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Update(ing)
}
@ -1171,7 +1171,7 @@ func (j *IngressTestJig) Update(update func(ing *extensions.Ingress)) {
Failf("failed to get ingress %q: %v", name, err)
}
update(j.Ingress)
j.Ingress, err = j.RunUpdate(j.Ingress)
j.Ingress, err = j.runUpdate(j.Ingress)
if err == nil {
DescribeIng(j.Ingress.Namespace)
return
@ -1223,7 +1223,7 @@ func (j *IngressTestJig) TryDeleteIngress() {
}
func (j *IngressTestJig) TryDeleteGivenIngress(ing *extensions.Ingress) {
if err := j.RunDelete(ing, j.Class); err != nil {
if err := j.runDelete(ing, j.Class); err != nil {
j.Logger.Infof("Error while deleting the ingress %v/%v with class %s: %v", ing.Namespace, ing.Name, j.Class, err)
}
}
@ -1235,8 +1235,8 @@ func (j *IngressTestJig) TryDeleteGivenService(svc *v1.Service) {
}
}
// RunDelete runs the required command to delete the given ingress.
func (j *IngressTestJig) RunDelete(ing *extensions.Ingress, class string) error {
// runDelete runs the required command to delete the given ingress.
func (j *IngressTestJig) runDelete(ing *extensions.Ingress, class string) error {
if j.Class != MulticlusterIngressClassValue {
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Delete(ing.Name, nil)
}

View File

@ -92,7 +92,7 @@ func IngressFromManifest(fileName string) (*extensions.Ingress, error) {
}
// IngressToManifest generates a yaml file in the given path with the given ingress.
// Returns the file name and error, if there was any.
// Assumes that a directory exists at the given path.
func IngressToManifest(ing *extensions.Ingress, path string) error {
serialized, err := util.MarshalToYaml(ing, extensions.SchemeGroupVersion)
if err != nil {

View File

@ -17,6 +17,9 @@ limitations under the License.
package manifest
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
extensions "k8s.io/api/extensions/v1beta1"
@ -24,12 +27,20 @@ import (
func TestIngressToManifest(t *testing.T) {
ing := &extensions.Ingress{}
// Create a temp dir.
tmpDir, err := ioutil.TempDir("", "kubemci")
if err != nil {
t.Fatalf("unexpected error in creating temp dir: %s", err)
}
defer os.RemoveAll(tmpDir)
ingPath := filepath.Join(tmpDir, "ing.yaml")
// Write the ingress to a file and ensure that there is no error.
if err := IngressToManifest(ing, "/tmp/ing.yaml"); err != nil {
if err := IngressToManifest(ing, ingPath); err != nil {
t.Fatalf("Error in creating file: %s", err)
}
// Writing it again should not return an error.
if err := IngressToManifest(ing, "/tmp/ing.yaml"); err != nil {
if err := IngressToManifest(ing, ingPath); err != nil {
t.Fatalf("Error in creating file: %s", err)
}
}