Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First class support for conformance option on command line #36

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/periodic_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:

- name: Run full conformance test
run: |
bin/hydrophone --focus "\[Conformance\]"
bin/hydrophone --conformance
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ $ bin/hydrophone --help
Usage of bin/hydrophone:
-busybox-image string
image let's you select an alternate busybox container image. (default "registry.k8s.io/e2e-test-images/busybox:1.36.1-1")
-conformance
run conformance tests.
-conformance-image string
image let's you select your conformance container image of your choice. (default "registry.k8s.io/conformance:v1.28.0")
-focus string
Expand Down
25 changes: 4 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,28 @@ import (
"os"

"github.com/dims/hydrophone/pkg/client"
"github.com/dims/hydrophone/pkg/common"
"github.com/dims/hydrophone/pkg/service"
)

func main() {
client := client.NewClient()

cfg, err := service.InitArgs()
cfg, err := common.InitArgs()
if err != nil {
log.Fatal("Error parsing arguments: ", err)
}

config, clientSet := service.Init(cfg)
client.ClientSet = clientSet

serverVersion, err := client.ClientSet.ServerVersion()
if err != nil {
log.Fatal("Error fetching server version: ", err)
}
log.Printf("API endpoint : %s", config.Host)
log.Printf("Server version : %#v", *serverVersion)
log.Printf("Running tests : '%s'", cfg.Focus)
if cfg.Skip != "" {
log.Printf("Skipping tests : '%s'", cfg.Skip)
}
log.Printf("Using conformance image : '%s'", cfg.ConformanceImage)
log.Printf("Using busybox image : '%s'", cfg.BusyboxImage)
log.Printf("Test framework will start '%d' threads and use verbosity '%d'",
cfg.Parallel, cfg.Verbosity)

if _, err := os.Stat(cfg.OutputDir); os.IsNotExist(err) {
if err = os.MkdirAll(cfg.OutputDir, 0755); err != nil {
log.Fatalf("Error creating output directory [%s] : %v", cfg.OutputDir, err)
}
}
common.ValidateArgs(client.ClientSet, config, cfg)

service.RunE2E(client.ClientSet, cfg)
client.PrintE2ELogs()
client.FetchFiles(config, clientSet, cfg.OutputDir)
service.Cleanup(client.ClientSet)

log.Println("Exiting with code: ", client.ExitCode)
os.Exit(client.ExitCode)
}
11 changes: 6 additions & 5 deletions pkg/client/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"log"
"time"

"github.com/dims/hydrophone/pkg/service"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"

"github.com/dims/hydrophone/pkg/common"
)

// Contains all the necessary channels to transfer data
Expand All @@ -49,7 +50,7 @@ func (c *Client) PrintE2ELogs() {
informerFactory.WaitForCacheSync(wait.NeverStop)

for {
pod, _ := podInformer.Lister().Pods(service.Namespace).Get(service.PodName)
pod, _ := podInformer.Lister().Pods(common.Namespace).Get(common.PodName)
if pod.Status.Phase == v1.PodRunning {
var err error
stream := streamLogs{
Expand Down Expand Up @@ -86,7 +87,7 @@ func (c *Client) PrintE2ELogs() {
// Wait for pod to be in terminated state and get the exit code
func (c *Client) podExitCode(pod *v1.Pod) {
// Watching the pod's status
watchInterface, err := c.ClientSet.CoreV1().Pods(service.Namespace).Watch(context.TODO(), metav1.ListOptions{
watchInterface, err := c.ClientSet.CoreV1().Pods(common.Namespace).Watch(context.TODO(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("metadata.name=%s", pod.Name),
})
if err != nil {
Expand All @@ -105,7 +106,7 @@ func (c *Client) podExitCode(pod *v1.Pod) {
if pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed {
log.Println("Pod terminated.")
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.Name == service.ConformanceContainer && containerStatus.State.Terminated != nil {
if containerStatus.Name == common.ConformanceContainer && containerStatus.State.Terminated != nil {
c.ExitCode = int(containerStatus.State.Terminated.ExitCode)
}
}
Expand All @@ -116,7 +117,7 @@ func (c *Client) podExitCode(pod *v1.Pod) {
if containerStatus.State.Terminated != nil {
terminated = true
log.Printf("container %s terminated.\n", containerStatus.Name)
if containerStatus.Name == service.ConformanceContainer {
if containerStatus.Name == common.ConformanceContainer {
c.ExitCode = int(containerStatus.State.Terminated.ExitCode)
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package client

import (
"context"
"github.com/dims/hydrophone/pkg/service"
"k8s.io/client-go/rest"
"log"
"os"
"path/filepath"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/dims/hydrophone/pkg/common"
)

var (
Expand All @@ -43,7 +44,7 @@ func (c *Client) FetchFiles(config *rest.Config, clientset *kubernetes.Clientset
log.Fatalf("unable to create e2e.log: %v\n", err)
}
defer e2eLogFile.Close()
err = downloadFile(config, clientset, service.PodName, service.OutputContainer, "/tmp/results/e2e.log", e2eLogFile)
err = downloadFile(config, clientset, common.PodName, common.OutputContainer, "/tmp/results/e2e.log", e2eLogFile)
if err != nil {
log.Fatalf("unable to download e2e.log: %v\n", err)
}
Expand All @@ -53,7 +54,7 @@ func (c *Client) FetchFiles(config *rest.Config, clientset *kubernetes.Clientset
log.Fatalf("unable to create junit_01.xml: %v\n", err)
}
defer junitXMLFile.Close()
err = downloadFile(config, clientset, service.PodName, service.OutputContainer, "/tmp/results/junit_01.xml", junitXMLFile)
err = downloadFile(config, clientset, common.PodName, common.OutputContainer, "/tmp/results/junit_01.xml", junitXMLFile)
if err != nil {
log.Fatalf("unable to download junit_01.xml: %v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"

"github.com/dims/hydrophone/pkg/service"
"github.com/dims/hydrophone/pkg/common"
)

func downloadFile(config *rest.Config, clientset *kubernetes.Clientset,
Expand All @@ -36,7 +36,7 @@ func downloadFile(config *rest.Config, clientset *kubernetes.Clientset,
req := clientset.CoreV1().RESTClient().Post().
Resource("pods").
Name(podName).
Namespace(service.Namespace).
Namespace(common.Namespace).
SubResource("exec").
Param("container", containerName)

Expand Down
7 changes: 4 additions & 3 deletions pkg/client/pod_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ package client
import (
"bufio"

"github.com/dims/hydrophone/pkg/service"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"

"github.com/dims/hydrophone/pkg/common"
)

// List pod resource with the given namespace
func getPodLogs(clientset *kubernetes.Clientset, stream streamLogs) {
podLogOpts := v1.PodLogOptions{
Container: service.ConformanceContainer,
Container: common.ConformanceContainer,
Follow: true,
}

req := clientset.CoreV1().Pods(service.Namespace).GetLogs(service.PodName, &podLogOpts)
req := clientset.CoreV1().Pods(common.Namespace).GetLogs(common.PodName, &podLogOpts)
podLogs, err := req.Stream(ctx)
if err != nil {
stream.errCh <- err
Expand Down
42 changes: 39 additions & 3 deletions pkg/service/args.go → pkg/common/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package service
package common

import (
"flag"
"fmt"
"log"
"os"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

// ArgConfig stores the argument passed when running the program
Expand Down Expand Up @@ -50,6 +54,9 @@ type ArgConfig struct {

// OutputDir is where the e2e.log and junit_01.xml is saved
OutputDir string

// Conformance to indicate whether we want to run conformance tests
ConformanceTests bool
}

func InitArgs() (*ArgConfig, error) {
Expand All @@ -70,12 +77,41 @@ func InitArgs() (*ArgConfig, error) {
flag.IntVar(&cfg.Parallel, "parallel", 1, "number of parallel threads in test framework.")
flag.IntVar(&cfg.Verbosity, "verbosity", 4, "verbosity of test framework.")
flag.StringVar(&cfg.OutputDir, "output-dir", outputDir, "directory for logs.")
flag.BoolVar(&cfg.ConformanceTests, "conformance", false, "run conformance tests.")

flag.Parse()

if cfg.Focus == "" {
return nil, fmt.Errorf("missing --focus argument (use '[Conformance]' to run all conformance tests)")
if cfg.ConformanceTests == (cfg.Focus != "") {
return nil, fmt.Errorf("specify either --conformance or --focus arguments, not both")
}

return &cfg, nil
}

func ValidateArgs(clientSet *kubernetes.Clientset, config *rest.Config, cfg *ArgConfig) {
serverVersion, err := clientSet.ServerVersion()
if err != nil {
log.Fatal("Error fetching server version: ", err)
}

if cfg.ConformanceTests {
cfg.Focus = "\\[Conformance\\]"
}

log.Printf("API endpoint : %s", config.Host)
log.Printf("Server version : %#v", *serverVersion)
log.Printf("Running tests : '%s'", cfg.Focus)
if cfg.Skip != "" {
log.Printf("Skipping tests : '%s'", cfg.Skip)
}
log.Printf("Using conformance image : '%s'", cfg.ConformanceImage)
log.Printf("Using busybox image : '%s'", cfg.BusyboxImage)
log.Printf("Test framework will start '%d' threads and use verbosity '%d'",
cfg.Parallel, cfg.Verbosity)

if _, err := os.Stat(cfg.OutputDir); os.IsNotExist(err) {
if err = os.MkdirAll(cfg.OutputDir, 0755); err != nil {
log.Fatalf("Error creating output directory [%s] : %v", cfg.OutputDir, err)
}
}
}
2 changes: 1 addition & 1 deletion pkg/service/const.go → pkg/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package service
package common

const (
containerImage = "registry.k8s.io/conformance:v1.28.0"
Expand Down
Loading
Loading