| 129 | func (*InitSpecMsg) InitType() string { return apc.ETLInitSpec } |
| 130 | |
| 131 | func (m *InitSpecMsg) Validate() (err error) { |
| 132 | errCtx := &cmn.ETLErrorContext{} |
| 133 | pod, err := ParsePodSpec(errCtx, m.Spec) |
| 134 | if err != nil { |
| 135 | return err |
| 136 | } |
| 137 | errCtx.ETLName = m.ID() |
| 138 | |
| 139 | if err := cos.ValidateEtlID(m.IDX); err != nil { |
| 140 | return fmt.Errorf("invalid pod name: %v", err) |
| 141 | } |
| 142 | |
| 143 | if err := validateCommType(m.CommType()); err != nil { |
| 144 | return cmn.NewErrETL(errCtx, err.Error()) |
| 145 | } |
| 146 | if m.CommType() == "" { |
| 147 | m.CommTypeX = PushCommType |
| 148 | } |
| 149 | |
| 150 | // Check pod specification constraints. |
| 151 | if len(pod.Spec.Containers) != 1 { |
| 152 | err = cmn.NewErrETL(errCtx, "unsupported number of containers (%d), expected: 1", len(pod.Spec.Containers)) |
| 153 | return |
| 154 | } |
| 155 | container := pod.Spec.Containers[0] |
| 156 | if len(container.Ports) != 1 { |
| 157 | return cmn.NewErrETL(errCtx, "unsupported number of container ports (%d), expected: 1", len(container.Ports)) |
| 158 | } |
| 159 | if container.Ports[0].Name != k8s.Default { |
| 160 | return cmn.NewErrETL(errCtx, "expected port name: %q, got: %q", k8s.Default, container.Ports[0].Name) |
| 161 | } |
| 162 | |
| 163 | // Validate that user container supports health check. |
| 164 | // Currently we need the `default` port (on which the application runs) to |
| 165 | // be same as the `readiness` probe port. |
| 166 | if container.ReadinessProbe == nil { |
| 167 | return cmn.NewErrETL(errCtx, "readinessProbe section is required in a container spec") |
| 168 | } |
| 169 | // TODO: Add support for other health checks. |
| 170 | if container.ReadinessProbe.HTTPGet == nil { |
| 171 | return cmn.NewErrETL(errCtx, "httpGet missing in the readinessProbe") |
| 172 | } |
| 173 | if container.ReadinessProbe.HTTPGet.Path == "" { |
| 174 | return cmn.NewErrETL(errCtx, "expected non-empty path for readinessProbe") |
| 175 | } |
| 176 | // Currently we need the `default` port (on which the application runs) |
| 177 | // to be same as the `readiness` probe port in the pod spec. |
| 178 | if container.ReadinessProbe.HTTPGet.Port.StrVal != k8s.Default { |
| 179 | return cmn.NewErrETL(errCtx, "readinessProbe port must be the %q port", k8s.Default) |
| 180 | } |
| 181 | return nil |
| 182 | } |
| 183 | |
| 184 | ///////////////// |
| 185 | // PodsLogsMsg // |