func()

in controllers/stage/chain/put_namespace.go [20:46]


func (h PutNamespace) ServeRequest(ctx context.Context, stage *cdPipeApi.Stage) error {
	l := ctrl.LoggerFrom(context.Background())

	l.Info("Creating namespace")

	ns := &v1.Namespace{
		ObjectMeta: metaV1.ObjectMeta{
			Name: stage.Spec.Namespace,
			Labels: map[string]string{
				util.TenantLabelName: stage.Namespace,
			},
		},
	}
	if err := h.client.Create(ctx, ns); err != nil {
		if apierrors.IsAlreadyExists(err) {
			l.Info("Namespace already exists")

			return nil
		}

		return fmt.Errorf("failed to create namespace: %w", err)
	}

	l.Info("Namespace has been created")

	return nil
}