Skip to content

Commit

Permalink
Crane UI + Tekton Integration Enhancement Updates (#35)
Browse files Browse the repository at this point in the history
* feat: update clustertasks to integrate with UI

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.

* chore: move kustomize manifests to config

* chore: update examples based on new paths

Now that all of the ClusterTasks have been updated based on
[the tekton ui integration enhancement](https://github.com/konveyor/enhancements/tree/master/enhancements/crane-2.0/tekton-ui-integration),
and some issues were discovered with handling of defaults, this commit
attempts to make all of the changes functional. That means, after this
commit all examples should integrate with the ClusterTasks as
implemented.

* chore: update hack dir

* chore: remove personal container image references

* docs: update descriptions to be more meaningful
  • Loading branch information
djzager committed Mar 18, 2022
1 parent cc9a570 commit f5814af
Show file tree
Hide file tree
Showing 29 changed files with 354 additions and 271 deletions.
35 changes: 18 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
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
FROM registry.redhat.io/openshift4/ose-cli:latest as cli-bin
COPY ./config /config
RUN curl -sL "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert" > /usr/local/bin/kubectl-convert && \
chmod +x /usr/local/bin/kubectl-convert
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/local/bin/ kustomize
RUN kustomize build /config/default > /deploy.yaml

FROM registry.redhat.io/ubi8/ubi:latest
COPY --from=crane-bin /build/crane /usr/local/bin/crane
COPY --from=cli-bin /usr/bin/oc /usr/bin/oc
COPY --from=cli-bin /usr/bin/kubectl /usr/bin/kubectl
COPY --from=cli-bin /usr/local/bin/kustomize /usr/local/bin/kustomize
COPY --from=cli-bin /usr/local/bin/kubectl-convert /usr/local/bin/kubectl-convert
COPY --from=cli-bin /deploy.yaml /deploy.yaml

COPY --from=crane-bin /build/crane /crane
RUN /crane plugin-manager add OpenshiftPlugin
RUN crane plugin-manager add OpenShiftPlugin --version v0.0.3

# Helpful tools
# TODO(djzager): Determine want can stay and what must go
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/local/bin/crane"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ 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.
Generate YAML by applying transformations to the exported resources.
spec:
steps:
- name: crane-apply
image: quay.io/konveyor/crane-runner:latest
script: |
# TODO(djzager): Should convert this to command & args
/crane apply \
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
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,23 @@ 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
- name: namespace
type: string
description: |
The source cluster namespace from which to export resources.
The namespace from which to export resources.
steps:
- name: crane-export
image: quay.io/konveyor/crane-runner:latest
script: |
/crane export \
--context=$(params.src-context) \
--namespace=$(params.src-namespace) \
--export-dir=$(workspaces.export.path)
crane export \
--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 +42,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 config/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/konveyor/crane-runner:latest
script: |
export KUBECONFIG=$(workspaces.kubeconfig.path)/kubeconfig
set +x
oc login --insecure-skip-tls-verify --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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: ClusterTask
metadata:
name: kubectl-scale-down
annotations:
migration.openshift.io/placeholder: "true"
description: |
Scale resource down using kubectl scale.
spec:
Expand All @@ -12,22 +11,24 @@ spec:
type: string
description: |
Context to use when scaling down resources
default: ""
- name: namespace
type: string
description: |
Namespace to use when scaling down resources
- name: type-name-resource
default: ""
- name: resource-type
type: string
description: |
The resource to be scaled down in type/name format (ie. deployment/mysql or rc/foo)
The resource type to be scaled down.
steps:
- name: kubectl-scale-down
image: quay.io/konveyor/crane-runner:latest
script: |
kubectl scale --context $(params.context) --namespace $(params.namespace) --replicas=0 $(params.type-name-resource)
kubectl scale --context "$(params.context)" --namespace "$(params.namespace)" --replicas=0 "$(params.resource-type)" --all
env:
- name: KUBECONFIG
value: $(workspaces.kubeconfig.path)/config
value: $(workspaces.kubeconfig.path)/kubeconfig
workspaces:
- name: kubeconfig
description: |
Expand Down
52 changes: 52 additions & 0 deletions config/clustertasks/crane-kustomize-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: crane-kustomize-init
annotations:
description: |
Initialize a kustomization.yaml for the manifests generated in crane-apply.
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/konveyor/crane-runner:latest
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
find "$(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.
89 changes: 89 additions & 0 deletions config/clustertasks/crane-transfer-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: crane-transfer-pvc
annotations:
description: |
Sync's a single PVC from source to destination cluster
spec:
params:
- name: source-context
type: string
description: |
The name of the context from kubeconfig representing the source
cluster.
You can get this information in your current environment using
`kubectl config get-contexts` to describe your one or many
contexts.
- name: source-namespace
type: string
description: |
The source cluster namespace in which pvc is synced.
- name: source-pvc-name
type: string
description: |
The name of the pvc to be synced from source cluster.
- name: dest-context
type: string
description: |
The name of the context from kubeconfig representing the destination
cluster.
You can get this information in your current environment using
`kubectl config get-contexts` to describe your one or many
contexts.
- name: dest-pvc-name
type: string
description: |
The name to give pvc in destination cluster.
default: ""
- name: dest-namespace
type: string
description: |
The source cluster namespace in which pvc is synced.
default: ""
- name: dest-storage-class-name
type: string
description: |
The name of the storage class to use in the destination cluster.
default: ""
- name: dest-pvc-capacity
type: string
description: |
Size of the destination volume to create.
default: ""
- name: endpoint-type
type: string
description: |
The name of the networking endpoint to be used for ingress traffic in the destination cluster
default: ""
steps:
- name: crane-transfer-pvc
image: quay.io/konveyor/crane-runner:latest
script: |
crane transfer-pvc \
--source-context=$(params.source-context) \
--destination-context=$(params.dest-context) \
--pvc-name $(params.source-pvc-name):$(params.dest-pvc-name) \
--pvc-namespace $(params.source-namespace):$(params.dest-namespace) \
--dest-pvc-storage-class-name $(params.dest-storage-class-name) \
--pvc-requests-storage $(params.dest-pvc-capacity) \
--endpoint $(params.endpoint-type)
env:
- name: KUBECONFIG
value: $(workspaces.kubeconfig.path)/kubeconfig
- name: DEST_PVC_NAME
value: $(params.dest-pvc-name)
- name: DEST_NAMESPACE
value: $(params.dest-namespace)
- name: DEST_STORAGE_CLASS_NAME
value: $(params.dest-storage-class-name)
- name: DEST_PVC_CAPACITY
value: $(params.dest-pvc-capacity)
- name: ENDPOINT_TYPE
value: $(params.endpoint-type)
workspaces:
- name: kubeconfig
description: |
The kubeconfig for accessing the source cluster.
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ 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 cluster specific metadata and status information. If optional-flags
are defined, they will be passed to all enabled plugins.
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
script: |
/crane version
/crane transform \
--ignored-patches-dir=$(workspaces.ignored-patches.path) \
--flags-file=$(workspaces.craneconfig.path) \
--export-dir=$(workspaces.export.path) \
crane transform \
--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

0 comments on commit f5814af

Please sign in to comment.