-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from claudiolor/master
- Loading branch information
Showing
24 changed files
with
1,504 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha2 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// SnapshotStatus is an enumeration representing the current state of the InstanceSnapshot. | ||
type SnapshotStatus string | ||
|
||
const ( | ||
// Pending -> The snapshot resource has been observed and the | ||
// process is waiting to be started. | ||
Pending SnapshotStatus = "Pending" | ||
// Processing -> The process of creation of the snapshot started. | ||
Processing SnapshotStatus = "Processing" | ||
// Completed -> The snapshot of the instance has been created. | ||
Completed SnapshotStatus = "Completed" | ||
// Failed -> The process of creation of the snapshot failed. | ||
Failed SnapshotStatus = "Failed" | ||
) | ||
|
||
// InstanceSnapshotSpec defines the desired state of InstanceSnapshot. | ||
type InstanceSnapshotSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
// Instance is the reference to the persistent VM instance to be snapshotted. | ||
// The instance should not be running, otherwise it won't be possible to | ||
// steal the volume and extract its content. | ||
Instance GenericRef `json:"instanceRef"` | ||
|
||
// Environment represents the reference to the environment to be snapshotted, in case more are | ||
// associated with the same Instance. If not specified, the first available environment is considered. | ||
Environment GenericRef `json:"environmentRef,omitempty"` | ||
|
||
// +kubebuilder:validation:MinLength=1 | ||
|
||
// ImageName is the name of the image to pushed in the docker registry. | ||
ImageName string `json:"imageName"` | ||
} | ||
|
||
// InstanceSnapshotStatus defines the observed state of InstanceSnapshot. | ||
type InstanceSnapshotStatus struct { | ||
// Phase represents the current state of the Instance Snapshot. | ||
Phase SnapshotStatus `json:"phase"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:resource:shortName="isnap" | ||
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase` | ||
// +kubebuilder:printcolumn:name="ImageName",type=string,JSONPath=`.spec.imageName` | ||
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` | ||
|
||
// InstanceSnapshot is the Schema for the instancesnapshots API. | ||
type InstanceSnapshot struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec InstanceSnapshotSpec `json:"spec,omitempty"` | ||
Status InstanceSnapshotStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// InstanceSnapshotList contains a list of InstanceSnapshot. | ||
type InstanceSnapshotList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []InstanceSnapshot `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&InstanceSnapshot{}, &InstanceSnapshotList{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM alpine:3.13.4 | ||
|
||
# Install the qemu-img useful to convert the image | ||
RUN apk add --update --no-cache qemu-img | ||
|
||
# Copy the entrypoint script | ||
COPY exporter.sh / | ||
|
||
# Run the entrypoint which converts the image and creates the dockerfile | ||
CMD ["/exporter.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/sh | ||
IMG_DIR=/data | ||
OUT_DIR=/img-tmp | ||
IMG_NAME=disk.img | ||
OUT_IMAGE=vm-snapshot.qcow2 | ||
PROG_NAME=$0 | ||
|
||
usage(){ | ||
echo "Usage: $PROG_NAME [-options]" | ||
echo " -d, --img-dir Specify the working directory [DEFAULT=$IMG_DIR]" | ||
echo " -o, --out-dir Specify the output directory [DEFAULT=$OUT_DIR]" | ||
echo " -n, --img-name Specify the name of the image [DEFAULT=$OUT_IMAGE]" | ||
exit 1 | ||
} | ||
|
||
parse_args(){ | ||
while [ "${1:-}" != "" ]; do | ||
case "$1" in | ||
"-d" | "--img-dir") | ||
shift | ||
IMG_DIR=$1 | ||
;; | ||
"-o" | "--out-dir") | ||
shift | ||
OUT_DIR=$1 | ||
;; | ||
"-n" | "--img-name") | ||
shift | ||
IMG_NAME=$1 | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
shift | ||
done | ||
} | ||
|
||
export_img(){ | ||
echo "Converting the image..." | ||
|
||
# Check if output directory exists, if not create it | ||
# and try with the conversion of the image. | ||
mkdir -p "$OUT_DIR" | ||
qemu-img convert -c -f raw -O qcow2 "${IMG_DIR}/${IMG_NAME}" "${OUT_DIR}/${OUT_IMAGE}" | ||
|
||
echo "Creating Dockerfile..." | ||
# Create the Dockerfile. | ||
cat <<EOF > "${OUT_DIR}/Dockerfile" | ||
FROM scratch | ||
ADD ${OUT_IMAGE} /disk/ | ||
EOF | ||
} | ||
|
||
parse_args "$@" | ||
|
||
if export_img; | ||
then | ||
echo "${IMG_DIR}/${IMG_NAME} successully converted" | ||
else | ||
echo "Conversion unsuccessfully completed" | ||
exit 1 | ||
fi |
Oops, something went wrong.