mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
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:
commit
b544314c2f
@ -1128,12 +1128,12 @@ func (j *IngressTestJig) CreateIngress(manifestPath, ns string, ingAnnotations m
|
|||||||
j.Ingress.Annotations[k] = v
|
j.Ingress.Annotations[k] = v
|
||||||
}
|
}
|
||||||
j.Logger.Infof(fmt.Sprintf("creating" + j.Ingress.Name + " ingress"))
|
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)
|
ExpectNoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCreate runs the required command to create the given ingress.
|
// runCreate runs the required command to create the given ingress.
|
||||||
func (j *IngressTestJig) RunCreate(ing *extensions.Ingress) (*extensions.Ingress, error) {
|
func (j *IngressTestJig) runCreate(ing *extensions.Ingress) (*extensions.Ingress, error) {
|
||||||
if j.Class != MulticlusterIngressClassValue {
|
if j.Class != MulticlusterIngressClassValue {
|
||||||
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Create(ing)
|
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
|
return ing, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunUpdate runs the required command to update the given ingress.
|
// runUpdate runs the required command to update the given ingress.
|
||||||
func (j *IngressTestJig) RunUpdate(ing *extensions.Ingress) (*extensions.Ingress, error) {
|
func (j *IngressTestJig) runUpdate(ing *extensions.Ingress) (*extensions.Ingress, error) {
|
||||||
if j.Class != MulticlusterIngressClassValue {
|
if j.Class != MulticlusterIngressClassValue {
|
||||||
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Update(ing)
|
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)
|
Failf("failed to get ingress %q: %v", name, err)
|
||||||
}
|
}
|
||||||
update(j.Ingress)
|
update(j.Ingress)
|
||||||
j.Ingress, err = j.RunUpdate(j.Ingress)
|
j.Ingress, err = j.runUpdate(j.Ingress)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
DescribeIng(j.Ingress.Namespace)
|
DescribeIng(j.Ingress.Namespace)
|
||||||
return
|
return
|
||||||
@ -1223,7 +1223,7 @@ func (j *IngressTestJig) TryDeleteIngress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (j *IngressTestJig) TryDeleteGivenIngress(ing *extensions.Ingress) {
|
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)
|
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.
|
// runDelete runs the required command to delete the given ingress.
|
||||||
func (j *IngressTestJig) RunDelete(ing *extensions.Ingress, class string) error {
|
func (j *IngressTestJig) runDelete(ing *extensions.Ingress, class string) error {
|
||||||
if j.Class != MulticlusterIngressClassValue {
|
if j.Class != MulticlusterIngressClassValue {
|
||||||
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Delete(ing.Name, nil)
|
return j.Client.ExtensionsV1beta1().Ingresses(ing.Namespace).Delete(ing.Name, nil)
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func IngressFromManifest(fileName string) (*extensions.Ingress, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IngressToManifest generates a yaml file in the given path with the given ingress.
|
// 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 {
|
func IngressToManifest(ing *extensions.Ingress, path string) error {
|
||||||
serialized, err := util.MarshalToYaml(ing, extensions.SchemeGroupVersion)
|
serialized, err := util.MarshalToYaml(ing, extensions.SchemeGroupVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,6 +17,9 @@ limitations under the License.
|
|||||||
package manifest
|
package manifest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
extensions "k8s.io/api/extensions/v1beta1"
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
@ -24,12 +27,20 @@ import (
|
|||||||
|
|
||||||
func TestIngressToManifest(t *testing.T) {
|
func TestIngressToManifest(t *testing.T) {
|
||||||
ing := &extensions.Ingress{}
|
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.
|
// 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)
|
t.Fatalf("Error in creating file: %s", err)
|
||||||
}
|
}
|
||||||
// Writing it again should not return an error.
|
// 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)
|
t.Fatalf("Error in creating file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user