diff --git a/Makefile b/Makefile index 9c03307db5088da01e06f343ef56bcc7213aa0f7..e52896c75c189fcdb1a1e43242bf156e62c33464 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ vet: generate # Generate manifests e.g. CRD, RBAC etc. manifests: - go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all + go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/... deploy: manifests kubectl apply -f config/crds diff --git a/config/samples/devops_v1alpha3_devopsproject.yaml b/config/samples/devops_v1alpha3_devopsproject.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b443b6d2cfb35c2a55931bd211c40322db4b4e7b --- /dev/null +++ b/config/samples/devops_v1alpha3_devopsproject.yaml @@ -0,0 +1,9 @@ +apiVersion: devops.kubesphere.io/v1alpha3 +kind: DevOpsProject +metadata: + labels: + controller-tools.k8s.io: "1.0" + name: devopsproject-sample +spec: + # Add fields here + foo: bar diff --git a/hack/generate_client.sh b/hack/generate_client.sh index 9d094b8b0342415021d78863cab8d9ccc0b46693..96df9ac806cce8fc0e0bf5924dd8f60537f1ab46 100755 --- a/hack/generate_client.sh +++ b/hack/generate_client.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -GV="network:v1alpha1 servicemesh:v1alpha2 tenant:v1alpha1 devops:v1alpha1" +GV="network:v1alpha1 servicemesh:v1alpha2 tenant:v1alpha1 devops:v1alpha1 devops:v1alpha3" rm -rf ./pkg/client ./hack/generate_group.sh "client,lister,informer" kubesphere.io/kubesphere/pkg/client kubesphere.io/kubesphere/pkg/apis "$GV" --output-base=./ -h "$PWD/hack/boilerplate.go.txt" diff --git a/pkg/apis/addtoscheme_devops_v1alpha3.go b/pkg/apis/addtoscheme_devops_v1alpha3.go new file mode 100644 index 0000000000000000000000000000000000000000..1e169cc2d58c3a1b06876264aae017da0bafeb22 --- /dev/null +++ b/pkg/apis/addtoscheme_devops_v1alpha3.go @@ -0,0 +1,26 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package apis + +import ( + api "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, api.SchemeBuilder.AddToScheme) +} diff --git a/pkg/apis/devops/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/devops/v1alpha1/zz_generated.deepcopy.go index d0bb2e679dbb555101d3d5000cb129f1ad7c2245..c1c3834038c26578c6fcf49017964ccf22e46424 100644 --- a/pkg/apis/devops/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/devops/v1alpha1/zz_generated.deepcopy.go @@ -16,12 +16,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha1 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -33,7 +33,6 @@ func (in *AuthConfig) DeepCopyInto(out *AuthConfig) { *out = new(v1.LocalObjectReference) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthConfig. @@ -49,7 +48,6 @@ func (in *AuthConfig) DeepCopy() *AuthConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CGroupLimits) DeepCopyInto(out *CGroupLimits) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CGroupLimits. @@ -77,7 +75,6 @@ func (in *ContainerConfig) DeepCopyInto(out *ContainerConfig) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerConfig. @@ -103,7 +100,6 @@ func (in *ContainerInfo) DeepCopyInto(out *ContainerInfo) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerInfo. @@ -119,7 +115,6 @@ func (in *ContainerInfo) DeepCopy() *ContainerInfo { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DockerConfig) DeepCopyInto(out *DockerConfig) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerConfig. @@ -135,7 +130,6 @@ func (in *DockerConfig) DeepCopy() *DockerConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DockerConfigEntry) DeepCopyInto(out *DockerConfigEntry) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerConfigEntry. @@ -158,7 +152,6 @@ func (in *DockerConfigJson) DeepCopyInto(out *DockerConfigJson) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerConfigJson. @@ -179,7 +172,6 @@ func (in DockerConfigMap) DeepCopyInto(out *DockerConfigMap) { for key, val := range *in { (*out)[key] = val } - return } } @@ -196,7 +188,6 @@ func (in DockerConfigMap) DeepCopy() DockerConfigMap { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EnvironmentSpec) DeepCopyInto(out *EnvironmentSpec) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EnvironmentSpec. @@ -217,7 +208,6 @@ func (in *Parameter) DeepCopyInto(out *Parameter) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Parameter. @@ -233,7 +223,6 @@ func (in *Parameter) DeepCopy() *Parameter { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ProxyConfig) DeepCopyInto(out *ProxyConfig) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxyConfig. @@ -259,7 +248,6 @@ func (in *S2iAutoScale) DeepCopyInto(out *S2iAutoScale) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iAutoScale. @@ -279,7 +267,6 @@ func (in *S2iBinary) DeepCopyInto(out *S2iBinary) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) out.Status = in.Status - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBinary. @@ -312,7 +299,6 @@ func (in *S2iBinaryList) DeepCopyInto(out *S2iBinaryList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBinaryList. @@ -340,7 +326,6 @@ func (in *S2iBinarySpec) DeepCopyInto(out *S2iBinarySpec) { in, out := &in.UploadTimeStamp, &out.UploadTimeStamp *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBinarySpec. @@ -356,7 +341,6 @@ func (in *S2iBinarySpec) DeepCopy() *S2iBinarySpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *S2iBinaryStatus) DeepCopyInto(out *S2iBinaryStatus) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBinaryStatus. @@ -377,7 +361,6 @@ func (in *S2iBuildResult) DeepCopyInto(out *S2iBuildResult) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuildResult. @@ -393,7 +376,6 @@ func (in *S2iBuildResult) DeepCopy() *S2iBuildResult { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *S2iBuildSource) DeepCopyInto(out *S2iBuildSource) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuildSource. @@ -413,7 +395,6 @@ func (in *S2iBuilder) DeepCopyInto(out *S2iBuilder) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilder. @@ -446,7 +427,6 @@ func (in *S2iBuilderList) DeepCopyInto(out *S2iBuilderList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderList. @@ -480,7 +460,6 @@ func (in *S2iBuilderSpec) DeepCopyInto(out *S2iBuilderSpec) { *out = new(UserDefineTemplate) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderSpec. @@ -505,7 +484,6 @@ func (in *S2iBuilderStatus) DeepCopyInto(out *S2iBuilderStatus) { in, out := &in.LastRunStartTime, &out.LastRunStartTime *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderStatus. @@ -525,7 +503,6 @@ func (in *S2iBuilderTemplate) DeepCopyInto(out *S2iBuilderTemplate) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) out.Status = in.Status - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderTemplate. @@ -558,7 +535,6 @@ func (in *S2iBuilderTemplateList) DeepCopyInto(out *S2iBuilderTemplateList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderTemplateList. @@ -596,7 +572,6 @@ func (in *S2iBuilderTemplateSpec) DeepCopyInto(out *S2iBuilderTemplateSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderTemplateSpec. @@ -612,7 +587,6 @@ func (in *S2iBuilderTemplateSpec) DeepCopy() *S2iBuilderTemplateSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *S2iBuilderTemplateStatus) DeepCopyInto(out *S2iBuilderTemplateStatus) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iBuilderTemplateStatus. @@ -715,7 +689,6 @@ func (in *S2iConfig) DeepCopyInto(out *S2iConfig) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iConfig. @@ -735,7 +708,6 @@ func (in *S2iRun) DeepCopyInto(out *S2iRun) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Spec = in.Spec in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iRun. @@ -768,7 +740,6 @@ func (in *S2iRunList) DeepCopyInto(out *S2iRunList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iRunList. @@ -792,7 +763,6 @@ func (in *S2iRunList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *S2iRunSpec) DeepCopyInto(out *S2iRunSpec) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iRunSpec. @@ -826,7 +796,6 @@ func (in *S2iRunStatus) DeepCopyInto(out *S2iRunStatus) { *out = new(S2iBuildSource) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S2iRunStatus. @@ -849,7 +818,6 @@ func (in *UserDefineTemplate) DeepCopyInto(out *UserDefineTemplate) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserDefineTemplate. @@ -865,7 +833,6 @@ func (in *UserDefineTemplate) DeepCopy() *UserDefineTemplate { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VolumeSpec) DeepCopyInto(out *VolumeSpec) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSpec. diff --git a/pkg/apis/devops/v1alpha3/devopsproject_types.go b/pkg/apis/devops/v1alpha3/devopsproject_types.go new file mode 100644 index 0000000000000000000000000000000000000000..b22d3adc889300d309d7ae108e8453b3be2a6c72 --- /dev/null +++ b/pkg/apis/devops/v1alpha3/devopsproject_types.go @@ -0,0 +1,66 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha3 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +const DevOpsProjectFinalizerName = "devopsproject.finalizers.kubesphere.io" + +// DevOpsProjectSpec defines the desired state of DevOpsProject +type DevOpsProjectSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + +} + +// DevOpsProjectStatus defines the observed state of DevOpsProject +type DevOpsProjectStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// DevOpsProject is the Schema for the devopsprojects API +// +k8s:openapi-gen=true +type DevOpsProject struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec DevOpsProjectSpec `json:"spec,omitempty"` + Status DevOpsProjectStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// DevOpsProjectList contains a list of DevOpsProject +type DevOpsProjectList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []DevOpsProject `json:"items"` +} + +func init() { + SchemeBuilder.Register(&DevOpsProject{}, &DevOpsProjectList{}) +} diff --git a/pkg/apis/devops/v1alpha3/devopsproject_types_test.go b/pkg/apis/devops/v1alpha3/devopsproject_types_test.go new file mode 100644 index 0000000000000000000000000000000000000000..325b380beb1e960739bb96817a389516433d6dbc --- /dev/null +++ b/pkg/apis/devops/v1alpha3/devopsproject_types_test.go @@ -0,0 +1,58 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha3 + +import ( + "testing" + + "github.com/onsi/gomega" + "golang.org/x/net/context" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" +) + +func TestStorageDevOpsProject(t *testing.T) { + key := types.NamespacedName{ + Name: "foo", + Namespace: "default", + } + created := &DevOpsProject{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "default", + }} + g := gomega.NewGomegaWithT(t) + + // Test Create + fetched := &DevOpsProject{} + g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) + + g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) + g.Expect(fetched).To(gomega.Equal(created)) + + // Test Updating the Labels + updated := fetched.DeepCopy() + updated.Labels = map[string]string{"hello": "world"} + g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) + + g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) + g.Expect(fetched).To(gomega.Equal(updated)) + + // Test Delete + g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) + g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) +} diff --git a/pkg/apis/devops/v1alpha3/doc.go b/pkg/apis/devops/v1alpha3/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..b526ff90e694af17dc826d2c5cc87a0852449450 --- /dev/null +++ b/pkg/apis/devops/v1alpha3/doc.go @@ -0,0 +1,23 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package v1alpha3 contains API Schema definitions for the devops v1alpha3 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=kubesphere.io/kubesphere/pkg/apis/devops +// +k8s:defaulter-gen=TypeMeta +// +groupName=devops.kubesphere.io +package v1alpha3 diff --git a/pkg/apis/devops/v1alpha3/register.go b/pkg/apis/devops/v1alpha3/register.go new file mode 100644 index 0000000000000000000000000000000000000000..51adad3c187df8097150aed30d560fbf3da14a1f --- /dev/null +++ b/pkg/apis/devops/v1alpha3/register.go @@ -0,0 +1,46 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// NOTE: Boilerplate only. Ignore this file. + +// Package v1alpha3 contains API Schema definitions for the devops v1alpha3 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=kubesphere.io/kubesphere/pkg/apis/devops +// +k8s:defaulter-gen=TypeMeta +// +groupName=devops.kubesphere.io +package v1alpha3 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "devops.kubesphere.io", Version: "v1alpha3"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + + // AddToScheme is required by pkg/client/... + AddToScheme = SchemeBuilder.AddToScheme +) + +// Resource is required by pkg/client/listers/... +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} diff --git a/pkg/apis/devops/v1alpha3/v1alpha3_suite_test.go b/pkg/apis/devops/v1alpha3/v1alpha3_suite_test.go new file mode 100644 index 0000000000000000000000000000000000000000..00c341a74e675e99daf4f2026809dbda8fed8ca5 --- /dev/null +++ b/pkg/apis/devops/v1alpha3/v1alpha3_suite_test.go @@ -0,0 +1,55 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha3 + +import ( + "log" + "os" + "path/filepath" + "testing" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" +) + +var cfg *rest.Config +var c client.Client + +func TestMain(m *testing.M) { + t := &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, + } + + err := SchemeBuilder.AddToScheme(scheme.Scheme) + if err != nil { + log.Fatal(err) + } + + if cfg, err = t.Start(); err != nil { + log.Fatal(err) + } + + if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { + log.Fatal(err) + } + + code := m.Run() + t.Stop() + os.Exit(code) +} diff --git a/pkg/apis/devops/v1alpha3/zz_generated.deepcopy.go b/pkg/apis/devops/v1alpha3/zz_generated.deepcopy.go new file mode 100644 index 0000000000000000000000000000000000000000..416ab132f6d7009dc88cc7805cc65ef8ef2b0574 --- /dev/null +++ b/pkg/apis/devops/v1alpha3/zz_generated.deepcopy.go @@ -0,0 +1,114 @@ +// +build !ignore_autogenerated + +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DevOpsProject) DeepCopyInto(out *DevOpsProject) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProject. +func (in *DevOpsProject) DeepCopy() *DevOpsProject { + if in == nil { + return nil + } + out := new(DevOpsProject) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DevOpsProject) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DevOpsProjectList) DeepCopyInto(out *DevOpsProjectList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]DevOpsProject, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectList. +func (in *DevOpsProjectList) DeepCopy() *DevOpsProjectList { + if in == nil { + return nil + } + out := new(DevOpsProjectList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DevOpsProjectList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DevOpsProjectSpec) DeepCopyInto(out *DevOpsProjectSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectSpec. +func (in *DevOpsProjectSpec) DeepCopy() *DevOpsProjectSpec { + if in == nil { + return nil + } + out := new(DevOpsProjectSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DevOpsProjectStatus) DeepCopyInto(out *DevOpsProjectStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectStatus. +func (in *DevOpsProjectStatus) DeepCopy() *DevOpsProjectStatus { + if in == nil { + return nil + } + out := new(DevOpsProjectStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/network/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/network/v1alpha1/zz_generated.deepcopy.go index ae35ee8ab211e98d095314069093da6d056c5308..71e01062f05023fbfe25feaa072c32847fa54c53 100644 --- a/pkg/apis/network/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/network/v1alpha1/zz_generated.deepcopy.go @@ -16,16 +16,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha1 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" - numorstring "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1/numorstring" + "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1/numorstring" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -56,7 +56,6 @@ func (in *EntityRule) DeepCopyInto(out *EntityRule) { *out = new(ServiceAccountMatch) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EntityRule. @@ -82,7 +81,6 @@ func (in *HTTPMatch) DeepCopyInto(out *HTTPMatch) { *out = make([]HTTPPath, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPMatch. @@ -98,7 +96,6 @@ func (in *HTTPMatch) DeepCopy() *HTTPMatch { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPPath) DeepCopyInto(out *HTTPPath) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPPath. @@ -124,7 +121,6 @@ func (in *ICMPFields) DeepCopyInto(out *ICMPFields) { *out = new(int) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ICMPFields. @@ -143,7 +139,6 @@ func (in *NamespaceNetworkPolicy) DeepCopyInto(out *NamespaceNetworkPolicy) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespaceNetworkPolicy. @@ -176,7 +171,6 @@ func (in *NamespaceNetworkPolicyList) DeepCopyInto(out *NamespaceNetworkPolicyLi (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespaceNetworkPolicyList. @@ -224,7 +218,6 @@ func (in *NamespaceNetworkPolicySpec) DeepCopyInto(out *NamespaceNetworkPolicySp *out = make([]PolicyType, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespaceNetworkPolicySpec. @@ -272,7 +265,6 @@ func (in *Rule) DeepCopyInto(out *Rule) { *out = new(HTTPMatch) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rule. @@ -293,7 +285,6 @@ func (in *ServiceAccountMatch) DeepCopyInto(out *ServiceAccountMatch) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceAccountMatch. @@ -313,7 +304,6 @@ func (in *WorkspaceNetworkPolicy) DeepCopyInto(out *WorkspaceNetworkPolicy) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) out.Status = in.Status - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicy. @@ -351,7 +341,6 @@ func (in *WorkspaceNetworkPolicyEgressRule) DeepCopyInto(out *WorkspaceNetworkPo (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicyEgressRule. @@ -381,7 +370,6 @@ func (in *WorkspaceNetworkPolicyIngressRule) DeepCopyInto(out *WorkspaceNetworkP (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicyIngressRule. @@ -406,7 +394,6 @@ func (in *WorkspaceNetworkPolicyList) DeepCopyInto(out *WorkspaceNetworkPolicyLi (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicyList. @@ -436,7 +423,6 @@ func (in *WorkspaceNetworkPolicyPeer) DeepCopyInto(out *WorkspaceNetworkPolicyPe *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicyPeer. @@ -471,7 +457,6 @@ func (in *WorkspaceNetworkPolicySpec) DeepCopyInto(out *WorkspaceNetworkPolicySp (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicySpec. @@ -487,7 +472,6 @@ func (in *WorkspaceNetworkPolicySpec) DeepCopy() *WorkspaceNetworkPolicySpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceNetworkPolicyStatus) DeepCopyInto(out *WorkspaceNetworkPolicyStatus) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceNetworkPolicyStatus. diff --git a/pkg/apis/servicemesh/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/servicemesh/v1alpha2/zz_generated.deepcopy.go index 23e36c5f86d64f75a249bad42f6cd955e8ca0529..c5a810aa5792654387f40e43e634fd97ea831687 100644 --- a/pkg/apis/servicemesh/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/servicemesh/v1alpha2/zz_generated.deepcopy.go @@ -16,12 +16,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha2 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -30,7 +30,6 @@ func (in *DestinationRuleSpecTemplate) DeepCopyInto(out *DestinationRuleSpecTemp *out = *in in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DestinationRuleSpecTemplate. @@ -50,7 +49,6 @@ func (in *ServicePolicy) DeepCopyInto(out *ServicePolicy) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServicePolicy. @@ -76,7 +74,6 @@ func (in *ServicePolicyCondition) DeepCopyInto(out *ServicePolicyCondition) { *out = *in in.LastProbeTime.DeepCopyInto(&out.LastProbeTime) in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServicePolicyCondition. @@ -101,7 +98,6 @@ func (in *ServicePolicyList) DeepCopyInto(out *ServicePolicyList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServicePolicyList. @@ -131,7 +127,6 @@ func (in *ServicePolicySpec) DeepCopyInto(out *ServicePolicySpec) { (*in).DeepCopyInto(*out) } in.Template.DeepCopyInto(&out.Template) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServicePolicySpec. @@ -162,7 +157,6 @@ func (in *ServicePolicyStatus) DeepCopyInto(out *ServicePolicyStatus) { in, out := &in.CompletionTime, &out.CompletionTime *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServicePolicyStatus. @@ -182,7 +176,6 @@ func (in *Strategy) DeepCopyInto(out *Strategy) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Strategy. @@ -208,7 +201,6 @@ func (in *StrategyCondition) DeepCopyInto(out *StrategyCondition) { *out = *in in.LastProbeTime.DeepCopyInto(&out.LastProbeTime) in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StrategyCondition. @@ -233,7 +225,6 @@ func (in *StrategyList) DeepCopyInto(out *StrategyList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StrategyList. @@ -263,7 +254,6 @@ func (in *StrategySpec) DeepCopyInto(out *StrategySpec) { (*in).DeepCopyInto(*out) } in.Template.DeepCopyInto(&out.Template) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StrategySpec. @@ -294,7 +284,6 @@ func (in *StrategyStatus) DeepCopyInto(out *StrategyStatus) { in, out := &in.CompletionTime, &out.CompletionTime *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StrategyStatus. @@ -312,7 +301,6 @@ func (in *VirtualServiceTemplateSpec) DeepCopyInto(out *VirtualServiceTemplateSp *out = *in in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VirtualServiceTemplateSpec. diff --git a/pkg/apis/tenant/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/tenant/v1alpha1/zz_generated.deepcopy.go index b50a8d568055060510daca7eeeee8b954d4aeaa0..a9319670d88e4a0fc39674c0033500e3259c29d5 100644 --- a/pkg/apis/tenant/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/tenant/v1alpha1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha1 @@ -31,7 +31,6 @@ func (in *Workspace) DeepCopyInto(out *Workspace) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Spec = in.Spec out.Status = in.Status - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Workspace. @@ -64,7 +63,6 @@ func (in *WorkspaceList) DeepCopyInto(out *WorkspaceList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceList. @@ -88,7 +86,6 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceSpec) DeepCopyInto(out *WorkspaceSpec) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceSpec. @@ -104,7 +101,6 @@ func (in *WorkspaceSpec) DeepCopy() *WorkspaceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceStatus) DeepCopyInto(out *WorkspaceStatus) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceStatus. diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index cdf28675e3fd4e1346c1ef6e0a23f81204e7c19c..17602d77f11aef724f895bd4be5c85bdac247990 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -25,6 +25,7 @@ import ( rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" devopsv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha1" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha3" networkv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/network/v1alpha1" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1" @@ -33,6 +34,7 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface DevopsV1alpha1() devopsv1alpha1.DevopsV1alpha1Interface + DevopsV1alpha3() devopsv1alpha3.DevopsV1alpha3Interface NetworkV1alpha1() networkv1alpha1.NetworkV1alpha1Interface ServicemeshV1alpha2() servicemeshv1alpha2.ServicemeshV1alpha2Interface TenantV1alpha1() tenantv1alpha1.TenantV1alpha1Interface @@ -43,6 +45,7 @@ type Interface interface { type Clientset struct { *discovery.DiscoveryClient devopsV1alpha1 *devopsv1alpha1.DevopsV1alpha1Client + devopsV1alpha3 *devopsv1alpha3.DevopsV1alpha3Client networkV1alpha1 *networkv1alpha1.NetworkV1alpha1Client servicemeshV1alpha2 *servicemeshv1alpha2.ServicemeshV1alpha2Client tenantV1alpha1 *tenantv1alpha1.TenantV1alpha1Client @@ -53,6 +56,11 @@ func (c *Clientset) DevopsV1alpha1() devopsv1alpha1.DevopsV1alpha1Interface { return c.devopsV1alpha1 } +// DevopsV1alpha3 retrieves the DevopsV1alpha3Client +func (c *Clientset) DevopsV1alpha3() devopsv1alpha3.DevopsV1alpha3Interface { + return c.devopsV1alpha3 +} + // NetworkV1alpha1 retrieves the NetworkV1alpha1Client func (c *Clientset) NetworkV1alpha1() networkv1alpha1.NetworkV1alpha1Interface { return c.networkV1alpha1 @@ -93,6 +101,10 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } + cs.devopsV1alpha3, err = devopsv1alpha3.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.networkV1alpha1, err = networkv1alpha1.NewForConfig(&configShallowCopy) if err != nil { return nil, err @@ -118,6 +130,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset cs.devopsV1alpha1 = devopsv1alpha1.NewForConfigOrDie(c) + cs.devopsV1alpha3 = devopsv1alpha3.NewForConfigOrDie(c) cs.networkV1alpha1 = networkv1alpha1.NewForConfigOrDie(c) cs.servicemeshV1alpha2 = servicemeshv1alpha2.NewForConfigOrDie(c) cs.tenantV1alpha1 = tenantv1alpha1.NewForConfigOrDie(c) @@ -130,6 +143,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.devopsV1alpha1 = devopsv1alpha1.New(c) + cs.devopsV1alpha3 = devopsv1alpha3.New(c) cs.networkV1alpha1 = networkv1alpha1.New(c) cs.servicemeshV1alpha2 = servicemeshv1alpha2.New(c) cs.tenantV1alpha1 = tenantv1alpha1.New(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index 2eb0a0a07cd1cdfd8c0ffa68c6ebbf088df987ce..1906a96b3217a5dde7c7fad78a5cb983bfce884a 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -27,6 +27,8 @@ import ( clientset "kubesphere.io/kubesphere/pkg/client/clientset/versioned" devopsv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha1" fakedevopsv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha1/fake" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha3" + fakedevopsv1alpha3 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake" networkv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/network/v1alpha1" fakenetworkv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/network/v1alpha1/fake" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2" @@ -87,6 +89,11 @@ func (c *Clientset) DevopsV1alpha1() devopsv1alpha1.DevopsV1alpha1Interface { return &fakedevopsv1alpha1.FakeDevopsV1alpha1{Fake: &c.Fake} } +// DevopsV1alpha3 retrieves the DevopsV1alpha3Client +func (c *Clientset) DevopsV1alpha3() devopsv1alpha3.DevopsV1alpha3Interface { + return &fakedevopsv1alpha3.FakeDevopsV1alpha3{Fake: &c.Fake} +} + // NetworkV1alpha1 retrieves the NetworkV1alpha1Client func (c *Clientset) NetworkV1alpha1() networkv1alpha1.NetworkV1alpha1Interface { return &fakenetworkv1alpha1.FakeNetworkV1alpha1{Fake: &c.Fake} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 36f2e736ef3111056b12d750736927f895fe2ca8..da64fc02649791b4ee298e00593c517daffeef57 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -25,6 +25,7 @@ import ( serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" devopsv1alpha1 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" @@ -35,6 +36,7 @@ var codecs = serializer.NewCodecFactory(scheme) var parameterCodec = runtime.NewParameterCodec(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ devopsv1alpha1.AddToScheme, + devopsv1alpha3.AddToScheme, networkv1alpha1.AddToScheme, servicemeshv1alpha2.AddToScheme, tenantv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 30434c5453c9c01e7e2908dac46da559c81c93ff..b163357787042d154fff57775ad986cbec946d7a 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -25,6 +25,7 @@ import ( serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" devopsv1alpha1 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" @@ -35,6 +36,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ devopsv1alpha1.AddToScheme, + devopsv1alpha3.AddToScheme, networkv1alpha1.AddToScheme, servicemeshv1alpha2.AddToScheme, tenantv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/devops_client.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/devops_client.go new file mode 100644 index 0000000000000000000000000000000000000000..b864758e506ff63d5ebb21724c9a1dfb48e066dc --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/devops_client.go @@ -0,0 +1,89 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + rest "k8s.io/client-go/rest" + v1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" + "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme" +) + +type DevopsV1alpha3Interface interface { + RESTClient() rest.Interface + DevOpsProjectsGetter +} + +// DevopsV1alpha3Client is used to interact with features provided by the devops.kubesphere.io group. +type DevopsV1alpha3Client struct { + restClient rest.Interface +} + +func (c *DevopsV1alpha3Client) DevOpsProjects() DevOpsProjectInterface { + return newDevOpsProjects(c) +} + +// NewForConfig creates a new DevopsV1alpha3Client for the given config. +func NewForConfig(c *rest.Config) (*DevopsV1alpha3Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &DevopsV1alpha3Client{client}, nil +} + +// NewForConfigOrDie creates a new DevopsV1alpha3Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *DevopsV1alpha3Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new DevopsV1alpha3Client for the given RESTClient. +func New(c rest.Interface) *DevopsV1alpha3Client { + return &DevopsV1alpha3Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha3.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *DevopsV1alpha3Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/devopsproject.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/devopsproject.go new file mode 100644 index 0000000000000000000000000000000000000000..f923e6e9dfb165bb99a5d7b00ab699e4930bfb95 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/devopsproject.go @@ -0,0 +1,180 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" + scheme "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme" +) + +// DevOpsProjectsGetter has a method to return a DevOpsProjectInterface. +// A group's client should implement this interface. +type DevOpsProjectsGetter interface { + DevOpsProjects() DevOpsProjectInterface +} + +// DevOpsProjectInterface has methods to work with DevOpsProject resources. +type DevOpsProjectInterface interface { + Create(*v1alpha3.DevOpsProject) (*v1alpha3.DevOpsProject, error) + Update(*v1alpha3.DevOpsProject) (*v1alpha3.DevOpsProject, error) + UpdateStatus(*v1alpha3.DevOpsProject) (*v1alpha3.DevOpsProject, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha3.DevOpsProject, error) + List(opts v1.ListOptions) (*v1alpha3.DevOpsProjectList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha3.DevOpsProject, err error) + DevOpsProjectExpansion +} + +// devOpsProjects implements DevOpsProjectInterface +type devOpsProjects struct { + client rest.Interface +} + +// newDevOpsProjects returns a DevOpsProjects +func newDevOpsProjects(c *DevopsV1alpha3Client) *devOpsProjects { + return &devOpsProjects{ + client: c.RESTClient(), + } +} + +// Get takes name of the devOpsProject, and returns the corresponding devOpsProject object, and an error if there is any. +func (c *devOpsProjects) Get(name string, options v1.GetOptions) (result *v1alpha3.DevOpsProject, err error) { + result = &v1alpha3.DevOpsProject{} + err = c.client.Get(). + Resource("devopsprojects"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of DevOpsProjects that match those selectors. +func (c *devOpsProjects) List(opts v1.ListOptions) (result *v1alpha3.DevOpsProjectList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha3.DevOpsProjectList{} + err = c.client.Get(). + Resource("devopsprojects"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested devOpsProjects. +func (c *devOpsProjects) Watch(opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("devopsprojects"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a devOpsProject and creates it. Returns the server's representation of the devOpsProject, and an error, if there is any. +func (c *devOpsProjects) Create(devOpsProject *v1alpha3.DevOpsProject) (result *v1alpha3.DevOpsProject, err error) { + result = &v1alpha3.DevOpsProject{} + err = c.client.Post(). + Resource("devopsprojects"). + Body(devOpsProject). + Do(). + Into(result) + return +} + +// Update takes the representation of a devOpsProject and updates it. Returns the server's representation of the devOpsProject, and an error, if there is any. +func (c *devOpsProjects) Update(devOpsProject *v1alpha3.DevOpsProject) (result *v1alpha3.DevOpsProject, err error) { + result = &v1alpha3.DevOpsProject{} + err = c.client.Put(). + Resource("devopsprojects"). + Name(devOpsProject.Name). + Body(devOpsProject). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *devOpsProjects) UpdateStatus(devOpsProject *v1alpha3.DevOpsProject) (result *v1alpha3.DevOpsProject, err error) { + result = &v1alpha3.DevOpsProject{} + err = c.client.Put(). + Resource("devopsprojects"). + Name(devOpsProject.Name). + SubResource("status"). + Body(devOpsProject). + Do(). + Into(result) + return +} + +// Delete takes name of the devOpsProject and deletes it. Returns an error if one occurs. +func (c *devOpsProjects) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Resource("devopsprojects"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *devOpsProjects) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("devopsprojects"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched devOpsProject. +func (c *devOpsProjects) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha3.DevOpsProject, err error) { + result = &v1alpha3.DevOpsProject{} + err = c.client.Patch(pt). + Resource("devopsprojects"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/doc.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..a4ae49dd191becf2bf9c957802faf716d16babc8 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha3 diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/doc.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..329c98fb5851ae844d6836e4aca84cdfbf130e5d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devops_client.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devops_client.go new file mode 100644 index 0000000000000000000000000000000000000000..e17f6e60cb79a7aacd99b96ffc4905a5e2515e90 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devops_client.go @@ -0,0 +1,40 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1alpha3 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/devops/v1alpha3" +) + +type FakeDevopsV1alpha3 struct { + *testing.Fake +} + +func (c *FakeDevopsV1alpha3) DevOpsProjects() v1alpha3.DevOpsProjectInterface { + return &FakeDevOpsProjects{c} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeDevopsV1alpha3) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devopsproject.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devopsproject.go new file mode 100644 index 0000000000000000000000000000000000000000..1fb7fe5949fdf1a7e24a4a773471b07483f8448d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devopsproject.go @@ -0,0 +1,131 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" +) + +// FakeDevOpsProjects implements DevOpsProjectInterface +type FakeDevOpsProjects struct { + Fake *FakeDevopsV1alpha3 +} + +var devopsprojectsResource = schema.GroupVersionResource{Group: "devops.kubesphere.io", Version: "v1alpha3", Resource: "devopsprojects"} + +var devopsprojectsKind = schema.GroupVersionKind{Group: "devops.kubesphere.io", Version: "v1alpha3", Kind: "DevOpsProject"} + +// Get takes name of the devOpsProject, and returns the corresponding devOpsProject object, and an error if there is any. +func (c *FakeDevOpsProjects) Get(name string, options v1.GetOptions) (result *v1alpha3.DevOpsProject, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(devopsprojectsResource, name), &v1alpha3.DevOpsProject{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha3.DevOpsProject), err +} + +// List takes label and field selectors, and returns the list of DevOpsProjects that match those selectors. +func (c *FakeDevOpsProjects) List(opts v1.ListOptions) (result *v1alpha3.DevOpsProjectList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(devopsprojectsResource, devopsprojectsKind, opts), &v1alpha3.DevOpsProjectList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha3.DevOpsProjectList{ListMeta: obj.(*v1alpha3.DevOpsProjectList).ListMeta} + for _, item := range obj.(*v1alpha3.DevOpsProjectList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested devOpsProjects. +func (c *FakeDevOpsProjects) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(devopsprojectsResource, opts)) +} + +// Create takes the representation of a devOpsProject and creates it. Returns the server's representation of the devOpsProject, and an error, if there is any. +func (c *FakeDevOpsProjects) Create(devOpsProject *v1alpha3.DevOpsProject) (result *v1alpha3.DevOpsProject, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(devopsprojectsResource, devOpsProject), &v1alpha3.DevOpsProject{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha3.DevOpsProject), err +} + +// Update takes the representation of a devOpsProject and updates it. Returns the server's representation of the devOpsProject, and an error, if there is any. +func (c *FakeDevOpsProjects) Update(devOpsProject *v1alpha3.DevOpsProject) (result *v1alpha3.DevOpsProject, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(devopsprojectsResource, devOpsProject), &v1alpha3.DevOpsProject{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha3.DevOpsProject), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeDevOpsProjects) UpdateStatus(devOpsProject *v1alpha3.DevOpsProject) (*v1alpha3.DevOpsProject, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(devopsprojectsResource, "status", devOpsProject), &v1alpha3.DevOpsProject{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha3.DevOpsProject), err +} + +// Delete takes name of the devOpsProject and deletes it. Returns an error if one occurs. +func (c *FakeDevOpsProjects) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteAction(devopsprojectsResource, name), &v1alpha3.DevOpsProject{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeDevOpsProjects) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(devopsprojectsResource, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha3.DevOpsProjectList{}) + return err +} + +// Patch applies the patch and returns the patched devOpsProject. +func (c *FakeDevOpsProjects) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha3.DevOpsProject, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(devopsprojectsResource, name, pt, data, subresources...), &v1alpha3.DevOpsProject{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha3.DevOpsProject), err +} diff --git a/pkg/client/clientset/versioned/typed/devops/v1alpha3/generated_expansion.go b/pkg/client/clientset/versioned/typed/devops/v1alpha3/generated_expansion.go new file mode 100644 index 0000000000000000000000000000000000000000..24c0980835f32f7e7c5c9a1bc12dc905b245478b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/devops/v1alpha3/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha3 + +type DevOpsProjectExpansion interface{} diff --git a/pkg/client/informers/externalversions/devops/interface.go b/pkg/client/informers/externalversions/devops/interface.go index a4f26e4cdd487e5a34341dab0eb8b38ab225c59e..f5e53aa440374df575df3f6bb4e612b3bca6dcaf 100644 --- a/pkg/client/informers/externalversions/devops/interface.go +++ b/pkg/client/informers/externalversions/devops/interface.go @@ -20,6 +20,7 @@ package devops import ( v1alpha1 "kubesphere.io/kubesphere/pkg/client/informers/externalversions/devops/v1alpha1" + v1alpha3 "kubesphere.io/kubesphere/pkg/client/informers/externalversions/devops/v1alpha3" internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" ) @@ -27,6 +28,8 @@ import ( type Interface interface { // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.Interface + // V1alpha3 provides access to shared informers for resources in V1alpha3. + V1alpha3() v1alpha3.Interface } type group struct { @@ -44,3 +47,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (g *group) V1alpha1() v1alpha1.Interface { return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) } + +// V1alpha3 returns a new v1alpha3.Interface. +func (g *group) V1alpha3() v1alpha3.Interface { + return v1alpha3.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/devops/v1alpha3/devopsproject.go b/pkg/client/informers/externalversions/devops/v1alpha3/devopsproject.go new file mode 100644 index 0000000000000000000000000000000000000000..23de56b291f89603a07b1dfa217adf1d04336412 --- /dev/null +++ b/pkg/client/informers/externalversions/devops/v1alpha3/devopsproject.go @@ -0,0 +1,88 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" + versioned "kubesphere.io/kubesphere/pkg/client/clientset/versioned" + internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" + v1alpha3 "kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha3" +) + +// DevOpsProjectInformer provides access to a shared informer and lister for +// DevOpsProjects. +type DevOpsProjectInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha3.DevOpsProjectLister +} + +type devOpsProjectInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewDevOpsProjectInformer constructs a new informer for DevOpsProject type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewDevOpsProjectInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredDevOpsProjectInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredDevOpsProjectInformer constructs a new informer for DevOpsProject type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredDevOpsProjectInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.DevopsV1alpha3().DevOpsProjects().List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.DevopsV1alpha3().DevOpsProjects().Watch(options) + }, + }, + &devopsv1alpha3.DevOpsProject{}, + resyncPeriod, + indexers, + ) +} + +func (f *devOpsProjectInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredDevOpsProjectInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *devOpsProjectInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&devopsv1alpha3.DevOpsProject{}, f.defaultInformer) +} + +func (f *devOpsProjectInformer) Lister() v1alpha3.DevOpsProjectLister { + return v1alpha3.NewDevOpsProjectLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/devops/v1alpha3/interface.go b/pkg/client/informers/externalversions/devops/v1alpha3/interface.go new file mode 100644 index 0000000000000000000000000000000000000000..91d7e6e0235b117a8e593cc81db84e8d86a44f07 --- /dev/null +++ b/pkg/client/informers/externalversions/devops/v1alpha3/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // DevOpsProjects returns a DevOpsProjectInformer. + DevOpsProjects() DevOpsProjectInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// DevOpsProjects returns a DevOpsProjectInformer. +func (v *version) DevOpsProjects() DevOpsProjectInformer { + return &devOpsProjectInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index b4763dd37f86774e4281f0549e387d48c9b27d9d..e798db28e3da932a8b5db014cc5d5c8381f21794 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -24,6 +24,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1" + v1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1" v1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" @@ -65,6 +66,10 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1alpha1.SchemeGroupVersion.WithResource("s2iruns"): return &genericInformer{resource: resource.GroupResource(), informer: f.Devops().V1alpha1().S2iRuns().Informer()}, nil + // Group=devops.kubesphere.io, Version=v1alpha3 + case v1alpha3.SchemeGroupVersion.WithResource("devopsprojects"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Devops().V1alpha3().DevOpsProjects().Informer()}, nil + // Group=network.kubesphere.io, Version=v1alpha1 case networkv1alpha1.SchemeGroupVersion.WithResource("namespacenetworkpolicies"): return &genericInformer{resource: resource.GroupResource(), informer: f.Network().V1alpha1().NamespaceNetworkPolicies().Informer()}, nil diff --git a/pkg/client/listers/devops/v1alpha3/devopsproject.go b/pkg/client/listers/devops/v1alpha3/devopsproject.go new file mode 100644 index 0000000000000000000000000000000000000000..8174f1873a81ffed802e1d9d7513b82828cf094a --- /dev/null +++ b/pkg/client/listers/devops/v1alpha3/devopsproject.go @@ -0,0 +1,65 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" +) + +// DevOpsProjectLister helps list DevOpsProjects. +type DevOpsProjectLister interface { + // List lists all DevOpsProjects in the indexer. + List(selector labels.Selector) (ret []*v1alpha3.DevOpsProject, err error) + // Get retrieves the DevOpsProject from the index for a given name. + Get(name string) (*v1alpha3.DevOpsProject, error) + DevOpsProjectListerExpansion +} + +// devOpsProjectLister implements the DevOpsProjectLister interface. +type devOpsProjectLister struct { + indexer cache.Indexer +} + +// NewDevOpsProjectLister returns a new DevOpsProjectLister. +func NewDevOpsProjectLister(indexer cache.Indexer) DevOpsProjectLister { + return &devOpsProjectLister{indexer: indexer} +} + +// List lists all DevOpsProjects in the indexer. +func (s *devOpsProjectLister) List(selector labels.Selector) (ret []*v1alpha3.DevOpsProject, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha3.DevOpsProject)) + }) + return ret, err +} + +// Get retrieves the DevOpsProject from the index for a given name. +func (s *devOpsProjectLister) Get(name string) (*v1alpha3.DevOpsProject, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha3.Resource("devopsproject"), name) + } + return obj.(*v1alpha3.DevOpsProject), nil +} diff --git a/pkg/client/listers/devops/v1alpha3/expansion_generated.go b/pkg/client/listers/devops/v1alpha3/expansion_generated.go new file mode 100644 index 0000000000000000000000000000000000000000..e7233bd7ed41f49d744498c7b644494985ef10bf --- /dev/null +++ b/pkg/client/listers/devops/v1alpha3/expansion_generated.go @@ -0,0 +1,23 @@ +/* +Copyright 2019 The KubeSphere authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha3 + +// DevOpsProjectListerExpansion allows custom methods to be added to +// DevOpsProjectLister. +type DevOpsProjectListerExpansion interface{} diff --git a/pkg/controller/devopsproject/devopsproject_controller.go b/pkg/controller/devopsproject/devopsproject_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..e47ccdb3710237b5d7265e9a2c3daf3538bd4c2b --- /dev/null +++ b/pkg/controller/devopsproject/devopsproject_controller.go @@ -0,0 +1,224 @@ +package s2ibinary + +import ( + "fmt" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + clientset "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + v1core "k8s.io/client-go/kubernetes/typed/core/v1" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + "k8s.io/klog" + devopsv1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3" + devopsClient "kubesphere.io/kubesphere/pkg/simple/client/devops" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" + "net/http" + "time" + + kubesphereclient "kubesphere.io/kubesphere/pkg/client/clientset/versioned" + devopsinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions/devops/v1alpha3" + devopslisters "kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha3" +) + +type DevOpsProjectController struct { + client clientset.Interface + kubesphereClient kubesphereclient.Interface + + eventBroadcaster record.EventBroadcaster + eventRecorder record.EventRecorder + + devOpsProjectLister devopslisters.DevOpsProjectLister + devOpsProjectSynced cache.InformerSynced + + workqueue workqueue.RateLimitingInterface + + workerLoopPeriod time.Duration + + devopsClient devopsClient.Interface +} + +func NewController(kubesphereClient kubesphereclient.Interface, + client clientset.Interface, + devopsClinet devopsClient.Interface, + devopsInformer devopsinformers.DevOpsProjectInformer) *DevOpsProjectController { + + broadcaster := record.NewBroadcaster() + broadcaster.StartLogging(func(format string, args ...interface{}) { + klog.Info(fmt.Sprintf(format, args)) + }) + broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")}) + recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "devopsproject-controller"}) + + v := &DevOpsProjectController{ + client: client, + devopsClient: devopsClinet, + kubesphereClient: kubesphereClient, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "devopsproject"), + devOpsProjectLister: devopsInformer.Lister(), + devOpsProjectSynced: devopsInformer.Informer().HasSynced, + workerLoopPeriod: time.Second, + } + + v.eventBroadcaster = broadcaster + v.eventRecorder = recorder + + devopsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: v.enqueueDevOpsProject, + UpdateFunc: func(oldObj, newObj interface{}) { + old := oldObj.(*devopsv1alpha3.DevOpsProject) + new := newObj.(*devopsv1alpha3.DevOpsProject) + if old.ResourceVersion == new.ResourceVersion { + return + } + v.enqueueDevOpsProject(newObj) + }, + DeleteFunc: v.enqueueDevOpsProject, + }) + return v +} + +// enqueueDevOpsProject takes a Foo resource and converts it into a namespace/name +// string which is then put onto the work workqueue. This method should *not* be +// passed resources of any type other than DevOpsProject. +func (c *DevOpsProjectController) enqueueDevOpsProject(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + utilruntime.HandleError(err) + return + } + c.workqueue.Add(key) +} + +func (c *DevOpsProjectController) processNextWorkItem() bool { + obj, shutdown := c.workqueue.Get() + + if shutdown { + return false + } + + err := func(obj interface{}) error { + defer c.workqueue.Done(obj) + var key string + var ok bool + + if key, ok = obj.(string); !ok { + c.workqueue.Forget(obj) + utilruntime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + if err := c.syncHandler(key); err != nil { + c.workqueue.AddRateLimited(key) + return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error()) + } + c.workqueue.Forget(obj) + klog.V(5).Infof("Successfully synced '%s'", key) + return nil + }(obj) + + if err != nil { + klog.Error(err, "could not reconcile devopsProject") + utilruntime.HandleError(err) + return true + } + + return true +} + +func (c *DevOpsProjectController) worker() { + + for c.processNextWorkItem() { + } +} + +func (c *DevOpsProjectController) Start(stopCh <-chan struct{}) error { + return c.Run(1, stopCh) +} + +func (c *DevOpsProjectController) Run(workers int, stopCh <-chan struct{}) error { + defer utilruntime.HandleCrash() + defer c.workqueue.ShutDown() + + klog.Info("starting devops project controller") + defer klog.Info("shutting down devops project controller") + + if !cache.WaitForCacheSync(stopCh, c.devOpsProjectSynced) { + return fmt.Errorf("failed to wait for caches to sync") + } + + for i := 0; i < workers; i++ { + go wait.Until(c.worker, c.workerLoopPeriod, stopCh) + } + + <-stopCh + return nil +} + +// syncHandler compares the actual state with the desired, and attempts to +// converge the two. It then updates the Status block of the devopsproject resource +// with the current status of the resource. +func (c *DevOpsProjectController) syncHandler(key string) error { + project, err := c.devOpsProjectLister.Get(key) + if err != nil { + if errors.IsNotFound(err) { + klog.Info(fmt.Sprintf("devopsproject '%s' in work queue no longer exists ", key)) + return nil + } + klog.Error(err, fmt.Sprintf("could not get devopsproject %s ", key)) + return err + } + if project.ObjectMeta.DeletionTimestamp.IsZero() { + if !sliceutil.HasString(project.ObjectMeta.Finalizers, devopsv1alpha3.DevOpsProjectFinalizerName) { + project.ObjectMeta.Finalizers = append(project.ObjectMeta.Finalizers, devopsv1alpha3.DevOpsProjectFinalizerName) + _, err := c.kubesphereClient.DevopsV1alpha3().DevOpsProjects().Update(project) + if err != nil { + klog.Error(err, fmt.Sprintf("failed to update project %s ", key)) + return err + } + } + + } else { + if sliceutil.HasString(project.ObjectMeta.Finalizers, devopsv1alpha3.DevOpsProjectFinalizerName) { + if err := c.deleteDevOpsProjectInDevOps(project); err != nil { + klog.Error(err, fmt.Sprintf("failed to delete resource %s in devops", key)) + return err + } + project.ObjectMeta.Finalizers = sliceutil.RemoveString(project.ObjectMeta.Finalizers, func(item string) bool { + return item == devopsv1alpha3.DevOpsProjectFinalizerName + }) + _, err := c.kubesphereClient.DevopsV1alpha3().DevOpsProjects().Update(project) + if err != nil { + klog.Error(err, fmt.Sprintf("failed to update project %s ", key)) + return err + } + } + + _, err := c.devopsClient.GetDevOpsProject(key) + if err != nil && devopsClient.GetDevOpsStatusCode(err) != http.StatusNotFound { + klog.Error(err, fmt.Sprintf("failed to get project %s ", key)) + return err + } else { + _, err := c.devopsClient.CreateDevOpsProject(key) + if err != nil { + klog.Error(err, fmt.Sprintf("failed to get project %s ", key)) + return err + } + } + } + + return nil +} + +func (c *DevOpsProjectController) deleteDevOpsProjectInDevOps(project *devopsv1alpha3.DevOpsProject) error { + + err := c.devopsClient.DeleteDevOpsProject(project.Name) + if err != nil { + klog.Errorf("error happened while deleting %s, %v", project.Name, err) + } + + return nil +} diff --git a/pkg/simple/client/devops/interface.go b/pkg/simple/client/devops/interface.go index 80b5ec6cf3b0a32b02362f43c83a1868f4e9ae0b..550c3497bf2e47fe239e5e9d39a1aa81490f93cd 100644 --- a/pkg/simple/client/devops/interface.go +++ b/pkg/simple/client/devops/interface.go @@ -1,5 +1,12 @@ package devops +import ( + "fmt" + "github.com/asaskevich/govalidator" + "net/http" + "strconv" +) + type Interface interface { CredentialOperator @@ -10,4 +17,30 @@ type Interface interface { ProjectMemberOperator ProjectPipelineOperator + + ProjectOperator +} + +func GetDevOpsStatusCode(devopsErr error) int { + if code, err := strconv.Atoi(devopsErr.Error()); err == nil { + message := http.StatusText(code) + if !govalidator.IsNull(message) { + return code + } + } + if jErr, ok := devopsErr.(*ErrorResponse); ok { + return jErr.Response.StatusCode + } + return http.StatusInternalServerError +} + +type ErrorResponse struct { + Body []byte + Response *http.Response + Message string +} + +func (e *ErrorResponse) Error() string { + u := fmt.Sprintf("%s://%s%s", e.Response.Request.URL.Scheme, e.Response.Request.URL.Host, e.Response.Request.URL.RequestURI()) + return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, u, e.Response.StatusCode, e.Message) } diff --git a/pkg/simple/client/devops/jenkins/build.go b/pkg/simple/client/devops/jenkins/build.go index 43f81a19c77ba58fadbdf72209df52c8b275689c..3db19be0d09f36305bbe4e7350af210f8aa8544d 100644 --- a/pkg/simple/client/devops/jenkins/build.go +++ b/pkg/simple/client/devops/jenkins/build.go @@ -399,7 +399,7 @@ func (b *Build) Poll(options ...interface{}) (int, error) { func (j *Jenkins) GetProjectPipelineBuildByType(projectId, pipelineId string, status string) (*devops.Build, error) { job, err := j.GetJob(pipelineId, projectId) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } build, err := job.getBuildByType(status) return build.Raw, nil @@ -407,7 +407,7 @@ func (j *Jenkins) GetProjectPipelineBuildByType(projectId, pipelineId string, st func (j *Jenkins) GetMultiBranchPipelineBuildByType(projectId, pipelineId, branch string, status string) (*devops.Build, error) { job, err := j.GetJob(pipelineId, projectId, branch) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } build, err := job.getBuildByType(status) return build.Raw, nil diff --git a/pkg/simple/client/devops/jenkins/member.go b/pkg/simple/client/devops/jenkins/member.go index 2d9cb47a3be17032f3abfa6343d8271d279e9f3f..8a27e77add4532beed1da8e0876bc989cf96a761 100644 --- a/pkg/simple/client/devops/jenkins/member.go +++ b/pkg/simple/client/devops/jenkins/member.go @@ -218,7 +218,7 @@ func (j *Jenkins) AddProjectMember(membership *devops.ProjectMembership) (*devop globalRole, err := j.GetGlobalRole(JenkinsAllUserRoleName) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } if globalRole == nil { _, err := j.AddGlobalRole(JenkinsAllUserRoleName, GlobalPermissionIds{ @@ -226,33 +226,33 @@ func (j *Jenkins) AddProjectMember(membership *devops.ProjectMembership) (*devop }, true) if err != nil { klog.Errorf("failed to create jenkins global role %+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } } err = globalRole.AssignRole(membership.Username) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } projectRole, err := j.GetProjectRole(GetProjectRoleName(membership.ProjectId, membership.Role)) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = projectRole.AssignRole(membership.Username) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipelineRole, err := j.GetProjectRole(GetPipelineRoleName(membership.ProjectId, membership.Role)) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = pipelineRole.AssignRole(membership.Username) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return membership, nil } @@ -260,42 +260,42 @@ func (j *Jenkins) AddProjectMember(membership *devops.ProjectMembership) (*devop func (j *Jenkins) UpdateProjectMember(oldMembership, newMembership *devops.ProjectMembership) (*devops.ProjectMembership, error) { oldProjectRole, err := j.GetProjectRole(GetProjectRoleName(oldMembership.ProjectId, oldMembership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = oldProjectRole.UnAssignRole(newMembership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } oldPipelineRole, err := j.GetProjectRole(GetPipelineRoleName(oldMembership.ProjectId, oldMembership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = oldPipelineRole.UnAssignRole(newMembership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } projectRole, err := j.GetProjectRole(GetProjectRoleName(oldMembership.ProjectId, newMembership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = projectRole.AssignRole(newMembership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipelineRole, err := j.GetProjectRole(GetPipelineRoleName(oldMembership.ProjectId, newMembership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = pipelineRole.AssignRole(newMembership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return newMembership, nil } @@ -303,20 +303,20 @@ func (j *Jenkins) UpdateProjectMember(oldMembership, newMembership *devops.Proje func (j *Jenkins) DeleteProjectMember(membership *devops.ProjectMembership) (*devops.ProjectMembership, error) { oldProjectRole, err := j.GetProjectRole(GetProjectRoleName(membership.ProjectId, membership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = oldProjectRole.UnAssignRole(membership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } oldPipelineRole, err := j.GetProjectRole(GetPipelineRoleName(membership.ProjectId, membership.Role)) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = oldPipelineRole.UnAssignRole(membership.Username) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return membership, nil } diff --git a/pkg/simple/client/devops/jenkins/project.go b/pkg/simple/client/devops/jenkins/project.go index 43579e688bf60cbb86024e7379a060e0cbc9a5f4..d1ccea4c1d2108470a560d3d599989519be66f93 100644 --- a/pkg/simple/client/devops/jenkins/project.go +++ b/pkg/simple/client/devops/jenkins/project.go @@ -3,10 +3,8 @@ package jenkins import ( "github.com/emicklei/go-restful" "k8s.io/klog" - "kubesphere.io/kubesphere/pkg/api/devops/v1alpha2" "kubesphere.io/kubesphere/pkg/simple/client/devops" "net/http" - "sync" ) type DevOpsProjectRoleResponse struct { @@ -14,96 +12,31 @@ type DevOpsProjectRoleResponse struct { Err error } -func (j *Jenkins) CreateDevOpsProject(username string, project *v1alpha2.DevOpsProject) (*v1alpha2.DevOpsProject, error) { - _, err := j.CreateFolder(project.ProjectId, project.Description) +func (j *Jenkins) CreateDevOpsProject(projectId string) (string, error) { + _, err := j.CreateFolder(projectId, "") if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } - - var addRoleCh = make(chan *DevOpsProjectRoleResponse, 8) - var addRoleWg sync.WaitGroup - for role, permission := range JenkinsProjectPermissionMap { - addRoleWg.Add(1) - go func(role string, permission ProjectPermissionIds) { - _, err := j.AddProjectRole(GetProjectRoleName(project.ProjectId, role), - GetProjectRolePattern(project.ProjectId), permission, true) - addRoleCh <- &DevOpsProjectRoleResponse{nil, err} - addRoleWg.Done() - }(role, permission) - } - for role, permission := range JenkinsPipelinePermissionMap { - addRoleWg.Add(1) - go func(role string, permission ProjectPermissionIds) { - _, err := j.AddProjectRole(GetPipelineRoleName(project.ProjectId, role), - GetPipelineRolePattern(project.ProjectId), permission, true) - addRoleCh <- &DevOpsProjectRoleResponse{nil, err} - addRoleWg.Done() - }(role, permission) - } - addRoleWg.Wait() - close(addRoleCh) - for addRoleResponse := range addRoleCh { - if addRoleResponse.Err != nil { - klog.Errorf("%+v", addRoleResponse.Err) - return nil, restful.NewError(GetJenkinsStatusCode(addRoleResponse.Err), addRoleResponse.Err.Error()) - } - } - - globalRole, err := j.GetGlobalRole(JenkinsAllUserRoleName) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - if globalRole == nil { - _, err := j.AddGlobalRole(JenkinsAllUserRoleName, GlobalPermissionIds{ - GlobalRead: true, - }, true) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - } - err = globalRole.AssignRole(username) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - - projectRole, err := j.GetProjectRole(GetProjectRoleName(project.ProjectId, devops.ProjectOwner)) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - err = projectRole.AssignRole(username) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - - pipelineRole, err := j.GetProjectRole(GetPipelineRoleName(project.ProjectId, devops.ProjectOwner)) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - err = pipelineRole.AssignRole(username) - if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) - } - return project, nil + return projectId, nil } func (j *Jenkins) DeleteDevOpsProject(projectId string) error { _, err := j.DeleteJob(projectId) - if err != nil && GetJenkinsStatusCode(err) != http.StatusNotFound { + if err != nil && devops.GetDevOpsStatusCode(err) != http.StatusNotFound { klog.Errorf("%+v", err) - return restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } + return nil +} - roleNames := make([]string, 0) - for role := range JenkinsProjectPermissionMap { - roleNames = append(roleNames, GetProjectRoleName(projectId, role)) - roleNames = append(roleNames, GetPipelineRoleName(projectId, role)) - } - err = j.DeleteProjectRoles(roleNames...) +func (j *Jenkins) GetDevOpsProject(projectId string) (string, error) { + job, err := j.GetJob(projectId) if err != nil { klog.Errorf("%+v", err) - return restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) + } - return nil + return job.GetName(), nil } diff --git a/pkg/simple/client/devops/jenkins/project_pipeline.go b/pkg/simple/client/devops/jenkins/project_pipeline.go index 7768c2fb32e5f737b92f0e23a847ffbcff6d49e6..4a28028c4a47bd8ee84a8e8edc9b75f8e38f252a 100644 --- a/pkg/simple/client/devops/jenkins/project_pipeline.go +++ b/pkg/simple/client/devops/jenkins/project_pipeline.go @@ -23,13 +23,13 @@ func (j *Jenkins) CreateProjectPipeline(projectId string, pipeline *devops.Proje return "", restful.NewError(http.StatusConflict, err.Error()) } - if err != nil && GetJenkinsStatusCode(err) != http.StatusNotFound { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + if err != nil && devops.GetDevOpsStatusCode(err) != http.StatusNotFound { + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } _, err = j.CreateJobInFolder(config, pipeline.Pipeline.Name, projectId) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return pipeline.Pipeline.Name, nil @@ -45,13 +45,13 @@ func (j *Jenkins) CreateProjectPipeline(projectId string, pipeline *devops.Proje return "", restful.NewError(http.StatusConflict, err.Error()) } - if err != nil && GetJenkinsStatusCode(err) != http.StatusNotFound { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + if err != nil && devops.GetDevOpsStatusCode(err) != http.StatusNotFound { + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } _, err = j.CreateJobInFolder(config, pipeline.MultiBranchPipeline.Name, projectId) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return pipeline.MultiBranchPipeline.Name, nil @@ -66,7 +66,7 @@ func (j *Jenkins) CreateProjectPipeline(projectId string, pipeline *devops.Proje func (j *Jenkins) DeleteProjectPipeline(projectId string, pipelineId string) (string, error) { _, err := j.DeleteJob(pipelineId, projectId) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return pipelineId, nil @@ -83,12 +83,12 @@ func (j *Jenkins) UpdateProjectPipeline(projectId string, pipeline *devops.Proje job, err := j.GetJob(pipeline.Pipeline.Name, projectId) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = job.UpdateConfig(config) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return pipeline.Pipeline.Name, nil @@ -104,13 +104,13 @@ func (j *Jenkins) UpdateProjectPipeline(projectId string, pipeline *devops.Proje job, err := j.GetJob(pipeline.MultiBranchPipeline.Name, projectId) if err != nil { - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } err = job.UpdateConfig(config) if err != nil { klog.Errorf("%+v", err) - return "", restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } return pipeline.MultiBranchPipeline.Name, nil @@ -126,17 +126,17 @@ func (j *Jenkins) GetProjectPipelineConfig(projectId, pipelineId string) (*devop job, err := j.GetJob(pipelineId, projectId) if err != nil { klog.Errorf("%+v", err) - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } switch job.Raw.Class { case "org.jenkinsci.plugins.workflow.job.WorkflowJob": config, err := job.GetConfig() if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipeline, err := parsePipelineConfigXml(config) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipeline.Name = pipelineId return &devops.ProjectPipeline{ @@ -147,11 +147,11 @@ func (j *Jenkins) GetProjectPipelineConfig(projectId, pipelineId string) (*devop case "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject": config, err := job.GetConfig() if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipeline, err := parseMultiBranchPipelineConfigXml(config) if err != nil { - return nil, restful.NewError(GetJenkinsStatusCode(err), err.Error()) + return nil, restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) } pipeline.Name = pipelineId return &devops.ProjectPipeline{ diff --git a/pkg/simple/client/devops/jenkins/request.go b/pkg/simple/client/devops/jenkins/request.go index 6239162eae4d1959f3d4aff54bb1cf563a21430e..968d0cc003e191327489e9def54b1975fe1e705b 100644 --- a/pkg/simple/client/devops/jenkins/request.go +++ b/pkg/simple/client/devops/jenkins/request.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "io/ioutil" + "kubesphere.io/kubesphere/pkg/simple/client/devops" "mime/multipart" "net/http" "net/url" @@ -64,7 +65,7 @@ func (r *Requester) SetCrumb(ar *APIRequest) error { crumbData := map[string]string{} response, err := r.GetJSON("/crumbIssuer/api/json", &crumbData, nil) if err != nil { - jenkinsError, ok := err.(*ErrorResponse) + jenkinsError, ok := err.(*devops.ErrorResponse) if ok && jenkinsError.Response.StatusCode == http.StatusNotFound { return nil } @@ -440,16 +441,6 @@ func (r *Requester) ReadJSONResponse(response *http.Response, responseStruct int return response, nil } -type ErrorResponse struct { - Body []byte - Response *http.Response - Message string -} - -func (e *ErrorResponse) Error() string { - u := fmt.Sprintf("%s://%s%s", e.Response.Request.URL.Scheme, e.Response.Request.URL.Host, e.Response.Request.URL.RequestURI()) - return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, u, e.Response.StatusCode, e.Message) -} func CheckResponse(r *http.Response) error { switch r.StatusCode { @@ -457,7 +448,7 @@ func CheckResponse(r *http.Response) error { return nil } defer r.Body.Close() - errorResponse := &ErrorResponse{Response: r} + errorResponse := &devops.ErrorResponse{Response: r} data, err := ioutil.ReadAll(r.Body) if err == nil && data != nil { errorResponse.Body = data diff --git a/pkg/simple/client/devops/jenkins/utils.go b/pkg/simple/client/devops/jenkins/utils.go index f080fedc8df972a035aa258da202211f1230e39d..e7893fee48a5d4906f32b8181f3e6725e1efda91 100644 --- a/pkg/simple/client/devops/jenkins/utils.go +++ b/pkg/simple/client/devops/jenkins/utils.go @@ -17,13 +17,11 @@ package jenkins import ( "compress/gzip" "encoding/json" - "github.com/asaskevich/govalidator" "io" "io/ioutil" "k8s.io/klog" "net/http" "net/url" - "strconv" "strings" "time" "unicode/utf8" @@ -131,16 +129,3 @@ func (t *JenkinsBlueTime) UnmarshalJSON(b []byte) error { func (t JenkinsBlueTime) MarshalJSON() ([]byte, error) { return json.Marshal(time.Time(t)) } - -func GetJenkinsStatusCode(jenkinsErr error) int { - if code, err := strconv.Atoi(jenkinsErr.Error()); err == nil { - message := http.StatusText(code) - if !govalidator.IsNull(message) { - return code - } - } - if jErr, ok := jenkinsErr.(*ErrorResponse); ok { - return jErr.Response.StatusCode - } - return http.StatusInternalServerError -} diff --git a/pkg/simple/client/devops/project.go b/pkg/simple/client/devops/project.go index 2ce7a782b13db9fa0bdf4fef0d1c9962ce861bde..bd0a0252be4f1d4a025984ac819d082fd39978cd 100644 --- a/pkg/simple/client/devops/project.go +++ b/pkg/simple/client/devops/project.go @@ -1,8 +1,12 @@ package devops -import "kubesphere.io/kubesphere/pkg/api/devops/v1alpha2" - +/** +project operator, providing API for creating/getting/deleting projects +The actual data of the project is stored in the CRD, +so we only need to create the project with the corresponding ID in the CI/CD system. +*/ type ProjectOperator interface { - CreateDevOpsProject(username string, project *v1alpha2.DevOpsProject) (*v1alpha2.DevOpsProject, error) + CreateDevOpsProject(projectId string) (string, error) DeleteDevOpsProject(projectId string) error + GetDevOpsProject(projectId string) (string, error) }