Skip to content

Commit

Permalink
feat: update clustertasks to integrate with UI
Browse files Browse the repository at this point in the history
The purpose of this change is to align with what is described in
konveyor/enhancements#59 only to the extent
that a demonstration of "Stateless App Migration" is possible.

This will likely break our examples so it should not be merged into
'main' until stabilized.
  • Loading branch information
djzager authored and pranavgaikwad committed Mar 29, 2022
1 parent c93a812 commit 1592b89
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 65 deletions.
18 changes: 4 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
FROM registry.ci.openshift.org/openshift/release:golang-1.16 as crane-bin

FROM registry.ci.openshift.org/openshift/release:golang-1.17 as crane-bin
ENV GOFLAGS "-mod=mod"
WORKDIR /go/src/github.com/konveyor/crane

RUN git clone https://github.com/konveyor/crane.git .
RUN go build -a -o /build/crane main.go

FROM registry.access.redhat.com/ubi8/ubi:latest

COPY --from=crane-bin /build/crane /crane
RUN /crane plugin-manager add OpenshiftPlugin

# Helpful tools
# TODO(djzager): Determine want can stay and what must go
COPY --from=crane-bin /build/crane /usr/bin/crane
RUN crane plugin-manager add OpenshiftPlugin
RUN curl -sL "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz" | \
tar xvzf - -C /usr/bin/ oc kubectl
RUN curl -sL "https://github.com/mikefarah/yq/releases/download/v4.16.1/yq_linux_amd64.tar.gz" | \
tar xvzf - -C /usr/bin/ ./yq_linux_amd64 && \
mv /usr/bin/yq_linux_amd64 /usr/bin/yq
RUN curl -sL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.4.1/kustomize_v4.4.1_linux_amd64.tar.gz" | \
tar xvzf - -C /usr/bin/ kustomize
RUN dnf -y install git

