Skip to content

Commit

Permalink
Fixes for 1.12.9 release (#1468)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
  • Loading branch information
pchico83 committed May 4, 2021
1 parent c4cd387 commit 9f3780e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 70 deletions.
4 changes: 4 additions & 0 deletions pkg/cmd/stack/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ func destroyServicesNotInStack(ctx context.Context, spinner *utils.Spinner, s *m
if _, ok := s.Endpoints[ingressesList[i].Name]; ok {
continue
}
if ingressesList[i].Labels[okLabels.StackEndpointNameLabel] == "" {
//ingress created with "public"
continue
}
if err := ingress.Destroy(ctx, ingressesList[i].Name, ingressesList[i].Namespace, c); err != nil {
return fmt.Errorf("error destroying ingress '%s': %s", ingressesList[i].Name, err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/stack/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func translateDeployment(svcName string, s *model.Stack) *appsv1.Deployment {
Ports: translateContainerPorts(svc),
SecurityContext: translateSecurityContext(svc),
Resources: translateResources(svc),
WorkingDir: svc.WorkingDir,
WorkingDir: svc.Workdir,
},
},
},
Expand Down Expand Up @@ -239,10 +239,10 @@ func translatePersistentVolumeClaims(name string, s *model.Stack) []apiv1.Persis
AccessModes: []apiv1.PersistentVolumeAccessMode{apiv1.ReadWriteOnce},
Resources: apiv1.ResourceRequirements{
Requests: apiv1.ResourceList{
"storage": volumeSpec.Storage.Size.Value,
"storage": volumeSpec.Size.Value,
},
},
StorageClassName: translateStorageClass(volumeSpec.Storage.Class),
StorageClassName: translateStorageClass(volumeSpec.Class),
},
}
result = append(result, pvc)
Expand Down Expand Up @@ -295,7 +295,7 @@ func translateStatefulSet(name string, s *model.Stack) *appsv1.StatefulSet {
SecurityContext: translateSecurityContext(svc),
VolumeMounts: translateVolumeMounts(name, svc),
Resources: translateResources(svc),
WorkingDir: svc.WorkingDir,
WorkingDir: svc.Workdir,
},
},
Volumes: translateVolumes(name, svc),
Expand Down Expand Up @@ -327,10 +327,10 @@ func getInitContainerCommandAndVolumeMounts(svc model.Service) ([]string, []apiv
if !addedDataVolume {
volumeMounts = append(volumeMounts, apiv1.VolumeMount{Name: volumeName, MountPath: "/data"})
if command == "" {
command = "chmod 777 /data/"
command = "chmod 777 /data/*"
addedDataVolume = true
} else {
command += " && chmod 777 /data/"
command += " && chmod 777 /data/*"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/stack/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func Test_translateStatefulSet(t *testing.T) {
initContainer := apiv1.Container{
Name: fmt.Sprintf("init-%s", "svcName"),
Image: "busybox",
Command: []string{"sh", "-c", "chmod 777 /data/"},
Command: []string{"sh", "-c", "chmod 777 /data/*"},
VolumeMounts: []apiv1.VolumeMount{
{
MountPath: "/data",
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Dev struct {
Healthchecks bool `json:"healthchecks,omitempty" yaml:"healthchecks,omitempty"`
Probes *Probes `json:"probes,omitempty" yaml:"probes,omitempty"`
Lifecycle *Lifecycle `json:"lifecycle,omitempty" yaml:"lifecycle,omitempty"`
WorkDir string `json:"workdir,omitempty" yaml:"workdir,omitempty"`
Workdir string `json:"workdir,omitempty" yaml:"workdir,omitempty"`
MountPath string `json:"mountpath,omitempty" yaml:"mountpath,omitempty"`
SubPath string `json:"subpath,omitempty" yaml:"subpath,omitempty"`
SecurityContext *SecurityContext `json:"securityContext,omitempty" yaml:"securityContext,omitempty"`
Expand Down Expand Up @@ -802,7 +802,7 @@ func (dev *Dev) ToTranslationRule(main *Dev, reset bool) *TranslationRule {
ImagePullPolicy: dev.ImagePullPolicy,
Environment: dev.Environment,
Secrets: dev.Secrets,
WorkDir: dev.WorkDir,
WorkDir: dev.Workdir,
PersistentVolume: main.PersistentVolumeEnabled(),
Volumes: []VolumeMount{},
SecurityContext: dev.SecurityContext,
Expand Down
16 changes: 3 additions & 13 deletions pkg/model/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ func (c *Command) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err != nil {
return err
}
if strings.Contains(single, " && ") {
if strings.Contains(single, " ") {
c.Values = []string{"sh", "-c", single}
} else {
c.Values, err = shellquote.Split(single)
if err != nil {
return err
}
c.Values = []string{single}
}
} else {
c.Values = multi
Expand All @@ -166,14 +163,7 @@ func (a *Args) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err != nil {
return err
}
if strings.Contains(single, " && ") {
a.Values = []string{"sh", "-c", single}
} else {
a.Values, err = shellquote.Split(single)
if err != nil {
return err
}
}
a.Values = []string{single}
} else {
a.Values = multi
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/serializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestCommandUnmashalling(t *testing.T) {
{
"single-space",
[]byte("start.sh arg"),
Command{Values: []string{"start.sh", "arg"}},
Command{Values: []string{"sh", "-c", "start.sh arg"}},
},
{
"double-command",
Expand Down
25 changes: 13 additions & 12 deletions pkg/model/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Service struct {
Ports []Port `yaml:"ports,omitempty"`
StopGracePeriod int64 `yaml:"stop_grace_period,omitempty"`
Volumes []StackVolume `yaml:"volumes,omitempty"`
WorkingDir string `yaml:"working_dir,omitempty"`
Workdir string `yaml:"workdir,omitempty"`

Public bool `yaml:"public,omitempty"`
Replicas int32 `yaml:"replicas,omitempty"`
Expand All @@ -74,10 +74,10 @@ type StackVolume struct {
}

type VolumeSpec struct {
Name string `yaml:"name,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Storage StorageResource `json:"storage,omitempty" yaml:"storage,omitempty"`
Size Quantity `json:"size,omitempty" yaml:"size,omitempty"`
Class string `json:"class,omitempty" yaml:"class,omitempty"`
}
type Envs struct {
List Environment
Expand Down Expand Up @@ -121,11 +121,16 @@ type Endpoint struct {
Rules []EndpointRule `yaml:"rules,omitempty"`
}

//Endpoints represents an okteto stack command
//CommandStack represents an okteto stack command
type CommandStack struct {
Values []string
}

//ArgsStack represents an okteto stack args
type ArgsStack struct {
Values []string
}

// EndpointRule represents an okteto ingress rule
type EndpointRule struct {
Path string `yaml:"path,omitempty"`
Expand Down Expand Up @@ -229,8 +234,8 @@ func ReadStack(bytes []byte, isCompose bool) (*Stack, error) {

}
for _, volume := range s.Volumes {
if volume.Storage.Size.Value.Cmp(resource.MustParse("0")) == 0 {
volume.Storage.Size.Value = resource.MustParse("1Gi")
if volume.Size.Value.Cmp(resource.MustParse("0")) == 0 {
volume.Size.Value = resource.MustParse("1Gi")
}
}
return s, nil
Expand Down Expand Up @@ -389,10 +394,6 @@ func GroupWarningsBySvc(fields []string) []string {
}

func isInVolumesTopLevelSection(volumeName string, s *Stack) bool {
for _, volume := range s.Volumes {
if volume.Name == volumeName {
return true
}
}
return false
_, ok := s.Volumes[volumeName]
return ok
}
37 changes: 27 additions & 10 deletions pkg/model/stack_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type ServiceRaw struct {
CapAdd []apiv1.Capability `yaml:"capAdd,omitempty"`
CapDropSneakCase []apiv1.Capability `yaml:"cap_drop,omitempty"`
CapDrop []apiv1.Capability `yaml:"capDrop,omitempty"`
Command Args `yaml:"command,omitempty"`
Command CommandStack `yaml:"command,omitempty"`
Entrypoint CommandStack `yaml:"entrypoint,omitempty"`
Args Args `yaml:"args,omitempty"`
Args ArgsStack `yaml:"args,omitempty"`
EnvFilesSneakCase EnvFiles `yaml:"env_file,omitempty"`
EnvFiles EnvFiles `yaml:"envFile,omitempty"`
Environment *RawMessage `yaml:"environment,omitempty"`
Expand All @@ -65,7 +65,7 @@ type ServiceRaw struct {
StopGracePeriod *RawMessage `yaml:"stopGracePeriod,omitempty"`
Volumes []StackVolume `yaml:"volumes,omitempty"`
WorkingDirSneakCase string `yaml:"working_dir,omitempty"`
WorkingDir string `yaml:"workingDir,omitempty"`
Workdir string `yaml:"workdir,omitempty"`

Public bool `yaml:"public,omitempty"`
Replicas int32 `yaml:"replicas"`
Expand Down Expand Up @@ -176,7 +176,8 @@ type VolumeTopLevel struct {
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Storage StorageResource `json:"storage,omitempty" yaml:"storage,omitempty"`
Size Quantity `json:"size,omitempty" yaml:"size,omitempty"`
Class string `json:"class,omitempty" yaml:"class,omitempty"`

Driver *WarningType `json:"driver,omitempty" yaml:"driver,omitempty"`
DriverOpts *WarningType `json:"driver_opts,omitempty" yaml:"driver_opts,omitempty"`
Expand Down Expand Up @@ -207,13 +208,9 @@ func (s *Stack) UnmarshalYAML(unmarshal func(interface{}) error) error {
for volumeName, v := range stackRaw.Volumes {
result := VolumeSpec{}
if v == nil {
result.Name = sanitizeName(volumeName)
result.Labels = make(map[string]string)
result.Annotations = make(map[string]string)
} else {
if v.Name == "" {
result.Name = sanitizeName(volumeName)
}
if v.Labels == nil {
result.Labels = make(map[string]string)
}
Expand Down Expand Up @@ -334,9 +331,9 @@ func (serviceRaw *ServiceRaw) ToService(svcName string, stack *Stack) (*Service,
}
}

svc.WorkingDir = serviceRaw.WorkingDir
svc.Workdir = serviceRaw.Workdir
if serviceRaw.WorkingDirSneakCase != "" {
svc.WorkingDir = serviceRaw.WorkingDirSneakCase
svc.Workdir = serviceRaw.WorkingDirSneakCase
}
return svc, nil
}
Expand Down Expand Up @@ -950,3 +947,23 @@ func (c *CommandStack) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
return nil
}

// UnmarshalYAML Implements the Unmarshaler interface of the yaml pkg.
func (a *ArgsStack) UnmarshalYAML(unmarshal func(interface{}) error) error {
var multi []string
err := unmarshal(&multi)
if err != nil {
var single string
err := unmarshal(&single)
if err != nil {
return err
}
a.Values, err = shellquote.Split(single)
if err != nil {
return err
}
} else {
a.Values = multi
}
return nil
}
10 changes: 5 additions & 5 deletions pkg/model/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

func (dev *Dev) translateDeprecatedVolumeFields() error {
if dev.WorkDir == "" && dev.MountPath == "" && len(dev.Sync.Folders) == 0 {
dev.WorkDir = "/okteto"
if dev.Workdir == "" && dev.MountPath == "" && len(dev.Sync.Folders) == 0 {
dev.Workdir = "/okteto"
}
if err := dev.translateDeprecatedMountPath(nil); err != nil {
return err
Expand Down Expand Up @@ -70,19 +70,19 @@ func (dev *Dev) translateDeprecatedMountPath(main *Dev) error {
}

func (dev *Dev) translateDeprecatedWorkdir(main *Dev) error {
if dev.WorkDir == "" || len(dev.Sync.Folders) > 0 {
if dev.Workdir == "" || len(dev.Sync.Folders) > 0 {
return nil
}
if main != nil && main.MountPath == "" {
return fmt.Errorf("'workdir' is not supported to define your synchronized folders in 'services'. Use the field 'sync' instead (%s)", syncFieldDocsURL)
}

dev.MountPath = dev.WorkDir
dev.MountPath = dev.Workdir
dev.Sync.Folders = append(
dev.Sync.Folders,
SyncFolder{
LocalPath: filepath.Join(".", dev.SubPath),
RemotePath: dev.WorkDir,
RemotePath: dev.Workdir,
},
)
return nil
Expand Down

0 comments on commit 9f3780e

Please sign in to comment.