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

Remove minio job because this is handled in the kotsadm-api startup now #138

Merged
merged 1 commit into from Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 0 additions & 52 deletions pkg/kotsadm/minio.go
Expand Up @@ -15,12 +15,6 @@ func getMinioYAML(namespace string) (map[string][]byte, error) {
docs := map[string][]byte{}
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)

var configMap bytes.Buffer
if err := s.Encode(minioConfigMap(namespace), &configMap); err != nil {
return nil, errors.Wrap(err, "failed to marshal minio config map")
}
docs["minio-configmap.yaml"] = configMap.Bytes()

var statefulset bytes.Buffer
if err := s.Encode(minioStatefulset(namespace), &statefulset); err != nil {
return nil, errors.Wrap(err, "failed to marshal minio statefulset")
Expand All @@ -33,12 +27,6 @@ func getMinioYAML(namespace string) (map[string][]byte, error) {
}
docs["minio-service.yaml"] = service.Bytes()

var job bytes.Buffer
if err := s.Encode(minioJob(namespace), &job); err != nil {
return nil, errors.Wrap(err, "failed to marshal minio job")
}
docs["minio-job.yaml"] = job.Bytes()

return docs, nil
}

Expand All @@ -47,10 +35,6 @@ func ensureMinio(deployOptions DeployOptions, clientset *kubernetes.Clientset) e
return errors.Wrap(err, "failed to ensure minio secret")
}

if err := ensureMinioConfigMap(deployOptions.Namespace, clientset); err != nil {
return errors.Wrap(err, "failed to ensure minio configmap")
}

if err := ensureMinioStatefulset(deployOptions.Namespace, clientset); err != nil {
return errors.Wrap(err, "failed to ensure minio statefulset")
}
Expand All @@ -59,26 +43,6 @@ func ensureMinio(deployOptions DeployOptions, clientset *kubernetes.Clientset) e
return errors.Wrap(err, "failed to ensure minio service")
}

if err := ensureMinioJob(deployOptions.Namespace, clientset); err != nil {
return errors.Wrap(err, "failed to ensure minio job")
}

return nil
}

func ensureMinioConfigMap(namespace string, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().ConfigMaps(namespace).Get("kotsadm-minio", metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get existing config map")
}

_, err := clientset.CoreV1().ConfigMaps(namespace).Create(minioConfigMap(namespace))
if err != nil {
return errors.Wrap(err, "failed to create configmap")
}
}

return nil
}

Expand Down Expand Up @@ -113,19 +77,3 @@ func ensureMinioService(namespace string, clientset *kubernetes.Clientset) error

return nil
}

func ensureMinioJob(namespace string, clientset *kubernetes.Clientset) error {
_, err := clientset.BatchV1().Jobs(namespace).Get("kotsadm-minio", metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get existing job")
}

_, err := clientset.BatchV1().Jobs(namespace).Create(minioJob(namespace))
if err != nil {
return errors.Wrap(err, "failed to create job")
}
}

return nil
}
177 changes: 0 additions & 177 deletions pkg/kotsadm/minio_objects.go
Expand Up @@ -2,107 +2,12 @@ package kotsadm

import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

func minioConfigMap(namespace string) *corev1.ConfigMap {
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-minio",
Namespace: namespace,
},
Data: map[string]string{
"initialize": `#!/bin/sh
set -e ; # Have script exit in the event of a failed command.

# connectToMinio
# Use a check-sleep-check loop to wait for Minio service to be available
connectToMinio() {
SCHEME=$1
ATTEMPTS=0 ; LIMIT=29 ; # Allow 30 attempts
set -e ; # fail if we can't read the keys.
ACCESS=$(cat /config/accesskey) ; SECRET=$(cat /config/secretkey) ;
set +e ; # The connections to minio are allowed to fail.
echo "Connecting to Minio server: $SCHEME://$MINIO_ENDPOINT:$MINIO_PORT" ;
MC_COMMAND="mc config host add myminio $SCHEME://$MINIO_ENDPOINT:$MINIO_PORT $ACCESS $SECRET" ;
$MC_COMMAND ;
STATUS=$? ;
until [ $STATUS = 0 ]
do
ATTEMPTS=` + "`expr $ATTEMPTS + 1`" + `;
echo \"Failed attempts: $ATTEMPTS\" ;
if [ $ATTEMPTS -gt $LIMIT ]; then
exit 1 ;
fi ;
sleep 2 ; # 1 second intervals between attempts
$MC_COMMAND ;
STATUS=$? ;
done ;
set -e ; # reset ` + "`e`" + ` as active
return 0
}

# checkBucketExists ($bucket)
# Check if the bucket exists, by using the exit code of ` + "`mc ls`" + `
checkBucketExists() {
BUCKET=$1
CMD=$(/usr/bin/mc ls myminio/$BUCKET > /dev/null 2>&1)
return $?
}

# createBucket ($bucket, $policy, $purge)
# Ensure bucket exists, purging if asked to
createBucket() {
BUCKET=$1
POLICY=$2
PURGE=$3

# Purge the bucket, if set & exists
# Since PURGE is user input, check explicitly for ` + "`true`" + `
if [ $PURGE = true ]; then
if checkBucketExists $BUCKET ; then
echo "Purging bucket '$BUCKET'."
set +e ; # don't exit if this fails
/usr/bin/mc rm -r --force myminio/$BUCKET
set -e ; # reset ` + "`e`" + ` as active
else
echo "Bucket '$BUCKET' does not exist, skipping purge."
fi
fi

# Create the bucket if it does not exist
if ! checkBucketExists $BUCKET ; then
echo "Creating bucket '$BUCKET'"
/usr/bin/mc mb myminio/$BUCKET
else
echo "Bucket '$BUCKET' already exists."
fi

# At this point, the bucket should exist, skip checking for existence
# Set policy on the bucket
echo "Setting policy of bucket '$BUCKET' to '$POLICY'."
/usr/bin/mc policy $POLICY myminio/$BUCKET
}

# Try connecting to Minio instance
scheme=http
connectToMinio $scheme
# Create the bucket
createBucket kotsadm none false`,
},
}

return configMap
}

func minioStatefulset(namespace string) *appsv1.StatefulSet {
statefulset := &appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -284,85 +189,3 @@ func minioService(namespace string) *corev1.Service {

return service
}

func minioJob(namespace string) *batchv1.Job {
job := &batchv1.Job{
TypeMeta: metav1.TypeMeta{
APIVersion: "batch/v1",
Kind: "Job",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-minio",
Namespace: namespace,
},
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "kotsadm-minio",
},
},
Spec: corev1.PodSpec{
SecurityContext: &corev1.PodSecurityContext{
// RunAsUser: util.IntPointer(1001), // TODO: make real user #
},
RestartPolicy: corev1.RestartPolicyOnFailure,
Volumes: []corev1.Volume{
{
Name: "minio-configuration",
VolumeSource: corev1.VolumeSource{
Projected: &corev1.ProjectedVolumeSource{
Sources: []corev1.VolumeProjection{
{
ConfigMap: &corev1.ConfigMapProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
},
},
{
Secret: &corev1.SecretProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
},
},
},
},
},
},
},
Containers: []corev1.Container{
{
Command: []string{
"/bin/sh",
"/config/initialize",
},
Env: []corev1.EnvVar{
{
Name: "MINIO_ENDPOINT",
Value: "kotsadm-minio",
},
{
Name: "MINIO_PORT",
Value: "9000",
},
},
Image: "minio/mc:RELEASE.2019-10-09T22-54-57Z",
ImagePullPolicy: corev1.PullIfNotPresent,
Name: "kotsadm-minio-mc",
VolumeMounts: []corev1.VolumeMount{
{
Name: "minio-configuration",
MountPath: "/config",
},
},
},
},
},
},
},
}

return job
}