Skip to content

Rewrite travis script in golang #346

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

Merged
merged 38 commits into from
Jul 19, 2018
Merged

Conversation

AlexNPavel
Copy link
Contributor

This PR changes some of the travis bash scripting to golang instead using the client-go kubernetes library, which also allows us to verify that the tests are passing correctly without having to manually check logs.

test/test.sh Outdated
make install
echo "Building memcached-example tester"
cd test
ln -s ../vendor vender
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. Plus we can probably remove this.

test/main.go Outdated
FieldSelector: "",
}

outerloop:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably make the retry-until-true-or-timeout check into a util and use that for all of our checks.
See how the etcd-operator does it:
https://github.com/coreos/etcd-operator/blob/master/pkg/util/retryutil/retry_util.go
https://github.com/coreos/etcd-operator/blob/master/test/e2e/e2eutil/wait_util.go#L255-L277

We can add a similar retry-timeout utility to the sdk.

test/main.go Outdated
log.Fatalf("Deployment %s did not produce %d available replicas.\n", name, replicas)
}
count++
deployments, err := api.Deployments("").List(listOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can query the Deployment directly:

dep, err := api.Deployments().Get("memcached-operator", metav1.GetOptions{})

test/main.go Outdated
fmt.Printf("Waiting for full availability of %s deployment (%d/%d)\n", name, deployment.Status.AvailableReplicas, replicas)
// printDeployments(deployments)
time.Sleep(time.Second * 1)
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the retryutil that we end up using, we can change this to a retry interval of 5s with a total of 6 retries. 1 second retries are too frequent and a total of 30s should be more than enough for the deployment to become ready.

test/main.go Outdated

file.Close()

// apply/create example-memcached deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're actually creating the Memcached Custom Resource(CR). Not the deployment itself.
So you can update or remove this comment.

test/main.go Outdated

deploymentReplicaCheck(api, "example-memcached", 3, 60)

// update deployment to 4 replicas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. We're updating the CR size to 4. Not the deployment.

test/main.go Outdated

file.Close()

// apply updated example-memcached deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this comment.

test/main.go Outdated
if err != nil {
log.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this from clientset to kubeclient.
And also we can remove line 35

api := clientset.AppsV1()

and instead just use the full form

kubeclient.AppsV1().Deployments().Get()..

wherever we need it so it's more clear.

We should move away from the dependency on the kubectl binary.
This commit removes that dependency for the most difficult of the
situations (updating a custom resource). Commits removing the rest
will come soon.
Some of the replacements for the kubectl command usage are a bit
cumbersome and not very clean, but it works for now. It should be
simplified more in the future (especially for things like group
and apiversion, which can be inferred from the yaml files)
This also moves back the couple of commands before the test gets
built into the travis script
@AlexNPavel AlexNPavel changed the title [DO NOT MERGE] Rewrite travis script in golang [WIP] Rewrite travis script in golang Jul 19, 2018
// See the License for the specific language governing permissions and
// limitations under the License.

package retryutil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move pkg/util/retryutil/retry_util.go to test/e2e/e2eutil/retry_util.go since
it's only being used by the e2e test for now.

func DeploymentReplicaCheck(t *testing.T, kubeclient *kubernetes.Clientset, namespace, name string, replicas, retries int) error {
err := retryutil.Retry(retryInterval, retries, func() (done bool, err error) {
deployment, err := kubeclient.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{IncludeUninitialized: true})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only retry if the Deployment was not found(i.e not yet created). For any other error we should just return the error:

import (
    apierrors "k8s.io/apimachinery/pkg/api/errors"
)
...

if err != nil && apierrors.IsNotFound(err) {
    ....
    return false, nil
} else {
    return false, err
}

This also updates DeploymentReplicaCheck slightly to fail on
errors that are not "NotFound" errors
@hasbro17 hasbro17 changed the title [WIP] Rewrite travis script in golang Rewrite travis script in golang Jul 19, 2018
@hasbro17
Copy link
Contributor

LGTM. Great work!

We can do more refactoring and general clean up in follow up PRs.
And we can try to support running the e2e test locally by detecting if TRAVIS_BUILD_DIR env is unset so we can just the GOPATH location directly and actually push the operator image to a user specified repo.

@hasbro17 hasbro17 merged commit 57feeea into operator-framework:master Jul 19, 2018
@AlexNPavel AlexNPavel deleted the travis branch July 20, 2018 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants