Skip to content

Commit

Permalink
fix: applied req changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Feb 1, 2024
1 parent d3eade9 commit 80492e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 0 additions & 5 deletions pkg/builder/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/celestiaorg/knuu/pkg/builder"
"github.com/celestiaorg/knuu/pkg/minio"
"github.com/celestiaorg/knuu/pkg/names"
"github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -46,25 +45,21 @@ func (k *Kaniko) Build(ctx context.Context, b *builder.BuilderOptions) (logs str
if err != nil {
return "", ErrCreatingJob.Wrap(err)
}
logrus.Infof("Created Job: %s", cJob.Name)

kJob, err := k.waitForJobCompletion(ctx, cJob)
if err != nil {
return "", ErrWaitingJobCompletion.Wrap(err)
}
logrus.Infof("Job completed: %s", kJob.Name)

pod, err := k.firstPodFromJob(ctx, kJob)
if err != nil {
return "", ErrGettingPodFromJob.Wrap(err)
}
logrus.Infof("Pod found: %s", pod.Name)

logs, err = k.containerLogs(ctx, pod)
if err != nil {
return "", ErrGettingContainerLogs.Wrap(err)
}
logrus.Infof("Container logs: %s", logs)

if err := k.cleanup(ctx, kJob); err != nil {
return "", ErrCleaningUp.Wrap(err)
Expand Down
22 changes: 13 additions & 9 deletions pkg/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const (
accessKey = "minioaccesskey"
secretKey = "miniosecretkey"

waitRetry = 5 * time.Second
waitRetry = 5 * time.Second
pvPrefix = "minio-pv-"
pvHostPath = "/tmp/minio-pv"
deploymentAppLabel = "app"
deploymentMinioLabel = "minio"
)

type Minio struct {
Expand All @@ -54,7 +58,7 @@ func (m *Minio) DeployMinio(ctx context.Context) error {
return nil
}

if err := m.createPVC(ctx, VolumeClaimName, PVCStorageSize); err != nil {
if err := m.createPVC(ctx, VolumeClaimName, PVCStorageSize, metav1.CreateOptions{}); err != nil {
return fmt.Errorf("failed to create PVC: %v", err)
}

Expand All @@ -66,10 +70,10 @@ func (m *Minio) DeployMinio(ctx context.Context) error {
},
Spec: appsV1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"app": "minio"},
MatchLabels: map[string]string{deploymentAppLabel: deploymentMinioLabel},
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"app": "minio"}},
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{deploymentAppLabel: deploymentMinioLabel}},
Spec: v1.PodSpec{
Containers: []v1.Container{{
Name: DeploymentName,
Expand Down Expand Up @@ -337,7 +341,7 @@ func checkServiceConnectivity(serviceEndpoint string) error {
return nil // success
}

func (m *Minio) createPVC(ctx context.Context, pvcName string, storageSize string) error {
func (m *Minio) createPVC(ctx context.Context, pvcName string, storageSize string, createOptions metav1.CreateOptions) error {
storageQt, err := resource.ParseQuantity(storageSize)
if err != nil {
return fmt.Errorf("failed to parse storage size: %v", err)
Expand Down Expand Up @@ -371,7 +375,7 @@ func (m *Minio) createPVC(ctx context.Context, pvcName string, storageSize strin
// Create a simple PV if no existing PV is suitable
_, err = m.Clientset.CoreV1().PersistentVolumes().Create(ctx, &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "minio-pv-",
GenerateName: pvPrefix,
},
Spec: v1.PersistentVolumeSpec{
Capacity: v1.ResourceList{
Expand All @@ -380,11 +384,11 @@ func (m *Minio) createPVC(ctx context.Context, pvcName string, storageSize strin
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
PersistentVolumeSource: v1.PersistentVolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/tmp/minio-pv", // Replace with your desired host path
Path: pvHostPath,
},
},
},
}, metav1.CreateOptions{})
}, createOptions)
if err != nil {
return fmt.Errorf("failed to create PersistentVolume: %v", err)
}
Expand All @@ -408,7 +412,7 @@ func (m *Minio) createPVC(ctx context.Context, pvcName string, storageSize strin
},
}

_, err = pvcClient.Create(ctx, pvc, metav1.CreateOptions{})
_, err = pvcClient.Create(ctx, pvc, createOptions)
if err != nil {
return fmt.Errorf("failed to create PersistentVolumeClaim: %v", err)
}
Expand Down

0 comments on commit 80492e4

Please sign in to comment.