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

Add migration command #870

Merged
merged 4 commits into from Apr 3, 2018

Conversation

shawn-hurley
Copy link
Contributor

@shawn-hurley shawn-hurley commented Apr 2, 2018

Describe what this PR does and why we need it:

We need a way to migrate from ETCD to CRD for openshift ansible

Changes proposed in this pull request

  • create a new command and add to RPM and Images
  • connects to etcd and crd dao's and will convert etcd to crd

Trello: https://trello.com/c/KlFLeFI0

example job.yaml:

---
apiVersion: batch/v1
kind: Job
metadata:
  name: asb-etcd-migration
spec:
  parallelism: 1
  completions: 1
  template:
    metadata:
      name: asb-etcd-migration
    spec:
      containers:
        - name: asb
          image: 'docker.io/shurley/origin-ansible-service-broker:migration'
          imagePullPolicy: Always
          # TODO: Need to update to proper entrypoint once it exists
          command:
            - '/usr/bin/migration'
          args:
            - '-host=asb-etcd.ansible-service-broker.svc'
            - '-ca-file=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt'
            - '-client-cert=/var/run/asb-etcd-auth/client.crt'
            - '-client-key=/var/run/asb-etcd-auth/client.key'
            - '-namespace=ansible-service-broker'
          volumeMounts:
          - name: config-volume
            mountPath: /etc/ansible-service-broker
          - name: asb-tls
            mountPath: /etc/tls/private
          - name: asb-etcd-auth
            mountPath: /var/run/asb-etcd-auth
          env:
            - name: BROKER_CONFIG
              value: /etc/ansible-service-broker/config.yaml
            - name: HTTP_PROXY
              value: ""
            - name: HTTPS_PROXY
              value: ""
      volumes:
        - name: config-volume
          configMap:
            name: broker-config
            items:
              - key: broker-config
                path: config.yaml
        - name: asb-tls
          secret:
            secretName: asb-tls
        - name: asb-etcd-auth
          secret:
            defaultMode: 420
            secretName: broker-etcd-auth-secret
      restartPolicy: Never
      serviceAccount: asb
      serviceAccountName: asb

shawn-hurley and others added 2 commits March 30, 2018 15:27
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 2, 2018
}
crdDao, err = crd.NewDao(options.MigrationNamespace)
if err != nil {
panic(fmt.Sprintf("Unable to connect to crd - %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I don't think this connects to the crd resource. It only creates the client. Maybe a different error message should be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Waiting on more reviews before updating this one

Copy link
Contributor

Choose a reason for hiding this comment

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

@shawn-hurley might also be worth a precheck on the bundle resource. Maybe something like this:

_, err := resources.Bundle.Bundles(c.config.Namespace).List(metav1.ListOptions{})
if err != nil {
....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the bundles already exist it will error and the migration will fail, I think it would be better to attempt to migrate IMO.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

Looking at the code portion now. There are changes to the makefile and spec file needed.

Makefile Outdated
@@ -19,6 +19,7 @@ vendor: ## Install or update project dependencies

broker: $(SOURCES) ## Build the broker
go build -i -ldflags="-s -w" ./cmd/broker
go build -i -ldflags="-s -w" ./cmd/migration
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't feel right. The broker Makefile target is the ACTUAL broker binary. This target says build the broker binary if any of the $(SOURCES) have changed.

I would expect the following:

migration: $(SOURCES) ## Build the migration tool
    go build -i -ldflags="-s -w" ./cmd/migration

@@ -69,6 +70,7 @@ prep-local: ## Prepares the local dev environment

build-image: ## Build a docker image with the broker binary
env GOOS=linux go build -i -ldflags="-s -s" -o ${BUILD_DIR}/broker ./cmd/broker
env GOOS=linux go build -i -ldflags="-s -s" -o ${BUILD_DIR}/migration ./cmd/migration
Copy link
Contributor

Choose a reason for hiding this comment

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

🆗

@@ -178,6 +179,7 @@ rm -rf src
%install
install -d -p %{buildroot}%{_bindir}
install -p -m 755 broker %{buildroot}%{_bindir}/asbd
install -p -m 755 migration %{buildroot}%{_bindir}/migration
Copy link
Contributor

Choose a reason for hiding this comment

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

you need a line under the %files section for the migration

%{_bindir}/migration
``

Similar to `asbd`
https://github.com/shawn-hurley/ansible-service-broker/blob/11b100561dc09b374a2a76aef5e99a0364e77b8d/ansible-service-broker.spec#L283

@@ -43,6 +43,7 @@ WORKDIR /go/src/github.com/openshift/ansible-service-broker

RUN go build -i -ldflags="-s -w" ./cmd/broker
RUN mv broker /usr/bin/asbd
RUN mv migration /usr/bin/migration
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@@ -23,6 +23,7 @@ RUN mkdir /var/log/ansible-service-broker \

COPY entrypoint.sh /usr/bin/
COPY broker /usr/bin/asbd
COPY migration /usr/bin/migration
Copy link
Contributor

Choose a reason for hiding this comment

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

💯


import (
"encoding/json"
"flag"
Copy link
Contributor

Choose a reason for hiding this comment

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

stock flag is probably okay for this. But it is weird to have a different one than we are using for the broker:

 "github.com/jessevdk/go-flags"

Not a blocker just pointing it out.

@jmrodri
Copy link
Contributor

jmrodri commented Apr 2, 2018

The rest looks okay.

@jmrodri
Copy link
Contributor

jmrodri commented Apr 2, 2018

Add migration to the clean target @rm -f broker migration. Once that is done, merge it yourself.

@jmrodri jmrodri added the build label Apr 2, 2018
@shawn-hurley shawn-hurley merged commit adfa7f4 into openshift:master Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants