(ctx context.Context, client Client, namespace string, log log.Logger)
| 158 | } |
| 159 | |
| 160 | func EnsureNamespace(ctx context.Context, client Client, namespace string, log log.Logger) error { |
| 161 | _, err := client.KubeClient().CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{}) |
| 162 | if err != nil { |
| 163 | if !kerrors.IsNotFound(err) { |
| 164 | if kerrors.IsForbidden(err) { |
| 165 | return nil |
| 166 | } |
| 167 | |
| 168 | return errors.Wrap(err, "get namespace") |
| 169 | } |
| 170 | |
| 171 | // create namespace |
| 172 | _, err = client.KubeClient().CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ |
| 173 | ObjectMeta: metav1.ObjectMeta{ |
| 174 | Name: namespace, |
| 175 | }, |
| 176 | }, metav1.CreateOptions{}) |
| 177 | if err != nil && !kerrors.IsAlreadyExists(err) { |
| 178 | return err |
| 179 | } |
| 180 | |
| 181 | log.WithPrefixColor("info ", "cyan+b").Donef("Created namespace: %s", namespace) |
| 182 | } |
| 183 | |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | // NewPortForwarder creates a new port forwarder object for the specified pods, ports and addresses |
| 188 | func NewPortForwarder(client Client, pod *corev1.Pod, ports []string, addresses []string, stopChan chan struct{}, readyChan chan struct{}, errorChan chan error) (*portforward.PortForwarder, error) { |
no test coverage detected