MCPcopy Index your code
hub / github.com/devspace-sh/devspace / EnsureNamespace

Function EnsureNamespace

pkg/devspace/kubectl/util.go:160–185  ·  view source on GitHub ↗
(ctx context.Context, client Client, namespace string, log log.Logger)

Source from the content-addressed store, hash-verified

158}
159
160func 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
188func NewPortForwarder(client Client, pod *corev1.Pod, ports []string, addresses []string, stopChan chan struct{}, readyChan chan struct{}, errorChan chan error) (*portforward.PortForwarder, error) {

Callers 3

ExcludeMethod · 0.92
ensureNamespaceFunction · 0.92
SaveMethod · 0.92

Calls 4

KubeClientMethod · 0.65
WithPrefixColorMethod · 0.65
GetMethod · 0.45
DonefMethod · 0.45

Tested by

no test coverage detected