diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..f88c3ecf --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,82 @@ +name: Build-Test + +on: + push: + branches: + - controller-v2 + pull_request: + branches: + - controller-v2 + release: + types: + - published + +jobs: + build: + name: CI # Lint, Test, Codecov, Docker build & Push + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.32 + args: --timeout 2m + + - name: Get kubebuilder + env: + version: 1.0.8 # latest stable version + arch: amd64 + run: | + # download the release + curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_linux_${arch}.tar.gz" + # extract the archive + tar -zxvf kubebuilder_${version}_linux_${arch}.tar.gz + mv kubebuilder_${version}_linux_${arch} kubebuilder && sudo mv kubebuilder /usr/local/ + # update your PATH to include /usr/local/kubebuilder/bin + export PATH=$PATH:/usr/local/kubebuilder/bin + - name: Run Tests + run: make test + + - name: Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.txt # optional + flags: unittests # optional + name: codecov-umbrella # optional + fail_ci_if_error: true # optional (default = false) + + - name: Docker build + if: github.event_name == 'pull_request' || (github.repository != 'keikoproj/upgrade-manager' && github.event_name == 'push') + run: make docker-build + + - name: Build and push Docker image with tag controller-v2 # only on pushes to keikoproj/upgrade-manager + if: github.event_name == 'push' && github.repository == 'keikoproj/upgrade-manager' + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: keikoproj/rolling-upgrade-controller + tags: controller-v2 + + - name: Build and push Docker image with tag latest # only on releases of keikoproj/upgrade-manager + if: github.event_name == 'release' && github.repository == 'keikoproj/upgrade-manager' + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: keikoproj/rolling-upgrade-controller + tags: latest + + - name: Build and push Docker image with tag git-tag # only on releases of keikoproj/upgrade-manager + if: github.event_name == 'release' && github.repository == 'keikoproj/upgrade-manager' + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: keikoproj/rolling-upgrade-controller + tag_with_ref: true diff --git a/Makefile b/Makefile index 72bcec3d..628d8c7d 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ ENVTEST_ASSETS_DIR=$(shell pwd)/testbin test: generate fmt vet manifests mkdir -p ${ENVTEST_ASSETS_DIR} test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile coverage.txt + go tool cover -html=./coverage.txt -o cover.html # Build manager binary manager: generate fmt vet diff --git a/controllers/helpers_test.go b/controllers/helpers_test.go index 99ba610d..b975a7e7 100644 --- a/controllers/helpers_test.go +++ b/controllers/helpers_test.go @@ -158,13 +158,10 @@ type MockAutoscalingGroup struct { } type launchTemplateInfo struct { - data *ec2.ResponseLaunchTemplateData name *string } type MockEC2 struct { ec2iface.EC2API - awsErr awserr.Error - reservations []*ec2.Reservation LaunchTemplates map[string]*launchTemplateInfo } diff --git a/controllers/providers/kubernetes/utils.go b/controllers/providers/kubernetes/utils.go index 2e557416..abeddd92 100644 --- a/controllers/providers/kubernetes/utils.go +++ b/controllers/providers/kubernetes/utils.go @@ -87,12 +87,10 @@ func GetKubernetesLocalConfig() (*rest.Config, error) { } func SelectNodeByInstanceID(instanceID string, nodes []*corev1.Node) *corev1.Node { - if nodes != nil { - for _, node := range nodes { - nodeID := GetNodeInstanceID(node) - if strings.EqualFold(instanceID, nodeID) { - return node - } + for _, node := range nodes { + nodeID := GetNodeInstanceID(node) + if strings.EqualFold(instanceID, nodeID) { + return node } } return nil diff --git a/controllers/rollingupgrade_controller.go b/controllers/rollingupgrade_controller.go index 37d196ef..b57dbd39 100644 --- a/controllers/rollingupgrade_controller.go +++ b/controllers/rollingupgrade_controller.go @@ -78,7 +78,7 @@ func (r *RollingUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Reque err := r.Get(ctx, req.NamespacedName, rollingUpgrade) if err != nil { if kerrors.IsNotFound(err) { - r.AdmissionMap.Delete(fmt.Sprintf("%s", req.NamespacedName)) + r.AdmissionMap.Delete(req.NamespacedName.String()) r.Info("rolling upgrade resource not found, deleted object from admission map", "name", req.NamespacedName) return ctrl.Result{}, nil } @@ -113,7 +113,7 @@ func (r *RollingUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Reque ) // at any given point in time, there should be only one reconcile operation running per ASG - if _, present := r.ReconcileMap.LoadOrStore(rollingUpgrade.NamespacedName(), scalingGroupName); present == true { + if _, present := r.ReconcileMap.LoadOrStore(rollingUpgrade.NamespacedName(), scalingGroupName); present { r.Info("a reconcile operation is already in progress for this ASG, requeuing", "scalingGroup", scalingGroupName, "name", rollingUpgrade.NamespacedName()) return ctrl.Result{RequeueAfter: v1alpha1.DefaultRequeueTime}, nil } @@ -136,7 +136,7 @@ func (r *RollingUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Reque } // store the rolling upgrade in admission map - if _, present := r.AdmissionMap.LoadOrStore(rollingUpgrade.NamespacedName(), scalingGroupName); present == false { + if _, present := r.AdmissionMap.LoadOrStore(rollingUpgrade.NamespacedName(), scalingGroupName); !present { r.Info("admitted new rolling upgrade", "scalingGroup", scalingGroupName, "update strategy", rollingUpgrade.Spec.Strategy, "name", rollingUpgrade.NamespacedName()) r.CacheConfig.FlushCache("autoscaling") } else {