示例#1
0
func autoConvert_api_ProjectSpec_To_v1_ProjectSpec(in *project_api.ProjectSpec, out *ProjectSpec, s conversion.Scope) error {
	if in.Finalizers != nil {
		in, out := &in.Finalizers, &out.Finalizers
		*out = make([]api_v1.FinalizerName, len(*in))
		for i := range *in {
			(*out)[i] = api_v1.FinalizerName((*in)[i])
		}
	} else {
		out.Finalizers = nil
	}
	return nil
}
func (nc *NamespaceController) delete(namespace *api_v1.Namespace) {
	// Set Terminating status.
	updatedNamespace := &api_v1.Namespace{
		ObjectMeta: namespace.ObjectMeta,
		Spec:       namespace.Spec,
		Status: api_v1.NamespaceStatus{
			Phase: api_v1.NamespaceTerminating,
		},
	}
	if namespace.Status.Phase != api_v1.NamespaceTerminating {
		nc.eventRecorder.Event(namespace, api.EventTypeNormal, "DeleteNamespace", fmt.Sprintf("Marking for deletion"))
		_, err := nc.federatedApiClient.Core().Namespaces().Update(updatedNamespace)
		if err != nil {
			glog.Errorf("Failed to update namespace %s: %v", updatedNamespace.Name, err)
			nc.deliverNamespace(namespace.Name, 0, true)
			return
		}
	}

	// TODO: delete all namespace content.

	// Remove kube_api.FinalzerKubernetes
	if len(updatedNamespace.Spec.Finalizers) != 0 {
		finalizerSet := sets.NewString()
		for i := range namespace.Spec.Finalizers {
			if namespace.Spec.Finalizers[i] != api_v1.FinalizerKubernetes {
				finalizerSet.Insert(string(namespace.Spec.Finalizers[i]))
			}
		}
		updatedNamespace.Spec.Finalizers = make([]api_v1.FinalizerName, 0, len(finalizerSet))
		for _, value := range finalizerSet.List() {
			updatedNamespace.Spec.Finalizers = append(updatedNamespace.Spec.Finalizers, api_v1.FinalizerName(value))
		}
		_, err := nc.federatedApiClient.Core().Namespaces().Finalize(updatedNamespace)
		if err != nil {
			glog.Errorf("Failed to update namespace %s: %v", updatedNamespace.Name, err)
			nc.deliverNamespace(namespace.Name, 0, true)
			return
		}
	}

	// TODO: What about namespaces in subclusters ???
	err := nc.federatedApiClient.Core().Namespaces().Delete(updatedNamespace.Name, &api.DeleteOptions{})
	if err != nil {
		// Its all good if the error is not found error. That means it is deleted already and we do not have to do anything.
		// This is expected when we are processing an update as a result of namespace finalizer deletion.
		// The process that deleted the last finalizer is also going to delete the namespace and we do not have to do anything.
		if !errors.IsNotFound(err) {
			glog.Errorf("Failed to delete namespace %s: %v", namespace.Name, err)
			nc.deliverNamespace(namespace.Name, 0, true)
		}
	}
}
func autoConvert_api_ProjectSpec_To_v1_ProjectSpec(in *project_api.ProjectSpec, out *ProjectSpec, s conversion.Scope) error {
	if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
		defaulting.(func(*project_api.ProjectSpec))(in)
	}
	if in.Finalizers != nil {
		in, out := &in.Finalizers, &out.Finalizers
		*out = make([]api_v1.FinalizerName, len(*in))
		for i := range *in {
			(*out)[i] = api_v1.FinalizerName((*in)[i])
		}
	} else {
		out.Finalizers = nil
	}
	return nil
}
示例#4
0
func (nc *NamespaceController) delete(namespace *api_v1.Namespace) {
	// Set Terminating status.
	updatedNamespace := &api_v1.Namespace{
		ObjectMeta: namespace.ObjectMeta,
		Spec:       namespace.Spec,
		Status: api_v1.NamespaceStatus{
			Phase: api_v1.NamespaceTerminating,
		},
	}
	if namespace.Status.Phase != api_v1.NamespaceTerminating {
		nc.eventRecorder.Event(namespace, api.EventTypeNormal, "DeleteNamespace", fmt.Sprintf("Marking for deletion"))
		_, err := nc.federatedApiClient.Core().Namespaces().Update(updatedNamespace)
		if err != nil {
			glog.Errorf("Failed to update namespace %s: %v", updatedNamespace.Name, err)
			nc.deliverNamespace(namespace.Name, 0, true)
			return
		}
	}

	// TODO: delete all namespace content.

	// Remove kube_api.FinalzerKubernetes
	if len(updatedNamespace.Spec.Finalizers) != 0 {
		finalizerSet := sets.NewString()
		for i := range namespace.Spec.Finalizers {
			if namespace.Spec.Finalizers[i] != api_v1.FinalizerKubernetes {
				finalizerSet.Insert(string(namespace.Spec.Finalizers[i]))
			}
		}
		updatedNamespace.Spec.Finalizers = make([]api_v1.FinalizerName, 0, len(finalizerSet))
		for _, value := range finalizerSet.List() {
			updatedNamespace.Spec.Finalizers = append(updatedNamespace.Spec.Finalizers, api_v1.FinalizerName(value))
		}
		_, err := nc.federatedApiClient.Core().Namespaces().Finalize(updatedNamespace)
		if err != nil {
			glog.Errorf("Failed to update namespace %s: %v", updatedNamespace.Name, err)
			nc.deliverNamespace(namespace.Name, 0, true)
			return
		}
	}

	// TODO: What about namespaces in subclusters ???
	err := nc.federatedApiClient.Core().Namespaces().Delete(updatedNamespace.Name, &api.DeleteOptions{})
	if err != nil {
		glog.Errorf("Failed to delete namespace %s: %v", namespace.Name, err)
		nc.deliverNamespace(namespace.Name, 0, true)
	}
}
// finalizeNamespace removes the specified finalizerToken and finalizes the namespace
func finalizeNamespace(kubeClient clientset.Interface, namespace *v1.Namespace, finalizerToken v1.FinalizerName) (*v1.Namespace, error) {
	namespaceFinalize := v1.Namespace{}
	namespaceFinalize.ObjectMeta = namespace.ObjectMeta
	namespaceFinalize.Spec = namespace.Spec
	finalizerSet := sets.NewString()
	for i := range namespace.Spec.Finalizers {
		if namespace.Spec.Finalizers[i] != finalizerToken {
			finalizerSet.Insert(string(namespace.Spec.Finalizers[i]))
		}
	}
	namespaceFinalize.Spec.Finalizers = make([]v1.FinalizerName, 0, len(finalizerSet))
	for _, value := range finalizerSet.List() {
		namespaceFinalize.Spec.Finalizers = append(namespaceFinalize.Spec.Finalizers, v1.FinalizerName(value))
	}
	namespace, err := kubeClient.Core().Namespaces().Finalize(&namespaceFinalize)
	if err != nil {
		// it was removed already, so life is good
		if errors.IsNotFound(err) {
			return namespace, nil
		}
	}
	return namespace, err
}
示例#6
0
// delete  deletes the given namespace or returns error if the deletion was not complete.
func (nc *NamespaceController) delete(namespace *api_v1.Namespace) error {
	// Set Terminating status.
	updatedNamespace := &api_v1.Namespace{
		ObjectMeta: namespace.ObjectMeta,
		Spec:       namespace.Spec,
		Status: api_v1.NamespaceStatus{
			Phase: api_v1.NamespaceTerminating,
		},
	}
	if namespace.Status.Phase != api_v1.NamespaceTerminating {
		nc.eventRecorder.Event(namespace, api.EventTypeNormal, "DeleteNamespace", fmt.Sprintf("Marking for deletion"))
		_, err := nc.federatedApiClient.Core().Namespaces().Update(updatedNamespace)
		if err != nil {
			return fmt.Errorf("failed to update namespace: %v", err)
		}
	}

	// Right now there is just 5 types of objects: ReplicaSet, Secret, Ingress, Events and Service.
	// Temporarly these items are simply deleted one by one to squeeze this code into 1.4.
	// TODO: Make it generic (like in the regular namespace controller) and parallel.
	err := nc.federatedApiClient.Core().Services(namespace.Name).DeleteCollection(&api.DeleteOptions{}, api.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to delete service list: %v", err)
	}
	err = nc.federatedApiClient.Extensions().ReplicaSets(namespace.Name).DeleteCollection(&api.DeleteOptions{}, api.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to delete replicaset list from namespace: %v", err)
	}
	err = nc.federatedApiClient.Core().Secrets(namespace.Name).DeleteCollection(&api.DeleteOptions{}, api.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to delete secret list from namespace: %v", err)
	}
	err = nc.federatedApiClient.Extensions().Ingresses(namespace.Name).DeleteCollection(&api.DeleteOptions{}, api.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to delete ingresses list from namespace: %v", err)
	}
	err = nc.federatedApiClient.Core().Events(namespace.Name).DeleteCollection(&api.DeleteOptions{}, api.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to delete events list from namespace: %v", err)
	}

	// Remove kube_api.FinalzerKubernetes
	if len(updatedNamespace.Spec.Finalizers) != 0 {
		finalizerSet := sets.NewString()
		for i := range namespace.Spec.Finalizers {
			if namespace.Spec.Finalizers[i] != api_v1.FinalizerKubernetes {
				finalizerSet.Insert(string(namespace.Spec.Finalizers[i]))
			}
		}
		updatedNamespace.Spec.Finalizers = make([]api_v1.FinalizerName, 0, len(finalizerSet))
		for _, value := range finalizerSet.List() {
			updatedNamespace.Spec.Finalizers = append(updatedNamespace.Spec.Finalizers, api_v1.FinalizerName(value))
		}
		_, err := nc.federatedApiClient.Core().Namespaces().Finalize(updatedNamespace)
		if err != nil {
			return fmt.Errorf("failed to finalize namespace: %v", err)
		}
	}

	// TODO: What about namespaces in subclusters ???
	err = nc.federatedApiClient.Core().Namespaces().Delete(updatedNamespace.Name, &api.DeleteOptions{})
	if err != nil {
		// Its all good if the error is not found error. That means it is deleted already and we do not have to do anything.
		// This is expected when we are processing an update as a result of namespace finalizer deletion.
		// The process that deleted the last finalizer is also going to delete the namespace and we do not have to do anything.
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to delete namespace: %v", err)
		}
	}
	return nil
}
示例#7
0
func (m *ProjectSpec) Unmarshal(data []byte) error {
	l := len(data)
	iNdEx := 0
	for iNdEx < l {
		preIndex := iNdEx
		var wire uint64
		for shift := uint(0); ; shift += 7 {
			if shift >= 64 {
				return ErrIntOverflowGenerated
			}
			if iNdEx >= l {
				return io.ErrUnexpectedEOF
			}
			b := data[iNdEx]
			iNdEx++
			wire |= (uint64(b) & 0x7F) << shift
			if b < 0x80 {
				break
			}
		}
		fieldNum := int32(wire >> 3)
		wireType := int(wire & 0x7)
		if wireType == 4 {
			return fmt.Errorf("proto: ProjectSpec: wiretype end group for non-group")
		}
		if fieldNum <= 0 {
			return fmt.Errorf("proto: ProjectSpec: illegal tag %d (wire type %d)", fieldNum, wire)
		}
		switch fieldNum {
		case 1:
			if wireType != 2 {
				return fmt.Errorf("proto: wrong wireType = %d for field Finalizers", wireType)
			}
			var stringLen uint64
			for shift := uint(0); ; shift += 7 {
				if shift >= 64 {
					return ErrIntOverflowGenerated
				}
				if iNdEx >= l {
					return io.ErrUnexpectedEOF
				}
				b := data[iNdEx]
				iNdEx++
				stringLen |= (uint64(b) & 0x7F) << shift
				if b < 0x80 {
					break
				}
			}
			intStringLen := int(stringLen)
			if intStringLen < 0 {
				return ErrInvalidLengthGenerated
			}
			postIndex := iNdEx + intStringLen
			if postIndex > l {
				return io.ErrUnexpectedEOF
			}
			m.Finalizers = append(m.Finalizers, k8s_io_kubernetes_pkg_api_v1.FinalizerName(data[iNdEx:postIndex]))
			iNdEx = postIndex
		default:
			iNdEx = preIndex
			skippy, err := skipGenerated(data[iNdEx:])
			if err != nil {
				return err
			}
			if skippy < 0 {
				return ErrInvalidLengthGenerated
			}
			if (iNdEx + skippy) > l {
				return io.ErrUnexpectedEOF
			}
			iNdEx += skippy
		}
	}

	if iNdEx > l {
		return io.ErrUnexpectedEOF
	}
	return nil
}