ENTRYPOINT ["/crane"]
ENTRYPOINT ["/usr/bin/crane"]
5 changes: 1 addition & 4 deletions manifests/clustertasks/crane-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ kind: ClusterTask
metadata:
name: crane-apply
annotations:
migration.openshift.io/run-after: "crane-transform"
description: |
This is where a really long-form explanation of what is happening in
crane-apply ClusterTask would go.
spec:
steps:
- name: crane-apply
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
# TODO(djzager): Should convert this to command & args
/crane apply \
--export-dir=$(workspaces.export.path) \
--transform-dir=$(workspaces.transform.path) \
--output-dir=$(workspaces.apply.path)
find $(workspaces.apply.path)
# https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md#using-workspaces-in-tasks
workspaces:
- name: export
description: |
Expand Down
25 changes: 13 additions & 12 deletions manifests/clustertasks/crane-export.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ kind: ClusterTask
metadata:
name: crane-export
annotations:
migration.openshift.io/placeholder: "true"
description: |
Export all of the resources from a given cluster's namespace.
Discover, and write to disk, all of the resources from a specified
cluster's namespace.
spec:
params:
- name: src-context
- name: context
type: string
description: |
The name of the context from kubeconfig representing the source
Expand All @@ -17,24 +17,25 @@ spec:
You can get this information in your current environment using
`kubectl config get-contexts` to describe your one or many
contexts.
- name: src-namespace
default: ""
- name: namespace
type: string
description: |
The source cluster namespace from which to export resources.
The namespace from which to export resources.
default: ""
steps:
- name: crane-export
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
/crane export \
--context=$(params.src-context) \
--namespace=$(params.src-namespace) \
--export-dir=$(workspaces.export.path)
--context="$(params.context)" \
--namespace="$(params.namespace)" \
--export-dir="$(workspaces.export.path)"
# Do this so we have some breadcrumbs in case our demo blows up
find $(workspaces.export.path)
env:
- name: KUBECONFIG
value: $(workspaces.kubeconfig.path)/config
value: $(workspaces.kubeconfig.path)/kubeconfig
workspaces:
- name: export
description: |
Expand All @@ -43,4 +44,4 @@ spec:
mountPath: /var/crane/export
- name: kubeconfig
description: |
The kubeconfig for accessing the source cluster.
The kubeconfig for accessing the cluster.
50 changes: 50 additions & 0 deletions manifests/clustertasks/crane-kubeconfig-generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: crane-kubeconfig-generator
annotations:
description: |
This Task is responsible for taking a secret with keys `url` and `token`,
logging into the cluster using `oc login`, renaming the context, and
saving the result in the kubeconfig workspace.
The idea is that subsequent Tasks in a Pipeline or PipelineRun could
reference this task first to populate a kubeconfig based on cluster
auth stored in a secret.
spec:
params:
- name: cluster-secret
type: string
description: |
The name of the secret holding cluster API Server URL and Token.
- name: context-name
type: string
description: |
The name to give the context.
steps:
- name: crane-export
image: quay.io/djzager/crane-runner:alpha
script: |
export KUBECONFIG=$(workspaces.kubeconfig.path)/kubeconfig
set +x
oc login --server=$CLUSTER_URL --token=$CLUSTER_TOKEN
set -x
kubectl config rename-context "$(kubectl config current-context)" "$(params.context-name)"
env:
- name: CLUSTER_URL
valueFrom:
secretKeyRef:
name: $(params.cluster-secret)
key: url
- name: CLUSTER_TOKEN
valueFrom:
secretKeyRef:
name: $(params.cluster-secret)
key: token
workspaces:
- name: kubeconfig
readOnly: false
description: |
Where the generated kubeconfig will be saved.
51 changes: 51 additions & 0 deletions manifests/clustertasks/crane-kustomize-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: crane-kustomize-init
annotations:
description: "Initialize a kustomization.yaml for the manifests generated in crane-apply. \n"
spec:
params:
- name: source-namespace
type: string
description: Source namespace from export.
- name: labels
type: string
description: Add one or more labels
default: ""
- name: name-prefix
type: string
description: Set the namePrefix field in the kustomization file.
default: ""
- name: namespace
type: string
description: Sets the value of the namespace field in the kustomization file.
default: ""
- name: name-suffix
type: string
description: Set the nameSuffix field in the kustomization file.
default: ""
steps:
- name: kustomize-namespace
image: quay.io/djzager/crane-runner:alpha
script: |
# Copy apply resources into kustomize workspace
cp -r "$(workspaces.apply.path)/resources/$(params.source-namespace)/." "$(workspaces.kustomize.path)"
pushd "$(workspaces.kustomize.path)"
kustomize init --autodetect \
--labels "$(params.labels)" \
--nameprefix "$(params.name-prefix)" \
--namespace "$(params.namespace)" \
--nameSuffix "$(params.name-suffix)"
kustomize build
popd
tree "$(workspaces.kustomize.path)"
workspaces:
- name: apply
description: |
This is the folder where the results from crane-apply are stored.
mountPath: /var/crane/apply
- name: kustomize
description: |
This is where the kustomize related manifests will be saved.
2 changes: 1 addition & 1 deletion manifests/clustertasks/crane-transfer-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
The name of the networking endpoint to be used for ingress traffic in the destination cluster
steps:
- name: crane-transfer-pvc
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
/crane transfer-pvc \
--destination-context=$(params.dest-context) \
Expand Down
24 changes: 15 additions & 9 deletions manifests/clustertasks/crane-transform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ metadata:
name: crane-transform
annotations:
description: |
This is where a really long-form explanation of what is happening in
crane-transform ClusterTask would go.
Take the resources from a `crane-export` and generate JSON patches to
remove
spec:
params:
- name: optional-flags
type: string
description: |
Comma separated list of `flag-name=value` pairs. These flags with values
will be passed into all plugins that are executed in the transform
operation.
default: ""
steps:
- name: crane-transform
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
/crane version
/crane transform \
--ignored-patches-dir=$(workspaces.ignored-patches.path) \
--flags-file=$(workspaces.craneconfig.path) \
--export-dir=$(workspaces.export.path) \
--ignored-patches-dir="$(workspaces.ignored-patches.path)" \
--flags-file="$(workspaces.craneconfig.path)" \
--optional-flags="$(params.optional-flags)" \
--export-dir="$(workspaces.export.path)" \
--transform-dir=$(workspaces.transform.path)
# Do this so we have some breadcrumbs in case our demo blows up
find $(workspaces.transform.path)
if [ "$(workspaces.ignored-patches.bound)" == "true" ]; then
find $(workspaces.ignored-patches.path)
fi
# https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md#using-workspaces-in-tasks
workspaces:
- name: export
description: |
Expand Down
2 changes: 1 addition & 1 deletion manifests/clustertasks/git-init-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
description: Git user.email
steps:
- name: git-init-push
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
git config --global user.email "$(params.user-email)"
git config --global user.name "$(params.user-name)"
Expand Down
2 changes: 1 addition & 1 deletion manifests/clustertasks/kubectl-apply-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
description: The context from the kubeconfig that represents the destination cluster.
steps:
- name: kubectl-apply
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
# TODO(djzager): come up with better way to use internal ip
kubectl --context $(params.dest-context) config view --flatten --minify > kubeconfig
Expand Down
29 changes: 14 additions & 15 deletions manifests/clustertasks/kubectl-apply-kustomize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ metadata:
description: |
Run kubectl apply -k against a kustomize directory.
spec:
# These are all required parameters to the task when we write a Pipeline using
# this task, we must ensure that these parameters are supplied.
params:
- name: dest-context
- name: context
type: string
description: The context from the kubeconfig that represents the destination cluster.
default: ""
steps:
- name: kubectl-apply
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
# TODO(djzager): come up with better way to use internal ip
kubectl --context $(params.dest-context) config view --flatten --minify > kubeconfig
yq eval --inplace --exit-status '.clusters[0].cluster.server |= "https://kubernetes.default.svc"' kubeconfig
export KUBECONFIG=$(pwd)/kubeconfig
if [ "$(workspaces.kubeconfig.bound)" == "true" ] ; then
export KUBECONFIG="$(workspaces.kubeconfig.path)/kubeconfig"
fi
kubectl apply -k $(workspaces.kustomize.path)/
env:
- name: KUBECONFIG
value: $(workspaces.kubeconfig.path)/config
# https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md#using-workspaces-in-tasks
kubectl --context="$(params.context)" apply -k "$(workspaces.kustomize.path)"
workspaces:
- name: kustomize
description: |
This is the folder storing a kustomization file to be applied.
This is the folder storing a kustomization.yaml file to be applied.
- name: kubeconfig
description: |
The user's kubeconfig
The user's kubeconfig. Otherwise, will just rely on mounted credentials
to access the cluster's API server.
See https://kubernetes.io/docs/tasks/run-application/access-api-from-pod
for more details.
optional: true
2 changes: 1 addition & 1 deletion manifests/clustertasks/kubectl-scale-down.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
The resource to be scaled down in type/name format (ie. deployment/mysql or rc/foo)
steps:
- name: kubectl-scale-down
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
kubectl scale --context $(params.context) --namespace $(params.namespace) --replicas=0 $(params.type-name-resource)
env:
Expand Down
16 changes: 10 additions & 6 deletions manifests/clustertasks/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ kind: Kustomization
commonLabels:
app: crane-runner
resources:
- crane-apply.yaml
- crane-kubeconfig-generator.yaml
- crane-export.yaml
- crane-transfer-pvc.yaml
- crane-transform.yaml
- git-init-push.yaml
- kubectl-apply-files.yaml
- crane-apply.yaml
- crane-kustomize-init.yaml
- kubectl-apply-kustomize.yaml
- kubectl-scale-down.yaml
- kustomize-namespace.yaml
# - crane-transfer-pvc.yaml
# - git-init-push.yaml
# - kubectl-apply-files.yaml
# - kubectl-scale-down.yaml
# - kustomize-namespace.yaml
spec:
steps: []
2 changes: 1 addition & 1 deletion manifests/clustertasks/kustomize-namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
description: The namespace we are importing to.
steps:
- name: kustomize-namespace
image: quay.io/konveyor/crane-runner:latest
image: quay.io/djzager/crane-runner:alpha
script: |
# Make common base directory
kustomize_base_dir="$(workspaces.kustomize.path)/base"
Expand Down

0 comments on commit 1592b89

Please sign in to comment.