Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KET / Kind e2e Test framework

riita10069
October 21, 2021

KET / Kind e2e Test framework

https://mercari.connpass.com/event/227024/
で発表しました。

アーカイブはYouTubeから見れます!
https://www.youtube.com/watch?v=u5Eq-uJBvzg

riita10069

October 21, 2021
Tweet

More Decks by riita10069

Other Decks in Technology

Transcript

  1. #VJME 4LB ff PME ,VCFOFUFTDMVTUFS %FQMPZ 7PMVNFECH *OJU$POUBJOFS %PXOMPBE%FMWF $VTUPN$POUSPMMFS

    $VTUPN$POUSPMMFS $VTUPN$POUSPMMFS https://github.com/go-delve/delve
  2. type ClientSet struct { ClientGo *k8s.ClientG o Kubectl *kubectl.Kubect l

    Kind *kind.Kin d Skaffold *skaffold.Skaffol d } err := kubectl.ApplyAllManifest(ctx, tt.fixture.manifestPaths, false) _, err = kubectl.WaitAResource ( ctx , "deploy" , types.NamespacedName { Namespace: "CONTROLLER_NAMESPACE" , Name: "CONTROLLER_NAME" , } , )
  3. func (k *Kubectl) ApplyFile(ctx context.Context, filePath string) error { args

    := []string { "apply" , "-f" , filePath , } err := k.Execute(ctx, args ) if err != nil { return err } return ni l } Self-created Commands!!
  4. for _, tt := range tests { tt := t

    t t.Run(tt.name, func(t *testing.T) { ctx := context.Background( ) err := kubectl.ApplyAllManifest(ctx, tt.fixture.manifestPaths, false ) for _, expect := range tt.res.A.Items { // check expec t } err = kubectl.DeleteAllManifest(ctx, tt.fixture.manifestPaths, true ) } ) } 1st, Create resources “declaratively” Maybe notify informer of the change. 2nd, Make sure the behavior of the Controller. 3rd, Restore the state of the resource.
  5. func Start(ctx context.Context, options ...Option) (*ClientSet, error) { ket :=

    NewKET( ) for _, option := range options { err := option(ket ) if err != nil { return nil, fmt.Errorf("failed to run options: %w", err ) } } cliSet := &ClientSet{ } kind := kind.NewKind(ket.kindVersion, ket.kubernetesVersion, ket.binDir, ket.kubeconfigPath ) cliSet.Kind = kin d err := kind.DeleteCluster(ctx, ket.kindClusterName ) if err != nil { return nil, fmt.Errorf("failed to delete kind cluster %s: %w", ket.kindClusterName, err ) } err = kind.CreateCluster(ctx, ket.kindClusterName ) if err != nil { return nil, fmt.Errorf("failed to create kind cluster %s: %w", ket.kindClusterName, err ) } First, create a Kind cluster.
  6. clientGo, err := k8s.NewClientGo(ket.kubeconfigPath ) if err != nil {

    return nil, fmt.Errorf("failed to create client-go: %w", err ) } cliSet.ClientGo = clientG o kubectl := kubectl.NewKubectl(ket.kubernetesVersion, ket.binDir, ket.kubeconfigPath ) cliSet.Kubectl = kubect l err = kubectl.UseContext(ctx, ket.kindClusterName ) if err != nil { return nil, fmt.Errorf("failed to use context: %w", err ) } err = kubectl.ApplyKustomize(ctx, ket.crdKustomizePath ) if err != nil { return nil, fmt.Errorf("failed to apply crd yaml: %w", err ) } if ket.useSkaffold { skaffold := skaffold.NewSkaffold(ket.skaffoldVersion, ket.binDir, ket.kubeconfigPath ) cliSet.Skaffold = skaffol d err = skaffold.Run(ctx, ket.skaffoldYaml, false ) if err != nil { return nil, fmt.Errorf("failed to skaffold run: %w", err ) } } return cliSet, ni l } Second, Apply CRDs and some Resources. Third, Skaffold run.(if you use Skaffold)