├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ └── feature_request.yml ├── PULL_REQUEST_TEMPLATE.md ├── release-drafter.yml └── workflows │ ├── build.yaml │ └── release-drafter.yml ├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── .golangci.yml ├── .licenserc.yaml ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── OWNERS ├── PROJECT ├── README.md ├── api └── openapi-spec │ └── swagger.json ├── assets ├── embed.go └── swagger-ui │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── index.html │ ├── oauth2-redirect.html │ ├── swagger-ui-bundle.js │ ├── swagger-ui-standalone-preset.js │ ├── swagger-ui.css │ └── swagger-ui.js ├── charts └── README.md ├── cmd ├── README.md ├── allinone │ ├── app │ │ └── entrypoint.go │ └── main.go ├── apiserver │ ├── apiserver.go │ └── app │ │ ├── options │ │ ├── options.go │ │ └── validation.go │ │ └── server.go ├── controller │ ├── app │ │ ├── controllers.go │ │ ├── helper.go │ │ ├── options │ │ │ ├── feature.go │ │ │ ├── feature_test.go │ │ │ ├── options.go │ │ │ └── options_test.go │ │ └── server.go │ └── main.go └── tools │ ├── app │ ├── restore_config.go │ ├── restore_config_test.go │ ├── root.go │ └── utils.go │ ├── doc-gen │ └── main.go │ └── main.go ├── codecov.yml ├── config ├── certmanager │ ├── certificate.yaml │ ├── kustomization.yaml │ └── kustomizeconfig.yaml ├── crd │ ├── bases │ │ ├── devops.kubesphere.io_addons.yaml │ │ ├── devops.kubesphere.io_addonstrategies.yaml │ │ ├── devops.kubesphere.io_clustersteptemplates.yaml │ │ ├── devops.kubesphere.io_clustertemplates.yaml │ │ ├── devops.kubesphere.io_devopsprojects.yaml │ │ ├── devops.kubesphere.io_gitrepositories.yaml │ │ ├── devops.kubesphere.io_pipelineruns.yaml │ │ ├── devops.kubesphere.io_pipelines.yaml │ │ ├── devops.kubesphere.io_s2ibinaries.yaml │ │ ├── devops.kubesphere.io_s2ibuilders.yaml │ │ ├── devops.kubesphere.io_s2ibuildertemplates.yaml │ │ ├── devops.kubesphere.io_s2iruns.yaml │ │ ├── devops.kubesphere.io_templates.yaml │ │ ├── devops.kubesphere.io_webhooks.yaml │ │ ├── gitops.kubesphere.io_applications.yaml │ │ └── gitops.kubesphere.io_imageupdaters.yaml │ ├── kustomization.yaml │ ├── kustomizeconfig.yaml │ └── patches │ │ ├── cainjection_in_clustertemplates.yaml │ │ ├── cainjection_in_fakes.yaml │ │ ├── cainjection_in_pipelineruns.yaml │ │ ├── cainjection_in_pipelines.yaml │ │ ├── cainjection_in_templates.yaml │ │ ├── webhook_in_clustertemplates.yaml │ │ ├── webhook_in_fakes.yaml │ │ ├── webhook_in_pipelineruns.yaml │ │ ├── webhook_in_pipelines.yaml │ │ └── webhook_in_templates.yaml ├── default │ ├── kustomization.yaml │ ├── manager_auth_proxy_patch.yaml │ ├── manager_webhook_patch.yaml │ └── webhookcainjection_patch.yaml ├── dockerfiles │ ├── apiserver │ │ └── Dockerfile │ ├── controller-manager │ │ └── Dockerfile │ └── tools │ │ └── Dockerfile ├── jenkins │ ├── deploy.yaml │ └── service.yaml ├── manager │ ├── apiserver-service.yaml │ ├── apiserver.yaml │ ├── config.yaml │ ├── kustomization.yaml │ ├── manager.yaml │ └── nameReference.yaml ├── prometheus │ ├── kustomization.yaml │ └── monitor.yaml ├── rbac │ ├── auth_proxy_client_clusterrole.yaml │ ├── auth_proxy_role.yaml │ ├── auth_proxy_role_binding.yaml │ ├── auth_proxy_service.yaml │ ├── clustertemplate_editor_role.yaml │ ├── clustertemplate_viewer_role.yaml │ ├── kustomization.yaml │ ├── leader_election_role.yaml │ ├── leader_election_role_binding.yaml │ ├── pipeline_editor_role.yaml │ ├── pipeline_viewer_role.yaml │ ├── pipelinerun_editor_role.yaml │ ├── pipelinerun_viewer_role.yaml │ ├── role.yaml │ ├── role_binding.yaml │ ├── template_editor_role.yaml │ └── template_viewer_role.yaml ├── samples │ ├── addon │ │ ├── argocd.yaml │ │ ├── argocd_simple_operator.yaml │ │ ├── ks_releaser.yaml │ │ └── ks_releaser_simple_operator.yaml │ ├── devops.kubesphere.io_v1alpha3_pipeline.yaml │ ├── devops_v1alpha1_clustertemplate.yaml │ ├── devops_v1alpha1_template.yaml │ ├── devops_v1alpha3_steptemplate.yaml │ ├── devops_v1alpha4_pipelinerun.yaml │ ├── devops_v1alpha4_pipelinerun_multi_branch_demo.yaml │ ├── devops_v1alpha4_pipelinerun_with_parameters.yaml │ ├── gitRepository_webhooks │ │ ├── devops.yaml │ │ ├── git_repository_webhook_controller.yaml │ │ └── kustomization.yaml │ ├── gitops │ │ ├── application.yaml │ │ ├── fluxcd-application-helmrelease.yaml │ │ ├── fluxcd-application-helmtemplate.yaml │ │ ├── fluxcd-application-kustomization.yaml │ │ └── image-updater.yaml │ ├── gitrepository.yaml │ ├── jenkins-agent-config.yaml │ ├── kubesphere.yaml │ ├── secret.yaml │ └── webhook.yaml └── webhook │ ├── kustomization.yaml │ ├── kustomizeconfig.yaml │ └── service.yaml ├── controllers ├── README.md ├── addon │ ├── addon_controller.go │ ├── addon_controller_test.go │ ├── operator_controller.go │ └── operator_controller_test.go ├── argocd │ ├── application_controller.go │ ├── application_controller_test.go │ ├── argocd-application-status-controller.go │ ├── argocd-application-status-controller_test.go │ ├── constants.go │ ├── data │ │ ├── argo-status-without-summary.json │ │ └── argo-status.json │ ├── git-repository-controller.go │ ├── git-repository-controller_test.go │ ├── image-updater-controller.go │ ├── image-updater-controller_test.go │ ├── interface_test.go │ ├── multi-cluster-controller.go │ ├── multi-cluster-controller_test.go │ ├── project_controller.go │ ├── project_controller_test.go │ ├── types.go │ ├── types_test.go │ ├── utils.go │ └── utils_test.go ├── core │ ├── fake.go │ ├── fake_manager.go │ ├── fake_manager_test.go │ ├── fake_test.go │ ├── named.go │ └── named_test.go ├── fluxcd │ ├── application-controller.go │ ├── application-controller_test.go │ ├── constants.go │ ├── fluxcd-application-status-controller.go │ ├── fluxcd-application-status-controller_test.go │ ├── git-repository-controller.go │ ├── git-repository-controller_test.go │ ├── multi-cluster-controller.go │ └── multi-cluster-controller_test.go ├── gitrepository │ ├── constants.go │ ├── gitrepository_amend_controller.go │ ├── gitrepository_amend_controller_test.go │ ├── gitrepository_webhook_controller.go │ ├── gitrepository_webhook_controller_test.go │ ├── interface_test.go │ ├── pull_request_status_controller.go │ ├── pull_request_status_controller_test.go │ ├── register.go │ ├── register_test.go │ ├── testdata │ │ ├── hook.json │ │ ├── hooks.json │ │ ├── pr.json │ │ ├── status.json │ │ └── statuses.json │ ├── webhook_notify.go │ └── webhook_notify_test.go ├── jenkins │ ├── README.md │ ├── config │ │ ├── README.md │ │ ├── agent_config.go │ │ ├── agent_config_test.go │ │ ├── constant.go │ │ ├── interface_test.go │ │ ├── jenkinsconfig_controller.go │ │ ├── jenkinsconfig_controller_test.go │ │ ├── labels_controller.go │ │ ├── labels_controller_test.go │ │ ├── podtemplate_controller.go │ │ ├── podtemplate_controller_test.go │ │ └── testdata │ │ │ └── casc.yaml │ ├── devopscredential │ │ ├── devopscredential_controller.go │ │ └── devopscredential_controller_test.go │ ├── devopsproject │ │ ├── devopsproject_controller.go │ │ └── devopsproject_controller_test.go │ ├── pipeline │ │ ├── constants.go │ │ ├── interface_test.go │ │ ├── json_converter.go │ │ ├── json_converter_test.go │ │ ├── metadata_converter.go │ │ ├── metadata_converter_test.go │ │ ├── pipeline_controller.go │ │ ├── pipeline_controller_test.go │ │ ├── pipeline_metadata_controller.go │ │ ├── pipeline_metadata_controller_test.go │ │ └── setup_test.go │ └── pipelinerun │ │ ├── jenkins_handler.go │ │ ├── jenkins_handler_test.go │ │ ├── pipelinerun_controller.go │ │ ├── pipelinerun_controller_test.go │ │ ├── pipelinerun_finder.go │ │ ├── pipelinerun_finder_test.go │ │ ├── pipelinerun_synchronizer.go │ │ ├── pipelinerun_synchronizer_test.go │ │ ├── setup_test.go │ │ ├── utils.go │ │ └── utils_test.go ├── predicate │ ├── label.go │ └── label_test.go └── suite_test.go ├── docs ├── README.md ├── addon.md ├── cli.md ├── customize-pipeline-steps.md ├── e2e.md ├── faq.md ├── gc.md ├── image-automation.md ├── installation.md ├── permission.md ├── pipeline-template.md ├── pod-template.md ├── projects.md ├── swagger.md ├── testing.md ├── webhook-management.md └── webhook.md ├── go.mod ├── go.sum ├── hack ├── boilerplate.go.txt ├── generate_client.sh └── generate_group.sh ├── pkg ├── api │ ├── devops │ │ ├── constants.go │ │ ├── register.go │ │ ├── v1alpha1 │ │ │ ├── doc.go │ │ │ ├── groupversion_info.go │ │ │ ├── groupversion_info_test.go │ │ │ ├── s2ibinary_types.go │ │ │ ├── s2ibinary_types_test.go │ │ │ ├── s2ibuilder_types.go │ │ │ ├── s2ibuilder_types_test.go │ │ │ ├── s2ibuildertemplate_types.go │ │ │ ├── s2ibuildertemplate_types_test.go │ │ │ ├── s2irun_types.go │ │ │ ├── s2irun_types_test.go │ │ │ └── zz_generated.deepcopy.go │ │ ├── v1alpha3 │ │ │ ├── addon.go │ │ │ ├── addon_strategy.go │ │ │ ├── addon_strategy_test.go │ │ │ ├── clustertemplate_types.go │ │ │ ├── credential_types.go │ │ │ ├── credential_types_test.go │ │ │ ├── devopsproject_types.go │ │ │ ├── gitrepository.go │ │ │ ├── groupversion_info.go │ │ │ ├── groupversion_info_test.go │ │ │ ├── last_changes.go │ │ │ ├── last_changes_test.go │ │ │ ├── pipeline_types.go │ │ │ ├── pipeline_types_test.go │ │ │ ├── pipelinerun_types.go │ │ │ ├── pipelinerun_types_test.go │ │ │ ├── steptemplate_render.go │ │ │ ├── steptemplate_render_test.go │ │ │ ├── steptemplate_types.go │ │ │ ├── template_interface.go │ │ │ ├── template_types.go │ │ │ ├── testdata │ │ │ │ ├── credential-kubeconfig.json │ │ │ │ ├── credential-ssh.json │ │ │ │ ├── credential-string.json │ │ │ │ ├── docker-login.json │ │ │ │ ├── dsl-echo.json │ │ │ │ └── sh-echo.json │ │ │ ├── webhook.go │ │ │ └── zz_generated.deepcopy.go │ │ └── violation_exceptions.list │ ├── gitops │ │ └── v1alpha1 │ │ │ ├── application.go │ │ │ ├── constants.go │ │ │ ├── groupversion_info.go │ │ │ ├── groupversion_info_test.go │ │ │ ├── image-updater.go │ │ │ ├── image-updater_test.go │ │ │ └── zz_generated.deepcopy.go │ └── types.go ├── apis │ ├── addtoscheme_devops_v1alpha3.go │ ├── apis.go │ └── apis_test.go ├── apiserver │ ├── apiserver.go │ ├── authentication │ │ ├── authenticators │ │ │ └── bearertoken │ │ │ │ └── bearertoken.go │ │ ├── oauth │ │ │ ├── oauth_options.go │ │ │ └── oauth_options_test.go │ │ ├── options │ │ │ └── authenticate_options.go │ │ └── request │ │ │ └── anonymous │ │ │ └── anonymous.go │ ├── filters │ │ ├── authentication.go │ │ ├── kubeapiserver.go │ │ └── requestinfo.go │ ├── request │ │ ├── context.go │ │ ├── context_test.go │ │ ├── requestinfo.go │ │ └── requestinfo_test.go │ ├── runtime │ │ ├── runtime.go │ │ └── runtime_test.go │ └── swagger │ │ └── swagger.go ├── client │ ├── cache │ │ ├── cache.go │ │ ├── options.go │ │ ├── redis.go │ │ ├── simple_cache.go │ │ └── simple_cache_test.go │ ├── clientset │ │ └── versioned │ │ │ ├── clientset.go │ │ │ ├── doc.go │ │ │ ├── fake │ │ │ ├── clientset_generated.go │ │ │ ├── doc.go │ │ │ └── register.go │ │ │ ├── scheme │ │ │ ├── doc.go │ │ │ └── register.go │ │ │ └── typed │ │ │ └── devops │ │ │ ├── v1alpha1 │ │ │ ├── devops_client.go │ │ │ ├── doc.go │ │ │ ├── fake │ │ │ │ ├── doc.go │ │ │ │ ├── fake_devops_client.go │ │ │ │ ├── fake_s2ibinary.go │ │ │ │ ├── fake_s2ibuilder.go │ │ │ │ ├── fake_s2ibuildertemplate.go │ │ │ │ └── fake_s2irun.go │ │ │ ├── generated_expansion.go │ │ │ ├── s2ibinary.go │ │ │ ├── s2ibuilder.go │ │ │ ├── s2ibuildertemplate.go │ │ │ └── s2irun.go │ │ │ └── v1alpha3 │ │ │ ├── devops_client.go │ │ │ ├── devopsproject.go │ │ │ ├── doc.go │ │ │ ├── fake │ │ │ ├── doc.go │ │ │ ├── fake_devops_client.go │ │ │ ├── fake_devopsproject.go │ │ │ └── fake_pipeline.go │ │ │ ├── generated_expansion.go │ │ │ └── pipeline.go │ ├── devops │ │ ├── OWNERS │ │ ├── build.go │ │ ├── configuration.go │ │ ├── credential.go │ │ ├── fake │ │ │ ├── fakeJenkinsClient.go │ │ │ ├── fakedevops.go │ │ │ └── fakedevops_test.go │ │ ├── interface.go │ │ ├── interface_test.go │ │ ├── jclient │ │ │ ├── build.go │ │ │ ├── configuration.go │ │ │ ├── credential.go │ │ │ ├── credential_test.go │ │ │ ├── jenkins.go │ │ │ ├── pipeline.go │ │ │ ├── project.go │ │ │ └── projectPipeline.go │ │ ├── jenkins │ │ │ ├── README.md │ │ │ ├── build.go │ │ │ ├── constants.go │ │ │ ├── credential.go │ │ │ ├── devops.go │ │ │ ├── devops_test.go │ │ │ ├── folder.go │ │ │ ├── internal │ │ │ │ ├── bitbucket.go │ │ │ │ ├── common_test.go │ │ │ │ ├── git.go │ │ │ │ ├── github.go │ │ │ │ ├── gitlab.go │ │ │ │ ├── pull_request.go │ │ │ │ ├── pull_request_test.go │ │ │ │ ├── scm.go │ │ │ │ └── svn.go │ │ │ ├── jenkins.go │ │ │ ├── job.go │ │ │ ├── options.go │ │ │ ├── pipeline.go │ │ │ ├── pipeline_internal.go │ │ │ ├── pipeline_internal_test.go │ │ │ ├── pipeline_model_converter.go │ │ │ ├── pipeline_test.go │ │ │ ├── project.go │ │ │ ├── project_pipeline.go │ │ │ ├── pure_request.go │ │ │ ├── request.go │ │ │ ├── request_test.go │ │ │ ├── triggers │ │ │ │ ├── genericwebhook.go │ │ │ │ └── genericwebhook_test.go │ │ │ ├── utils.go │ │ │ └── utils_test.go │ │ ├── pipeline.go │ │ ├── pipeline_test.go │ │ ├── project.go │ │ ├── project_pipeline.go │ │ ├── role.go │ │ └── util │ │ │ └── credential.go │ ├── git │ │ ├── client.go │ │ ├── client_test.go │ │ ├── message.go │ │ └── message_test.go │ ├── informers │ │ └── externalversions │ │ │ ├── devops │ │ │ ├── interface.go │ │ │ ├── v1alpha1 │ │ │ │ ├── interface.go │ │ │ │ ├── s2ibinary.go │ │ │ │ ├── s2ibuilder.go │ │ │ │ ├── s2ibuildertemplate.go │ │ │ │ └── s2irun.go │ │ │ └── v1alpha3 │ │ │ │ ├── devopsproject.go │ │ │ │ ├── interface.go │ │ │ │ └── pipeline.go │ │ │ ├── factory.go │ │ │ ├── generic.go │ │ │ ├── internalinterfaces │ │ │ └── factory_interfaces.go │ │ │ └── types │ │ │ └── interface.go │ ├── k8s │ │ ├── fake_client.go │ │ ├── kubernetes.go │ │ ├── kubernetes_test.go │ │ ├── options.go │ │ └── options_test.go │ ├── listers │ │ └── devops │ │ │ ├── v1alpha1 │ │ │ ├── expansion_generated.go │ │ │ ├── gitrepository.go │ │ │ ├── s2ibinary.go │ │ │ ├── s2ibuilder.go │ │ │ ├── s2ibuildertemplate.go │ │ │ ├── s2irun.go │ │ │ └── webhook.go │ │ │ └── v1alpha3 │ │ │ ├── devopsproject.go │ │ │ ├── expansion_generated.go │ │ │ └── pipeline.go │ ├── s3 │ │ ├── fake │ │ │ ├── fakes3.go │ │ │ └── fakes3_test.go │ │ ├── interface.go │ │ ├── options.go │ │ └── s3.go │ └── sonarqube │ │ ├── OWNERS │ │ ├── interface.go │ │ ├── interface_test.go │ │ ├── options.go │ │ ├── options_test.go │ │ ├── sonarqube.go │ │ └── sonarqube_test.go ├── config │ ├── config.go │ └── gitops.go ├── constants │ └── constants.go ├── event │ ├── README.md │ ├── common │ │ └── types.go │ └── workflowrun │ │ ├── actions.go │ │ ├── actions_test.go │ │ ├── parameter_action.go │ │ ├── parameter_action_test.go │ │ ├── types.go │ │ ├── workflowrun_handler.go │ │ └── workflowrun_handler_test.go ├── external │ └── fluxcd │ │ ├── helm │ │ └── v2beta1 │ │ │ ├── condition_types.go │ │ │ ├── doc.go │ │ │ ├── groupversion_info.go │ │ │ ├── helmrelease_types.go │ │ │ ├── reference_types.go │ │ │ └── zz_generated.deepcopy.go │ │ ├── kustomize │ │ └── v1beta2 │ │ │ ├── condition_types.go │ │ │ ├── doc.go │ │ │ ├── groupversion_info.go │ │ │ ├── kustomization_types.go │ │ │ ├── kustomize_types.go │ │ │ ├── reference_types.go │ │ │ └── zz_generated.deepcopy.go │ │ ├── meta │ │ ├── annotations.go │ │ ├── conditions.go │ │ ├── doc.go │ │ ├── reference_types.go │ │ └── zz_generated.deepcopy.go │ │ └── source │ │ └── v1beta2 │ │ ├── artifact_types.go │ │ ├── doc.go │ │ ├── groupversion_info.go │ │ ├── helmchart_types.go │ │ └── zz_generated.deepcopy.go ├── indexers │ ├── indexers.go │ └── indexers_test.go ├── informers │ ├── informers.go │ └── null_informers.go ├── jwt │ └── token │ │ ├── fake_issuer.go │ │ ├── fake_issuer_test.go │ │ ├── issuer.go │ │ ├── jwt.go │ │ └── jwt_test.go ├── kapis │ ├── common │ │ ├── options.go │ │ └── options_test.go │ ├── devops │ │ ├── group.go │ │ ├── v1alpha2 │ │ │ ├── OWNERS │ │ │ ├── devops.go │ │ │ ├── devops_test.go │ │ │ ├── handler.go │ │ │ ├── pipeline_sonar.go │ │ │ ├── proxy.go │ │ │ ├── proxy_test.go │ │ │ ├── register.go │ │ │ ├── register_test.go │ │ │ ├── s2ibinary.go │ │ │ └── sonarqube.go │ │ └── v1alpha3 │ │ │ ├── common │ │ │ └── options.go │ │ │ ├── gitops │ │ │ ├── factory.go │ │ │ ├── git.go │ │ │ ├── handler.go │ │ │ ├── route.go │ │ │ └── types.go │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── pipeline │ │ │ ├── branch_filter.go │ │ │ ├── branch_filter_test.go │ │ │ ├── handler.go │ │ │ ├── register.go │ │ │ └── register_test.go │ │ │ ├── pipelinerun │ │ │ ├── backwardlisthandler.go │ │ │ ├── backwardlisthandler_test.go │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── listhandler.go │ │ │ ├── listhandler_test.go │ │ │ ├── register.go │ │ │ ├── register_test.go │ │ │ ├── util.go │ │ │ └── util_test.go │ │ │ ├── register.go │ │ │ ├── register_test.go │ │ │ ├── scm │ │ │ ├── gitrepository_handler.go │ │ │ ├── gitrepository_handler_test.go │ │ │ ├── route.go │ │ │ ├── scmhandler.go │ │ │ ├── scmhandler_test.go │ │ │ ├── testdata │ │ │ │ ├── orgs.json │ │ │ │ ├── repos.json │ │ │ │ └── user.json │ │ │ ├── types.go │ │ │ └── utils.go │ │ │ ├── steptemplate │ │ │ ├── handler.go │ │ │ ├── route.go │ │ │ └── route_test.go │ │ │ ├── template │ │ │ ├── cluster_template_handler.go │ │ │ ├── cluster_template_handler_test.go │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── render.go │ │ │ ├── render_test.go │ │ │ ├── route.go │ │ │ ├── route_test.go │ │ │ ├── template_handler.go │ │ │ └── template_handler_test.go │ │ │ ├── utils │ │ │ ├── utils.go │ │ │ └── utils_test.go │ │ │ └── webhook │ │ │ ├── handler.go │ │ │ ├── register.go │ │ │ ├── register_test.go │ │ │ ├── scm.go │ │ │ ├── scm_test.go │ │ │ ├── workflowrun_handler.go │ │ │ └── workflowrun_handler_test.go │ ├── gitops │ │ └── v1alpha1 │ │ │ ├── argocd │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── route.go │ │ │ └── route_test.go │ │ │ ├── fluxcd │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── route.go │ │ │ └── route_test.go │ │ │ ├── gitops │ │ │ ├── handler.go │ │ │ ├── handler_test.go │ │ │ ├── util.go │ │ │ └── util_test.go │ │ │ ├── registery.go │ │ │ └── registery_test.go │ ├── oauth │ │ ├── handler.go │ │ ├── register.go │ │ └── register_test.go │ ├── proxy │ │ └── register.go │ ├── utils.go │ └── utils_test.go ├── models │ ├── auth │ │ ├── token.go │ │ └── token_test.go │ ├── devops │ │ ├── OWNERS │ │ ├── common.go │ │ ├── common_test.go │ │ ├── devops.go │ │ ├── devops_test.go │ │ ├── jkerror.go │ │ ├── jkerror_test.go │ │ ├── project_credential_handler.go │ │ ├── project_credential_handler_test.go │ │ ├── project_pipeline_sonar_handler.go │ │ ├── project_pipeline_sonar_handler_test.go │ │ ├── s2ibinary_handler.go │ │ └── s2ibinary_handler_test.go │ ├── pipeline │ │ ├── pipeline.go │ │ └── pipeline_test.go │ └── pipelinerun │ │ └── pipelinerun.go ├── server │ ├── errors │ │ └── errors.go │ ├── options │ │ └── options.go │ └── params │ │ ├── params.go │ │ └── params_test.go ├── store │ ├── configmap │ │ ├── pipelinerun.go │ │ └── pipelinerun_test.go │ ├── fake │ │ ├── fake_core_test.go │ │ └── fake_store.go │ └── store │ │ ├── types.go │ │ └── types_test.go ├── utils │ ├── hash.go │ ├── hashutil │ │ ├── MD5.go │ │ └── MD5_test.go │ ├── idutils │ │ ├── id_utils.go │ │ └── id_utils_test.go │ ├── k8sutil │ │ ├── k8sutil.go │ │ ├── k8sutil_test.go │ │ ├── objectmeta.go │ │ └── objectmeta_test.go │ ├── net │ │ ├── net.go │ │ └── net_test.go │ ├── readerutils │ │ ├── MD5Reader.go │ │ └── MD5Reader_test.go │ ├── reflectutils │ │ ├── deep.go │ │ └── reflect.go │ ├── secretutil │ │ ├── secret_mask.go │ │ └── secret_mask_test.go │ ├── sliceutil │ │ ├── sliceutils.go │ │ └── sliceutils_test.go │ └── stringutils │ │ ├── error.go │ │ ├── error_test.go │ │ ├── string.go │ │ └── string_test.go └── version │ └── version.go └── test ├── api ├── README.md ├── data │ └── devops_v1alpha3_steptemplate.yaml ├── testcase-1.yaml ├── testcase-2.yaml └── testcase-render.yaml └── e2e ├── cases └── chart-install │ ├── e2e.yaml │ └── expected.yaml └── common ├── kind-1.19.yaml ├── kind-1.20.yaml ├── kind-1.21.yaml ├── kind-1.22.yaml └── kind-1.23.yaml /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Search known questions in the Chinese KubeSphere forum 4 | url: https://kubesphere.com.cn/forum/ 5 | about: KubeSphere DevOps 中文用戶可以在论坛中搜索已知问题 6 | - name: Open Source Best Practice 7 | url: https://github.com/LinuxSuRen/open-source-best-practice 8 | about: 如果您参与开源的经历不多,欢迎阅读这份《参与开源最佳实践》 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: File a feature request 3 | labels: [kind/feature] 4 | body: 5 | - type: markdown 6 | id: preface 7 | attributes: 8 | value: "Hello there! Thank you for submitting new features for KubeSphere DevOps. Please spend a little bit to fill in the following instructions in detail. Before that, we highly recommend you to read [the open source best practice](https://github.com/LinuxSuRen/open-source-best-practice/blob/75efb3e5b460716e1e4e03fb3846f1876fd3a5c0/how-to-contribute.md) (which written in Chinese)." 9 | - type: input 10 | id: version 11 | validations: 12 | required: true 13 | attributes: 14 | label: What is version of KubeSphere DevOps has the issue? 15 | - type: input 16 | id: how-to-install 17 | attributes: 18 | label: "How did you install the Kubernetes? Or what is the Kubernetes distribution?" 19 | description: "In some cases, this is very important." 20 | validations: 21 | required: false 22 | - type: textarea 23 | id: description 24 | attributes: 25 | label: "Describe this feature" 26 | validations: 27 | required: true 28 | - type: textarea 29 | id: additional-information 30 | attributes: 31 | label: "Additional information" 32 | description: "If you have other information to note, you can fill it in here (screenshots, videos, etc.)." 33 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | # Configuration for Release Drafter: https://github.com/toolmantim/release-drafter 2 | name-template: 'v$NEXT_PATCH_VERSION 🌈' 3 | tag-template: 'v$NEXT_PATCH_VERSION' 4 | version-template: '$MAJOR.$MINOR.$PATCH' 5 | # Emoji reference: https://gitmoji.carloscuesta.me/ 6 | categories: 7 | - title: '🚀 Features' 8 | labels: 9 | - 'feature' 10 | - 'enhancement' 11 | - 'kind/feature' 12 | - title: '🐛 Bug Fixes' 13 | labels: 14 | - 'fix' 15 | - 'bugfix' 16 | - 'bug' 17 | - 'regression' 18 | - 'kind/bug' 19 | - title: '💥 Breaking changes' 20 | labels: 21 | - 'break' 22 | - 'kind/break' 23 | - title: '📝 Documentation updates' 24 | labels: 25 | - 'documentation' 26 | - 'kind/doc' 27 | - title: '👻 Maintenance' 28 | labels: 29 | - 'chore' 30 | - 'kind/chore' 31 | - 'dependencies' 32 | - title: '🚦 Tests' 33 | labels: 34 | - test 35 | - 'kind/test' 36 | - tests 37 | exclude-labels: 38 | - reverted 39 | - no-changelog 40 | - release-note-none 41 | - release-notes-none 42 | - skip-changelog 43 | - invalid 44 | change-template: '* $TITLE (#$NUMBER) @$AUTHOR' 45 | replacers: 46 | - search: '/(?:and )?@dependabot-preview(?:\[bot\])?,?/g' 47 | replace: '' 48 | - search: '/(?:and )?@ks-ci-bot,?/g' 49 | replace: '' 50 | template: | 51 | ## What’s Changed 52 | 53 | $CHANGES 54 | 55 | Thanks again to $CONTRIBUTORS! 🎉 56 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | update_release_draft: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: release-drafter/release-drafter@v5 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GHCR_TOKEN }} 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Binaries for programs and plugins 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | bin 9 | scripts 10 | 11 | # Test binary, build with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Kubernetes Generated files - skip generated files, except for vendored files 18 | 19 | !vendor/**/zz_generated.* 20 | 21 | # editor and IDE paraphernalia 22 | .idea 23 | .nocalhost 24 | *.swp 25 | *.swo 26 | *~ 27 | 28 | .vscode 29 | __debug_bin 30 | 31 | kubesphere.yaml 32 | */**/*.xml 33 | logs.txt 34 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | # More information: https://www.gitpod.io/docs/config-docker/ 4 | RUN sudo rm -rf /usr/bin/hd && \ 5 | brew install linuxsuren/linuxsuren/hd && \ 6 | hd install cli/cli && \ 7 | hd install ks && \ 8 | hd install minikube 9 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.Dockerfile 3 | 4 | tasks: 5 | - init: | 6 | [[ ! -z "${DOCKER_USER}" && ! -z "${DOCKER_PASSWD}" ]] && docker login -u${DOCKER_USER} -p${DOCKER_PASSWD} 7 | [[ ! -z "${GITHUB_USER}" && ! -z "${GITHUB_TOKEN}" ]] && docker login ghcr.io/linuxsuren -u${GITHUB_USER} -p${GITHUB_TOKEN} 8 | git config --global user.name $GIT_AUTHOR_NAME 9 | git config --global user.email $GIT_COMMITTER_EMAIL 10 | echo kubesphere/ks-devops | gh repo fork --remote 11 | make docker-build-push-controller 12 | make docker-build-push-apiserver 13 | -------------------------------------------------------------------------------- /.licenserc.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 The KubeSphere Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | header: 18 | license: 19 | spdx-id: Apache-2.0 20 | copyright-owner: KubeSphere Authors 21 | 22 | paths-ignore: 23 | - 'charts' 24 | - 'config' 25 | - 'hack' 26 | - 'test' 27 | - 'vendor' 28 | - 'LICENSE' 29 | - 'OWNERS' 30 | - 'PROJECT' 31 | - 'Makefile' 32 | - 'codecov.yml' 33 | - '**/testdata/**' 34 | - '**/*.md' 35 | - '**/go.mod' 36 | - '**/go.sum' 37 | - '.devcontainer' 38 | - '.github' 39 | - '.gitignore' 40 | - '.gitpod*' 41 | - '.golangci.yml' 42 | - '.licenserc.yaml' 43 | - 'cmd/tools/jwt/app/mock_app' 44 | - 'pkg/api/devops/violation_exceptions.list' 45 | - 'pkg/client/devops/jenkins/build.go' 46 | - 'pkg/client/devops/jenkins/folder.go' 47 | - 'pkg/client/devops/jenkins/jenkins.go' 48 | - 'pkg/client/devops/jenkins/job.go' 49 | - 'pkg/client/devops/jenkins/request.go' 50 | - 'pkg/client/devops/jenkins/utils.go' 51 | - '**/*.json' 52 | 53 | comment: on-failure 54 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - chilianyi 3 | - zheng1 4 | - stoneshi-yunify 5 | - renyunkang 6 | 7 | reviewers: 8 | - chilianyi 9 | - zheng1 10 | - stoneshi-yunify 11 | - renyunkang 12 | -------------------------------------------------------------------------------- /PROJECT: -------------------------------------------------------------------------------- 1 | domain: kubesphere.io 2 | repo: github.com/kubesphere/ks-devops 3 | resources: 4 | - group: devops 5 | kind: Pipeline 6 | version: v1alpha3 7 | - group: devops 8 | kind: PipelineRun 9 | version: v1alpha3 10 | - group: devops 11 | kind: Template 12 | version: v1alpha1 13 | - group: devops 14 | kind: ClusterTemplate 15 | version: v1alpha1 16 | - group: gitops 17 | kind: Application 18 | version: v1alpha1 19 | version: "2" 20 | -------------------------------------------------------------------------------- /assets/embed.go: -------------------------------------------------------------------------------- 1 | package assets 2 | 3 | import ( 4 | "embed" 5 | ) 6 | 7 | //go:embed swagger-ui 8 | var Static embed.FS 9 | -------------------------------------------------------------------------------- /assets/swagger-ui/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubesphere/ks-devops/a11e1c6b7a46b2eb031143b0468691f2e8eea9ea/assets/swagger-ui/favicon-16x16.png -------------------------------------------------------------------------------- /assets/swagger-ui/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubesphere/ks-devops/a11e1c6b7a46b2eb031143b0468691f2e8eea9ea/assets/swagger-ui/favicon-32x32.png -------------------------------------------------------------------------------- /assets/swagger-ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Swagger UI 7 | 8 | 9 | 10 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | 38 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /charts/README.md: -------------------------------------------------------------------------------- 1 | See also [kubesphere-sigs/ks-devops-helm-chart](https://github.com/kubesphere-sigs/ks-devops-helm-chart). 2 | -------------------------------------------------------------------------------- /cmd/README.md: -------------------------------------------------------------------------------- 1 | There're two components in `ks-devops`, they are APIServer and controller-manager. 2 | Normally, they run in a Kubernetes cluster as Pods. But technically, they also are 3 | regular executable binary files. So, you can run `ks-devops` as a binary file. 4 | 5 | There're three commands here: 6 | 7 | * [apiserver](apiserver) 8 | * [controller-manager](controller) 9 | * [All in One](allinone) 10 | * Combine apiserver and controller-manager into one command. 11 | 12 | ## Others 13 | 14 | There're some small tools under this directory. -------------------------------------------------------------------------------- /cmd/allinone/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/cmd/allinone/app" 21 | "log" 22 | ) 23 | 24 | func main() { 25 | cmd := app.NewCommand() 26 | if err := cmd.Execute(); err != nil { 27 | log.Fatalln(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cmd/apiserver/apiserver.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "log" 21 | 22 | "github.com/kubesphere/ks-devops/cmd/apiserver/app" 23 | ) 24 | 25 | func main() { 26 | cmd := app.NewAPIServerCommand() 27 | 28 | if err := cmd.Execute(); err != nil { 29 | log.Fatalln(err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cmd/apiserver/app/options/validation.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package options 18 | 19 | // Validate validates server run options, to find 20 | // options' misconfiguration 21 | func (s *ServerRunOptions) Validate() []error { 22 | var errors []error 23 | 24 | errors = append(errors, s.GenericServerRunOptions.Validate()...) 25 | errors = append(errors, s.JenkinsOptions.Validate()...) 26 | errors = append(errors, s.KubernetesOptions.Validate()...) 27 | errors = append(errors, s.SonarQubeOptions.Validate()...) 28 | errors = append(errors, s.S3Options.Validate()...) 29 | 30 | return errors 31 | } 32 | -------------------------------------------------------------------------------- /cmd/controller/app/options/options_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package options 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | func TestOption(t *testing.T) { 26 | opt := NewDevOpsControllerManagerOptions() 27 | assert.NotNil(t, opt) 28 | 29 | flags := opt.Flags() 30 | assert.NotNil(t, flags) 31 | assert.NotNil(t, flags.FlagSet("kubernetes")) 32 | assert.NotNil(t, flags.FlagSet("devops")) 33 | assert.NotNil(t, flags.FlagSet("feature")) 34 | assert.NotNil(t, flags.FlagSet("argocd")) 35 | assert.NotNil(t, flags.FlagSet("generic")) 36 | assert.NotNil(t, flags.FlagSet("leaderelection")) 37 | assert.NotNil(t, flags.FlagSet("klog")) 38 | 39 | opt.ApplicationSelector = "key=value" 40 | assert.Nil(t, opt.Validate()) 41 | 42 | opt.ApplicationSelector = "!@#$" 43 | assert.NotNil(t, opt.Validate()) 44 | } 45 | -------------------------------------------------------------------------------- /cmd/controller/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/kubesphere/ks-devops/cmd/controller/app" 23 | ) 24 | 25 | func main() { 26 | command := app.NewControllerManagerCommand() 27 | 28 | if err := command.Execute(); err != nil { 29 | os.Exit(1) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cmd/tools/app/root.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package app 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | var toolOpt *ToolOptions 24 | 25 | type ToolOptions struct { 26 | kubeconfig string 27 | } 28 | 29 | func (o *ToolOptions) runHelpE(cmd *cobra.Command, args []string) error { 30 | return cmd.Help() 31 | } 32 | 33 | // NewToolsCmd creates a root command for tools 34 | func NewToolsCmd() (cmd *cobra.Command) { 35 | opts := &ToolOptions{} 36 | 37 | rootCmd := &cobra.Command{ 38 | Use: "devops-tools", 39 | Short: "Tools for DevOps services", 40 | RunE: toolOpt.runHelpE, 41 | } 42 | 43 | flags := rootCmd.PersistentFlags() 44 | flags.StringVarP(&opts.kubeconfig, "kubeconfig", "k", "", 45 | "path of kubernetes kubeconfig file, default: Using the inClusterConfig") 46 | 47 | rootCmd.AddCommand(NewRestoreCmd(opts.kubeconfig)) 48 | return rootCmd 49 | } 50 | -------------------------------------------------------------------------------- /cmd/tools/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/kubesphere/ks-devops/cmd/tools/app" 23 | ) 24 | 25 | func main() { 26 | command := app.NewToolsCmd() 27 | if err := command.Execute(); err != nil { 28 | command.PrintErrf("execute command error: %+v", err) 29 | os.Exit(1) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # https://docs.codecov.com/docs/ignoring-paths 2 | ignore: 3 | - "*generated*.go" 4 | - "**/*generated*.go" # glob accepted 5 | - "pkg/client/clientset/versioned" 6 | - "pkg/client/listers" 7 | - "pkg/client/informers" 8 | 9 | # https://docs.codecov.com/docs/commit-status 10 | # it's hard to have a coverage for some code lines 11 | coverage: 12 | status: 13 | project: 14 | default: 15 | target: auto 16 | threshold: 0.1% 17 | patch: 18 | default: 19 | target: auto 20 | threshold: 0% 21 | -------------------------------------------------------------------------------- /config/certmanager/certificate.yaml: -------------------------------------------------------------------------------- 1 | # The following manifests contain a self-signed issuer CR and a certificate CR. 2 | # More document can be found at https://docs.cert-manager.io 3 | # WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for 4 | # breaking changes 5 | apiVersion: cert-manager.io/v1alpha2 6 | kind: Issuer 7 | metadata: 8 | name: selfsigned-issuer 9 | namespace: system 10 | spec: 11 | selfSigned: {} 12 | --- 13 | apiVersion: cert-manager.io/v1alpha2 14 | kind: Certificate 15 | metadata: 16 | name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml 17 | namespace: system 18 | spec: 19 | # $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize 20 | dnsNames: 21 | - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc 22 | - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local 23 | issuerRef: 24 | kind: Issuer 25 | name: selfsigned-issuer 26 | secretName: webhook-server-cert # this secret will not be prefixed, since it's not managed by kustomize 27 | -------------------------------------------------------------------------------- /config/certmanager/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - certificate.yaml 3 | 4 | configurations: 5 | - kustomizeconfig.yaml 6 | -------------------------------------------------------------------------------- /config/certmanager/kustomizeconfig.yaml: -------------------------------------------------------------------------------- 1 | # This configuration is for teaching kustomize how to update name ref and var substitution 2 | nameReference: 3 | - kind: Issuer 4 | group: cert-manager.io 5 | fieldSpecs: 6 | - kind: Certificate 7 | group: cert-manager.io 8 | path: spec/issuerRef/name 9 | 10 | varReference: 11 | - kind: Certificate 12 | group: cert-manager.io 13 | path: spec/commonName 14 | - kind: Certificate 15 | group: cert-manager.io 16 | path: spec/dnsNames 17 | -------------------------------------------------------------------------------- /config/crd/kustomizeconfig.yaml: -------------------------------------------------------------------------------- 1 | # This file is for teaching kustomize how to substitute name and namespace reference in CRD 2 | nameReference: 3 | - kind: Service 4 | version: v1 5 | fieldSpecs: 6 | - kind: CustomResourceDefinition 7 | group: apiextensions.k8s.io 8 | path: spec/conversion/webhookClientConfig/service/name 9 | 10 | namespace: 11 | - kind: CustomResourceDefinition 12 | group: apiextensions.k8s.io 13 | path: spec/conversion/webhookClientConfig/service/namespace 14 | create: false 15 | 16 | varReference: 17 | - path: metadata/annotations 18 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_clustertemplates.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | annotations: 7 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 8 | name: clustertemplates.devops.kubesphere.io 9 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_fakes.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | annotations: 7 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 8 | name: fakes.devops.kubesphere.io 9 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_pipelineruns.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | annotations: 7 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 8 | name: pipelineruns.devops.kubesphere.io 9 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_pipelines.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | annotations: 7 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 8 | name: pipelines.devops.kubesphere.io 9 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_templates.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | annotations: 7 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 8 | name: templates.devops.kubesphere.io 9 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_clustertemplates.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables conversion webhook for CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | name: clustertemplates.devops.kubesphere.io 7 | spec: 8 | conversion: 9 | strategy: Webhook 10 | webhookClientConfig: 11 | # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, 12 | # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) 13 | caBundle: Cg== 14 | service: 15 | namespace: system 16 | name: webhook-service 17 | path: /convert 18 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_fakes.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables conversion webhook for CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | name: fakes.devops.kubesphere.io 7 | spec: 8 | conversion: 9 | strategy: Webhook 10 | webhookClientConfig: 11 | # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, 12 | # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) 13 | caBundle: Cg== 14 | service: 15 | namespace: system 16 | name: webhook-service 17 | path: /convert 18 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_pipelineruns.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables conversion webhook for CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | name: pipelineruns.devops.kubesphere.io 7 | spec: 8 | conversion: 9 | strategy: Webhook 10 | webhookClientConfig: 11 | # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, 12 | # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) 13 | caBundle: Cg== 14 | service: 15 | namespace: system 16 | name: webhook-service 17 | path: /convert 18 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_pipelines.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables conversion webhook for CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | name: pipelines.devops.kubesphere.io 7 | spec: 8 | conversion: 9 | strategy: Webhook 10 | webhookClientConfig: 11 | # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, 12 | # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) 13 | caBundle: Cg== 14 | service: 15 | namespace: system 16 | name: webhook-service 17 | path: /convert 18 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_templates.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables conversion webhook for CRD 2 | # CRD conversion requires k8s 1.13 or later. 3 | apiVersion: apiextensions.k8s.io/v1beta1 4 | kind: CustomResourceDefinition 5 | metadata: 6 | name: templates.devops.kubesphere.io 7 | spec: 8 | conversion: 9 | strategy: Webhook 10 | webhookClientConfig: 11 | # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, 12 | # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) 13 | caBundle: Cg== 14 | service: 15 | namespace: system 16 | name: webhook-service 17 | path: /convert 18 | -------------------------------------------------------------------------------- /config/default/manager_auth_proxy_patch.yaml: -------------------------------------------------------------------------------- 1 | # This patch inject a sidecar container which is a HTTP proxy for the 2 | # controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: controller-manager 7 | namespace: system 8 | spec: 9 | template: 10 | spec: 11 | containers: 12 | - name: kube-rbac-proxy 13 | image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 14 | args: 15 | - "--secure-listen-address=0.0.0.0:8443" 16 | - "--upstream=http://127.0.0.1:8080/" 17 | - "--logtostderr=true" 18 | - "--v=10" 19 | ports: 20 | - containerPort: 8443 21 | name: https 22 | - name: manager 23 | args: 24 | - "--metrics-addr=127.0.0.1:8080" 25 | - "--enable-leader-election" 26 | -------------------------------------------------------------------------------- /config/default/manager_webhook_patch.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: controller-manager 5 | namespace: system 6 | spec: 7 | template: 8 | spec: 9 | containers: 10 | - name: manager 11 | ports: 12 | - containerPort: 9443 13 | name: webhook-server 14 | protocol: TCP 15 | volumeMounts: 16 | - mountPath: /tmp/k8s-webhook-server/serving-certs 17 | name: cert 18 | readOnly: true 19 | volumes: 20 | - name: cert 21 | secret: 22 | defaultMode: 420 23 | secretName: webhook-server-cert 24 | -------------------------------------------------------------------------------- /config/default/webhookcainjection_patch.yaml: -------------------------------------------------------------------------------- 1 | # This patch add annotation to admission webhook config and 2 | # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. 3 | apiVersion: admissionregistration.k8s.io/v1beta1 4 | kind: MutatingWebhookConfiguration 5 | metadata: 6 | name: mutating-webhook-configuration 7 | annotations: 8 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 9 | --- 10 | apiVersion: admissionregistration.k8s.io/v1beta1 11 | kind: ValidatingWebhookConfiguration 12 | metadata: 13 | name: validating-webhook-configuration 14 | annotations: 15 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 16 | -------------------------------------------------------------------------------- /config/dockerfiles/apiserver/Dockerfile: -------------------------------------------------------------------------------- 1 | # Build the manager binary 2 | FROM golang:1.23 AS builder 3 | 4 | ARG GOPROXY 5 | WORKDIR /workspace 6 | 7 | # Copy the Go Modules manifests 8 | COPY go.mod go.mod 9 | COPY go.sum go.sum 10 | 11 | # Copy the go source 12 | COPY cmd/ cmd/ 13 | COPY assets assets/ 14 | COPY pkg/ pkg/ 15 | 16 | # Build 17 | RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o apiserver cmd/apiserver/apiserver.go 18 | 19 | # Use distroless as minimal base image to package the manager binary 20 | # Refer to https://github.com/GoogleContainerTools/distroless for more details 21 | FROM gcr.io/distroless/static:nonroot 22 | WORKDIR / 23 | COPY --from=builder /workspace/apiserver . 24 | USER nonroot:nonroot 25 | 26 | ENTRYPOINT ["/apiserver"] 27 | -------------------------------------------------------------------------------- /config/dockerfiles/controller-manager/Dockerfile: -------------------------------------------------------------------------------- 1 | # Build the manager binary 2 | FROM golang:1.23 AS builder 3 | 4 | ARG GOPROXY 5 | WORKDIR /workspace 6 | 7 | # Copy the Go Modules manifests 8 | COPY go.mod go.mod 9 | COPY go.sum go.sum 10 | 11 | # Copy the go source 12 | COPY controllers/ controllers/ 13 | COPY cmd/ cmd/ 14 | COPY assets assets/ 15 | COPY pkg/ pkg/ 16 | 17 | # Build 18 | RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o controller-manager cmd/controller/main.go 19 | 20 | # Use distroless as minimal base image to package the manager binary 21 | # Refer to https://github.com/GoogleContainerTools/distroless for more details 22 | FROM gcr.io/distroless/static:nonroot 23 | WORKDIR / 24 | COPY --from=builder /workspace/controller-manager . 25 | USER nonroot:nonroot 26 | 27 | ENTRYPOINT ["/controller-manager"] 28 | -------------------------------------------------------------------------------- /config/dockerfiles/tools/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.23 as downloader 2 | RUN go install github.com/linuxsuren/http-downloader@v0.0.98 3 | RUN http-downloader install kubesphere-sigs/ks@v0.0.73 4 | 5 | # Build the tool binary 6 | FROM golang:1.23 AS builder 7 | 8 | ARG GOPROXY 9 | WORKDIR /workspace 10 | 11 | # Copy the Go Modules manifests 12 | COPY go.mod go.mod 13 | COPY go.sum go.sum 14 | 15 | # Copy the go source 16 | COPY cmd/ cmd/ 17 | COPY assets assets/ 18 | COPY pkg/ pkg/ 19 | 20 | # Build 21 | RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o devops-tools cmd/tools/main.go 22 | 23 | # Use distroless as minimal base image to package the manager binary 24 | # Refer to https://github.com/GoogleContainerTools/distroless for more details 25 | FROM gcr.io/distroless/static:nonroot 26 | COPY --from=builder /workspace/devops-tools /usr/local/bin/devops-tools 27 | COPY --from=downloader /usr/local/bin/ks /usr/local/bin/ks 28 | USER nonroot:nonroot 29 | 30 | CMD ["devops-tools"] 31 | -------------------------------------------------------------------------------- /config/jenkins/deploy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: ks-jenkins 5 | spec: 6 | selector: 7 | matchLabels: 8 | control-plane: ks-jenkins 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | control-plane: ks-jenkins 14 | spec: 15 | containers: 16 | - image: kubesphere/ks-jenkins:2.249.1 17 | name: jenkins 18 | ports: 19 | - containerPort: 8080 20 | name: http 21 | resources: 22 | limits: 23 | cpu: 1 24 | memory: 2000Mi 25 | requests: 26 | cpu: 100m 27 | memory: 20Mi 28 | terminationGracePeriodSeconds: 10 29 | -------------------------------------------------------------------------------- /config/jenkins/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: ks-jenkins 5 | labels: 6 | control-plane: ks-jenkins 7 | spec: 8 | type: NodePort 9 | ports: 10 | - port: 8080 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | selector: 15 | control-plane: ks-jenkins 16 | -------------------------------------------------------------------------------- /config/manager/apiserver-service.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: devops-apiserver 5 | namespace: kubesphere-devops-system 6 | labels: 7 | app.kubernetes.io/instance: devops 8 | app.kubernetes.io/managed-by: Helm 9 | app.kubernetes.io/name: ks-devops 10 | app.kubernetes.io/version: v3.2.1 11 | devops.kubesphere.io/component: apiserver 12 | helm.sh/chart: ks-devops-0.1.10 13 | annotations: 14 | meta.helm.sh/release-name: devops 15 | meta.helm.sh/release-namespace: kubesphere-devops-system 16 | spec: 17 | ports: 18 | - protocol: TCP 19 | port: 9090 20 | targetPort: 9090 21 | nodePort: 30427 22 | selector: 23 | app.kubernetes.io/instance: devops 24 | app.kubernetes.io/name: ks-devops 25 | devops.kubesphere.io/component: apiserver 26 | type: NodePort 27 | -------------------------------------------------------------------------------- /config/manager/config.yaml: -------------------------------------------------------------------------------- 1 | kind: ConfigMap 2 | apiVersion: v1 3 | metadata: 4 | name: devops-config 5 | namespace: kubesphere-devops-system 6 | labels: 7 | app.kubernetes.io/managed-by: Helm 8 | annotations: 9 | meta.helm.sh/release-name: devops 10 | meta.helm.sh/release-namespace: kubesphere-devops-system 11 | data: 12 | kubesphere.yaml: |- 13 | authentication: 14 | authenticateRateLimiterDuration: 10m0s 15 | authenticateRateLimiterMaxTries: "10" 16 | jwtSecret: FAGmFiOZ9gJ42A39YChcKVzL6u20Cwim 17 | loginHistoryRetentionPeriod: 168h 18 | maximumClockSkew: 10s 19 | devops: 20 | host: http://devops-jenkins.kubesphere-devops-system 21 | maxConnections: "100" 22 | namespace: kubesphere-devops-system 23 | username: admin 24 | workerNamespace: kubesphere-devops-worker 25 | ldap: 26 | groupSearchBase: ou=Groups,dc=kubesphere,dc=io 27 | host: openldap.kubesphere-system.svc:389 28 | managerDN: cn=admin,dc=kubesphere,dc=io 29 | managerPassword: admin 30 | userSearchBase: ou=Users,dc=kubesphere,dc=io 31 | s3: 32 | accessKeyID: openpitrixminioaccesskey 33 | bucket: s2i-binaries 34 | disableSSL: "True" 35 | endpoint: http://minio.kubesphere-system.svc:9000 36 | forcePathStyle: "True" 37 | region: us-east-1 38 | secretAccessKey: openpitrixminiosecretkey 39 | -------------------------------------------------------------------------------- /config/manager/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - manager.yaml 3 | - apiserver.yaml 4 | - apiserver-service.yaml 5 | - config.yaml 6 | 7 | configurations: 8 | - nameReference.yaml 9 | 10 | apiVersion: kustomize.config.k8s.io/v1beta1 11 | kind: Kustomization 12 | images: 13 | - name: ghcr.io/kubesphere/devops-apiserver:v3.3.0-rc.0 14 | newName: ghcr.io/kubesphere/devops-apiserver 15 | newTag: master 16 | - name: controller:latest 17 | newName: ghcr.io/kubesphere/devops-controller 18 | newTag: master -------------------------------------------------------------------------------- /config/manager/manager.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | labels: 5 | control-plane: controller-manager 6 | name: system 7 | --- 8 | apiVersion: apps/v1 9 | kind: Deployment 10 | metadata: 11 | name: controller-manager 12 | namespace: system 13 | labels: 14 | control-plane: controller-manager 15 | spec: 16 | selector: 17 | matchLabels: 18 | control-plane: controller-manager 19 | replicas: 1 20 | template: 21 | metadata: 22 | labels: 23 | control-plane: controller-manager 24 | spec: 25 | containers: 26 | - command: 27 | - /manager 28 | args: 29 | - --enable-leader-election 30 | image: controller:latest 31 | name: manager 32 | resources: 33 | limits: 34 | cpu: 100m 35 | memory: 30Mi 36 | requests: 37 | cpu: 100m 38 | memory: 20Mi 39 | terminationGracePeriodSeconds: 10 40 | -------------------------------------------------------------------------------- /config/manager/nameReference.yaml: -------------------------------------------------------------------------------- 1 | nameReference: 2 | - kind: ConfigMap 3 | fieldSpecs: 4 | - kind: Deployment 5 | path: spec/template/spec/volumes[0]/configmap/name 6 | - kind: Namespace 7 | fieldSpecs: 8 | - kind: Deployment 9 | path: spec/template/spec/initContainers[0]/command[6] 10 | - kind: Namespace 11 | fieldSpecs: 12 | - kind: Deployment 13 | path: spec/template/spec/initContainers[1]/command[5] -------------------------------------------------------------------------------- /config/prometheus/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - monitor.yaml 3 | -------------------------------------------------------------------------------- /config/prometheus/monitor.yaml: -------------------------------------------------------------------------------- 1 | 2 | # Prometheus Monitor Service (Metrics) 3 | apiVersion: monitoring.coreos.com/v1 4 | kind: ServiceMonitor 5 | metadata: 6 | labels: 7 | control-plane: controller-manager 8 | name: controller-manager-metrics-monitor 9 | namespace: system 10 | spec: 11 | endpoints: 12 | - path: /metrics 13 | port: https 14 | selector: 15 | matchLabels: 16 | control-plane: controller-manager 17 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_client_clusterrole.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRole 3 | metadata: 4 | name: metrics-reader 5 | rules: 6 | - nonResourceURLs: ["/metrics"] 7 | verbs: ["get"] 8 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_role.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRole 3 | metadata: 4 | name: proxy-role 5 | rules: 6 | - apiGroups: ["authentication.k8s.io"] 7 | resources: 8 | - tokenreviews 9 | verbs: ["create"] 10 | - apiGroups: ["authorization.k8s.io"] 11 | resources: 12 | - subjectaccessreviews 13 | verbs: ["create"] 14 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_role_binding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: proxy-rolebinding 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: ClusterRole 8 | name: proxy-role 9 | subjects: 10 | - kind: ServiceAccount 11 | name: default 12 | namespace: system 13 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | labels: 5 | control-plane: controller-manager 6 | name: controller-manager-metrics-service 7 | namespace: system 8 | spec: 9 | ports: 10 | - name: https 11 | port: 8443 12 | targetPort: https 13 | selector: 14 | control-plane: controller-manager 15 | -------------------------------------------------------------------------------- /config/rbac/clustertemplate_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to edit clustertemplates. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: clustertemplate-editor-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - clustertemplates 11 | verbs: 12 | - create 13 | - delete 14 | - get 15 | - list 16 | - patch 17 | - update 18 | - watch 19 | - apiGroups: 20 | - devops.kubesphere.io 21 | resources: 22 | - clustertemplates/status 23 | verbs: 24 | - get 25 | -------------------------------------------------------------------------------- /config/rbac/clustertemplate_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to view clustertemplates. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: clustertemplate-viewer-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - clustertemplates 11 | verbs: 12 | - get 13 | - list 14 | - watch 15 | - apiGroups: 16 | - devops.kubesphere.io 17 | resources: 18 | - clustertemplates/status 19 | verbs: 20 | - get 21 | -------------------------------------------------------------------------------- /config/rbac/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - role.yaml 3 | - role_binding.yaml 4 | - leader_election_role.yaml 5 | - leader_election_role_binding.yaml 6 | # Comment the following 4 lines if you want to disable 7 | # the auth proxy (https://github.com/brancz/kube-rbac-proxy) 8 | # which protects your /metrics endpoint. 9 | - auth_proxy_service.yaml 10 | - auth_proxy_role.yaml 11 | - auth_proxy_role_binding.yaml 12 | - auth_proxy_client_clusterrole.yaml 13 | -------------------------------------------------------------------------------- /config/rbac/leader_election_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions to do leader election. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: Role 4 | metadata: 5 | name: leader-election-role 6 | rules: 7 | - apiGroups: 8 | - "" 9 | resources: 10 | - configmaps 11 | verbs: 12 | - get 13 | - list 14 | - watch 15 | - create 16 | - update 17 | - patch 18 | - delete 19 | - apiGroups: 20 | - "" 21 | resources: 22 | - configmaps/status 23 | verbs: 24 | - get 25 | - update 26 | - patch 27 | - apiGroups: 28 | - "" 29 | resources: 30 | - events 31 | verbs: 32 | - create 33 | -------------------------------------------------------------------------------- /config/rbac/leader_election_role_binding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: RoleBinding 3 | metadata: 4 | name: leader-election-rolebinding 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: Role 8 | name: leader-election-role 9 | subjects: 10 | - kind: ServiceAccount 11 | name: default 12 | namespace: system 13 | -------------------------------------------------------------------------------- /config/rbac/pipeline_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to edit pipelines. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: pipeline-editor-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - pipelines 11 | verbs: 12 | - create 13 | - delete 14 | - get 15 | - list 16 | - patch 17 | - update 18 | - watch 19 | - apiGroups: 20 | - devops.kubesphere.io 21 | resources: 22 | - pipelines/status 23 | verbs: 24 | - get 25 | -------------------------------------------------------------------------------- /config/rbac/pipeline_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to view pipelines. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: pipeline-viewer-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - pipelines 11 | verbs: 12 | - get 13 | - list 14 | - watch 15 | - apiGroups: 16 | - devops.kubesphere.io 17 | resources: 18 | - pipelines/status 19 | verbs: 20 | - get 21 | -------------------------------------------------------------------------------- /config/rbac/pipelinerun_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to edit pipelineruns. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: pipelinerun-editor-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - pipelineruns 11 | verbs: 12 | - create 13 | - delete 14 | - get 15 | - list 16 | - patch 17 | - update 18 | - watch 19 | - apiGroups: 20 | - devops.kubesphere.io 21 | resources: 22 | - pipelineruns/status 23 | verbs: 24 | - get 25 | -------------------------------------------------------------------------------- /config/rbac/pipelinerun_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to view pipelineruns. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: pipelinerun-viewer-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - pipelineruns 11 | verbs: 12 | - get 13 | - list 14 | - watch 15 | - apiGroups: 16 | - devops.kubesphere.io 17 | resources: 18 | - pipelineruns/status 19 | verbs: 20 | - get 21 | -------------------------------------------------------------------------------- /config/rbac/role_binding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: manager-rolebinding 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: ClusterRole 8 | name: manager-role 9 | subjects: 10 | - kind: ServiceAccount 11 | name: default 12 | namespace: system 13 | -------------------------------------------------------------------------------- /config/rbac/template_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to edit templates. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: template-editor-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - templates 11 | verbs: 12 | - create 13 | - delete 14 | - get 15 | - list 16 | - patch 17 | - update 18 | - watch 19 | - apiGroups: 20 | - devops.kubesphere.io 21 | resources: 22 | - templates/status 23 | verbs: 24 | - get 25 | -------------------------------------------------------------------------------- /config/rbac/template_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # permissions for end users to view templates. 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: template-viewer-role 6 | rules: 7 | - apiGroups: 8 | - devops.kubesphere.io 9 | resources: 10 | - templates 11 | verbs: 12 | - get 13 | - list 14 | - watch 15 | - apiGroups: 16 | - devops.kubesphere.io 17 | resources: 18 | - templates/status 19 | verbs: 20 | - get 21 | -------------------------------------------------------------------------------- /config/samples/addon/argocd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: Addon 3 | metadata: 4 | name: argocd 5 | spec: 6 | version: v2.3.1 7 | strategy: 8 | name: simple-operator-argocd 9 | -------------------------------------------------------------------------------- /config/samples/addon/argocd_simple_operator.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: AddonStrategy 3 | metadata: 4 | name: simple-operator-argocd 5 | spec: 6 | type: simple-operator 7 | simpleOperator: 8 | apiVersion: argoproj.io/v1alpha1 9 | kind: ArgoCD 10 | template: | 11 | apiVersion: argoproj.io/v1alpha1 12 | kind: ArgoCD 13 | spec: 14 | version: {{.Spec.Version}} 15 | -------------------------------------------------------------------------------- /config/samples/addon/ks_releaser.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: Addon 3 | metadata: 4 | name: ks-releaser 5 | spec: 6 | version: v0.0.14 7 | strategy: 8 | name: simple-operator-releasercontroller 9 | -------------------------------------------------------------------------------- /config/samples/addon/ks_releaser_simple_operator.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: AddonStrategy 3 | metadata: 4 | name: ks-releaser-simple-operator 5 | spec: 6 | type: simple-operator 7 | simpleOperator: 8 | apiVersion: devops.kubesphere.io/v1alpha1 9 | kind: ReleaserController 10 | parameters: 11 | image: "ghcr.io/kubesphere-sigs/ks-releaser" 12 | template: | 13 | apiVersion: devops.kubesphere.io/v1alpha1 14 | kind: ReleaserController 15 | spec: 16 | image: {{.Spec.Parameters.image}} 17 | version: {{.Spec.Version}} 18 | webhook: false 19 | -------------------------------------------------------------------------------- /config/samples/devops.kubesphere.io_v1alpha3_pipeline.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: Pipeline 3 | metadata: 4 | name: pipeline-sample 5 | spec: 6 | # Add fields here 7 | foo: bar 8 | -------------------------------------------------------------------------------- /config/samples/devops_v1alpha3_steptemplate.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: ClusterStepTemplate 3 | metadata: 4 | name: steptemplate-sample 5 | spec: 6 | runtime: shell 7 | template: | 8 | echo 1 9 | -------------------------------------------------------------------------------- /config/samples/devops_v1alpha4_pipelinerun.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: devops.kubesphere.io/v1alpha3 3 | kind: DevOpsProject 4 | metadata: 5 | annotations: 6 | kubesphere.io/creator: admin 7 | name: demo-devopsproject 8 | status: 9 | adminNamespace: default 10 | --- 11 | apiVersion: devops.kubesphere.io/v1alpha3 12 | kind: Pipeline 13 | metadata: 14 | annotations: 15 | kubesphere.io/creator: admin 16 | name: demo-pipeline 17 | namespace: default 18 | spec: 19 | pipeline: 20 | disable_concurrent: true 21 | discarder: 22 | days_to_keep: "7" 23 | num_to_keep: "10" 24 | jenkinsfile: | 25 | pipeline { 26 | agent { 27 | node { 28 | label 'base' 29 | } 30 | } 31 | stages { 32 | stage('Greeting') { 33 | steps { 34 | container('base') { 35 | sh 'sleep 5 && echo "Hello, ks-devops!"' 36 | } 37 | } 38 | } 39 | } 40 | } 41 | name: good 42 | type: pipeline 43 | 44 | --- 45 | apiVersion: devops.kubesphere.io/v1alpha3 46 | kind: PipelineRun 47 | metadata: 48 | name: demo-pipelinerun 49 | namespace: default 50 | spec: 51 | pipelineRef: 52 | name: demo-pipeline 53 | -------------------------------------------------------------------------------- /config/samples/devops_v1alpha4_pipelinerun_multi_branch_demo.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Namespace 4 | metadata: 5 | name: demo-devopsproject 6 | --- 7 | apiVersion: devops.kubesphere.io/v1alpha3 8 | kind: DevOpsProject 9 | metadata: 10 | annotations: 11 | kubesphere.io/creator: admin 12 | name: demo-devopsproject 13 | status: 14 | adminNamespace: demo-devopsproject 15 | 16 | --- 17 | apiVersion: devops.kubesphere.io/v1alpha3 18 | kind: Pipeline 19 | metadata: 20 | annotations: 21 | kubesphere.io/creator: admin 22 | name: demo-multi-branch-pipeline 23 | namespace: demo-devopsproject 24 | spec: 25 | multi_branch_pipeline: 26 | discarder: 27 | days_to_keep: '-1' 28 | num_to_keep: '-1' 29 | git_source: 30 | discover_branches: true 31 | git_clone_option: 32 | depth: 1 33 | timeout: 20 34 | url: 'https://gitlab.com/johnniang/jenkinsfile-demo.git' 35 | name: demo-multi-branch-pipeline 36 | script_path: Jenkinsfile 37 | source_type: git 38 | type: multi-branch-pipeline 39 | 40 | --- 41 | apiVersion: devops.kubesphere.io/v1alpha3 42 | kind: PipelineRun 43 | metadata: 44 | generateName: demo-pipelinerun- 45 | namespace: demo-devopsproject 46 | spec: 47 | pipelineRef: 48 | name: demo-multi-branch-pipeline 49 | pipelineSpec: 50 | type: multi-branch-pipeline 51 | scm: 52 | refName: main 53 | refType: branch 54 | -------------------------------------------------------------------------------- /config/samples/gitRepository_webhooks/devops.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | data: 3 | kubesphere.yaml: |- 4 | devops: 5 | host: http://fake.com 6 | username: fake 7 | kind: ConfigMap 8 | metadata: 9 | name: devops-config 10 | -------------------------------------------------------------------------------- /config/samples/gitRepository_webhooks/git_repository_webhook_controller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: git-repository-webhook-controller 5 | labels: 6 | control-plane: git-repository-webhook-controller 7 | spec: 8 | selector: 9 | matchLabels: 10 | control-plane: git-repository-webhook-controller 11 | replicas: 1 12 | template: 13 | metadata: 14 | labels: 15 | control-plane: git-repository-webhook-controller 16 | spec: 17 | containers: 18 | - args: 19 | - --enabled-controllers 20 | - all=false,gitrepository=true 21 | image: ghcr.io/linuxsuren/devops-controller:webhook-manager 22 | name: manager 23 | volumeMounts: 24 | - mountPath: /etc/kubesphere/ 25 | name: devops-config 26 | resources: 27 | limits: 28 | cpu: 100m 29 | memory: 30Mi 30 | requests: 31 | cpu: 100m 32 | memory: 20Mi 33 | terminationGracePeriodSeconds: 10 34 | volumes: 35 | - configMap: 36 | defaultMode: 420 37 | name: devops-config 38 | name: devops-config -------------------------------------------------------------------------------- /config/samples/gitRepository_webhooks/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - git_repository_webhook_controller.yaml 3 | - devops.yaml 4 | -------------------------------------------------------------------------------- /config/samples/gitops/application.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: gitops.kubesphere.io/v1alpha1 2 | kind: Application 3 | metadata: 4 | name: app 5 | annotations: 6 | argocd-image-updater.argoproj.io/image-list: ghcr.io/linuxsuren-bot/open-podcasts-ui 7 | spec: 8 | argoApp: 9 | spec: 10 | project: testddmtg 11 | source: 12 | repoURL: https://github.com/linuxsuren-bot/open-podcasts/ 13 | targetRevision: HEAD 14 | path: config/default 15 | directory: 16 | recurse: true 17 | destination: 18 | server: https://kubernetes.default.svc 19 | namespace: default 20 | syncPolicy: 21 | automated: 22 | prune: true 23 | -------------------------------------------------------------------------------- /config/samples/gitops/fluxcd-application-helmtemplate.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: gitops.kubesphere.io/v1alpha1 2 | kind: Application 3 | metadata: 4 | name: chengleqi-test-template 5 | namespace: my-devops-projecthmhx2 6 | spec: 7 | kind: fluxcd 8 | fluxApp: 9 | spec: 10 | source: 11 | config: 12 | helmRelease: 13 | chart: 14 | template: chengleqi-test-helm 15 | deploy: 16 | - destination: 17 | # host cluster 18 | kubeConfig: 19 | targetNamespace: template-app 20 | interval: 1m0s 21 | upgrade: 22 | remediation: 23 | remediateLastFailure: true 24 | force: true 25 | install: 26 | createNamespace: true 27 | - destination: 28 | # member cluster 29 | kubeConfig: 30 | secretRef: 31 | name: node-1 32 | key: value 33 | targetNamespace: template-app 34 | storageNamespace: default 35 | interval: 1m0s 36 | upgrade: 37 | remediation: 38 | remediateLastFailure: true 39 | force: true 40 | install: 41 | createNamespace: true 42 | -------------------------------------------------------------------------------- /config/samples/gitops/fluxcd-application-kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: gitops.kubesphere.io/v1alpha1 2 | kind: Application 3 | metadata: 4 | name: chengleqi-test-kus 5 | namespace: my-devops-projecthmhx2 6 | spec: 7 | kind: fluxcd 8 | fluxApp: 9 | spec: 10 | source: 11 | sourceRef: 12 | kind: GitRepository 13 | name: fluxcd-gitee-repo 14 | namespace: my-devops-projecthmhx2 15 | config: 16 | kustomization: 17 | - destination: 18 | # host cluster 19 | kubeConfig: 20 | targetNamespace: default 21 | interval: 8m0s 22 | prune: true 23 | path: "nginx" 24 | - destination: 25 | # member cluster 26 | kubeConfig: 27 | secretRef: 28 | name: node-1 29 | key: value 30 | targetNamespace: default 31 | interval: 8m0s 32 | prune: true 33 | path: "nginx" -------------------------------------------------------------------------------- /config/samples/gitops/image-updater.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: gitops.kubesphere.io/v1alpha1 2 | kind: ImageUpdater 3 | metadata: 4 | name: updater 5 | namespace: testddmtg 6 | spec: 7 | # default value of kind is argocd 8 | # kind: argocd 9 | images: 10 | - ghcr.io/linuxsuren-bot/open-podcasts-ui 11 | - nginx 12 | - alpine 13 | argo: 14 | app: 15 | name: app 16 | -------------------------------------------------------------------------------- /config/samples/gitrepository.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: GitRepository 3 | metadata: 4 | name: gitrepository 5 | namespace: testxb4m8 6 | spec: 7 | provider: github 8 | owner: linuxsuren 9 | repo: test 10 | -------------------------------------------------------------------------------- /config/samples/jenkins-agent-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: jenkins-agent-config 5 | namespace: kubesphere-devops-system 6 | data: 7 | agent.pod_resource_limit: default # or high or custom 8 | -------------------------------------------------------------------------------- /config/samples/kubesphere.yaml: -------------------------------------------------------------------------------- 1 | authentication: 2 | authenticateRateLimiterDuration: 10m0s 3 | authenticateRateLimiterMaxTries: "10" 4 | jwtSecret: Z1TBo4jUSB5Rs6eyLqHSJ77GXtG8NhSP 5 | loginHistoryRetentionPeriod: 168h 6 | maximumClockSkew: 10s 7 | devops: 8 | host: http://172.18.0.2:30180/ # Need to change 9 | maxConnections: "100" 10 | password: 01UccBiGssWh4YNvAYnRrR # Need to change 11 | username: admin 12 | -------------------------------------------------------------------------------- /config/samples/secret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | stringData: 3 | username: linuxsuren 4 | password: linuxsuren 5 | kind: Secret 6 | metadata: 7 | name: github 8 | type: credential.devops.kubesphere.io/basic-auth 9 | -------------------------------------------------------------------------------- /config/samples/webhook.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha1 2 | kind: Webhook 3 | metadata: 4 | name: webhook 5 | spec: 6 | server: https://github.com 7 | skipVerify: true 8 | events: 9 | - push 10 | - release 11 | -------------------------------------------------------------------------------- /config/webhook/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - manifests.yaml 3 | - service.yaml 4 | 5 | configurations: 6 | - kustomizeconfig.yaml 7 | -------------------------------------------------------------------------------- /config/webhook/kustomizeconfig.yaml: -------------------------------------------------------------------------------- 1 | # the following config is for teaching kustomize where to look at when substituting vars. 2 | # It requires kustomize v2.1.0 or newer to work properly. 3 | nameReference: 4 | - kind: Service 5 | version: v1 6 | fieldSpecs: 7 | - kind: MutatingWebhookConfiguration 8 | group: admissionregistration.k8s.io 9 | path: webhooks/clientConfig/service/name 10 | - kind: ValidatingWebhookConfiguration 11 | group: admissionregistration.k8s.io 12 | path: webhooks/clientConfig/service/name 13 | 14 | namespace: 15 | - kind: MutatingWebhookConfiguration 16 | group: admissionregistration.k8s.io 17 | path: webhooks/clientConfig/service/namespace 18 | create: true 19 | - kind: ValidatingWebhookConfiguration 20 | group: admissionregistration.k8s.io 21 | path: webhooks/clientConfig/service/namespace 22 | create: true 23 | 24 | varReference: 25 | - path: metadata/annotations 26 | -------------------------------------------------------------------------------- /config/webhook/service.yaml: -------------------------------------------------------------------------------- 1 | 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: webhook-service 6 | namespace: system 7 | spec: 8 | ports: 9 | - port: 443 10 | targetPort: 9443 11 | selector: 12 | control-plane: controller-manager 13 | -------------------------------------------------------------------------------- /controllers/README.md: -------------------------------------------------------------------------------- 1 | Thanks for your contribution to the controller area. 2 | 3 | If you create a new controller, please don't forget to add it to `cmd/controller/app/controllers.go`. 4 | -------------------------------------------------------------------------------- /controllers/argocd/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package argocd 18 | 19 | const controllerGroupName = "argocd" 20 | -------------------------------------------------------------------------------- /controllers/argocd/data/argo-status-without-summary.json: -------------------------------------------------------------------------------- 1 | { 2 | "health": { 3 | "status": "Healthy" 4 | }, 5 | "reconciledAt": "2022-06-30T06:48:05Z", 6 | "sourceType": "Kustomize" 7 | } 8 | -------------------------------------------------------------------------------- /controllers/argocd/data/argo-status.json: -------------------------------------------------------------------------------- 1 | { 2 | "health": { 3 | "status": "Healthy" 4 | }, 5 | "reconciledAt": "2022-06-30T06:48:05Z", 6 | "sourceType": "Kustomize", 7 | "summary": { 8 | "images": [ 9 | "ghcr.io/linuxsuren-bot/open-podcasts-ui:v1.0.2", 10 | "ghcr.io/linuxsuren-bot/open-podcasts:v1.0.0", 11 | "ghcr.io/opensource-f2f/kube-rbac-proxy:v0.8.0", 12 | "ghcr.io/opensource-f2f/open-podcasts-apiserver:dev" 13 | ] 14 | }, 15 | "sync": { 16 | "comparedTo": { 17 | "destination": { 18 | "name": "in-cluster", 19 | "namespace": "argocd" 20 | }, 21 | "source": { 22 | "kustomize": { 23 | "images": [ 24 | "ghcr.io/linuxsuren-bot/open-podcasts-ui:v1.0.2" 25 | ] 26 | }, 27 | "path": "config/default", 28 | "repoURL": "https://github.com/linuxsuren-bot/open-podcasts/", 29 | "targetRevision": "HEAD" 30 | } 31 | }, 32 | "revision": "1d4fcf1f56f5dbe2ae65abb001ffc304f1d58070", 33 | "status": "Synced" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /controllers/core/fake_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package core 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestNoErrors(t *testing.T) { 25 | assert.True(t, NoErrors(t, nil)) 26 | } 27 | -------------------------------------------------------------------------------- /controllers/gitrepository/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package gitrepository 15 | 16 | const ( 17 | groupName = "gitrepository" 18 | ) 19 | -------------------------------------------------------------------------------- /controllers/gitrepository/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package gitrepository 15 | 16 | import ( 17 | "github.com/kubesphere/ks-devops/controllers/core" 18 | "sigs.k8s.io/controller-runtime/pkg/client" 19 | ) 20 | 21 | func GetReconcilers(k8s client.Client) core.GroupedReconcilers { 22 | return []core.GroupedReconciler{ 23 | &AmendReconciler{ 24 | Client: k8s, 25 | }, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /controllers/gitrepository/register_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package gitrepository 15 | 16 | import ( 17 | "github.com/stretchr/testify/assert" 18 | "testing" 19 | ) 20 | 21 | func TestGetReconcilers(t *testing.T) { 22 | reconcilers := GetReconcilers(nil) 23 | for i := range reconcilers { 24 | item := reconcilers[i] 25 | assert.Equal(t, groupName, item.GetGroupName()) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /controllers/gitrepository/testdata/hook.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "url": "https://api.github.com/repos/linuxsuren/test/hooks/1", 4 | "test_url": "https://api.github.com/repos/linuxsuren/test/hooks/1/test", 5 | "ping_url": "https://api.github.com/repos/linuxsuren/test/hooks/1/pings", 6 | "name": "web", 7 | "events": [ 8 | "push", 9 | "pull_request" 10 | ], 11 | "active": true, 12 | "config": { 13 | "url": "http://example.com/webhook", 14 | "content_type": "json", 15 | "insecure_ssl": "1" 16 | }, 17 | "updated_at": "2011-09-06T20:39:23Z", 18 | "created_at": "2011-09-06T17:26:27Z" 19 | } 20 | -------------------------------------------------------------------------------- /controllers/gitrepository/testdata/hooks.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "url": "https://api.github.com/repos/linuxsuren/test/hooks/1", 5 | "test_url": "https://api.github.com/repos/linuxsuren/test/hooks/1/test", 6 | "ping_url": "https://api.github.com/repos/linuxsuren/test/hooks/1/pings", 7 | "name": "web", 8 | "events": [ 9 | "push", 10 | "pull_request" 11 | ], 12 | "active": true, 13 | "config": { 14 | "url": "http://example.com/webhook", 15 | "content_type": "json" 16 | }, 17 | "updated_at": "2011-09-06T20:39:23Z", 18 | "created_at": "2011-09-06T17:26:27Z" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /controllers/gitrepository/testdata/status.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_at": "2012-07-20T01:19:13Z", 3 | "updated_at": "2012-07-20T01:19:13Z", 4 | "state": "success", 5 | "target_url": "https://ci.example.com/1000/output", 6 | "description": "Build has completed successfully", 7 | "id": 1, 8 | "url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", 9 | "context": "continuous-integration/drone", 10 | "creator": { 11 | "login": "octocat", 12 | "id": 1, 13 | "avatar_url": "https://github.com/images/error/octocat_happy.gif", 14 | "gravatar_id": "", 15 | "url": "https://api.github.com/users/octocat", 16 | "html_url": "https://github.com/octocat", 17 | "followers_url": "https://api.github.com/users/octocat/followers", 18 | "following_url": "https://api.github.com/users/octocat/following{/other_user}", 19 | "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", 20 | "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", 21 | "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", 22 | "organizations_url": "https://api.github.com/users/octocat/orgs", 23 | "repos_url": "https://api.github.com/users/octocat/repos", 24 | "events_url": "https://api.github.com/users/octocat/events{/privacy}", 25 | "received_events_url": "https://api.github.com/users/octocat/received_events", 26 | "type": "User", 27 | "site_admin": false 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /controllers/jenkins/README.md: -------------------------------------------------------------------------------- 1 | All Jenkins-related controllers live here. 2 | -------------------------------------------------------------------------------- /controllers/jenkins/config/agent_config_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package config 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestGetDefaultConfig(t *testing.T) { 25 | config := getDefaultConfig() 26 | assert.NotNil(t, config) 27 | assert.NotNil(t, config["pod.concurrent"]) 28 | } 29 | 30 | func TestGetHighConfig(t *testing.T) { 31 | config := getHighConfig() 32 | assert.NotNil(t, config) 33 | assert.NotNil(t, config["pod.concurrent"]) 34 | } 35 | -------------------------------------------------------------------------------- /controllers/jenkins/config/constant.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package config 18 | 19 | const ( 20 | // ANNOJenkinsConfigFormula represents the formula name 21 | ANNOJenkinsConfigFormula = "devops.kubesphere.io/jenkins-config-formula" 22 | // ANNOJenkinsConfigCustomized indicates if the formula was customized 23 | ANNOJenkinsConfigCustomized = "devops.kubesphere.io/jenkins-config-customized" 24 | ) 25 | 26 | const ( 27 | // FormulaCustom is a formula name - custom 28 | FormulaCustom = "custom" 29 | // FormulaHigh is a formula name - high 30 | FormulaHigh = "high" 31 | // FormulaLow is a formula name - low 32 | FormulaLow = "low" 33 | ) 34 | 35 | const reconcilerGroupName = "jenkins" 36 | 37 | const podTemplateFinalizer = "podtemplate.devops.kubesphere.io/finalizer" 38 | -------------------------------------------------------------------------------- /controllers/jenkins/pipeline/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pipeline 18 | 19 | const ( 20 | // ControllerGroupName is the group name of a set of controllers 21 | ControllerGroupName = "jenkins" 22 | ) 23 | -------------------------------------------------------------------------------- /controllers/jenkins/pipeline/interface_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pipeline 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/controllers/core" 21 | "github.com/stretchr/testify/assert" 22 | "testing" 23 | ) 24 | 25 | func TestInterfaceImplement(t *testing.T) { 26 | type interInstance struct { 27 | NamedReconciler core.NamedReconciler 28 | GroupReconciler core.GroupReconciler 29 | } 30 | 31 | tests := []struct { 32 | name string 33 | instance interInstance 34 | }{{ 35 | name: "JenkinsfileReconciler", 36 | instance: interInstance{ 37 | NamedReconciler: &JenkinsfileReconciler{}, 38 | GroupReconciler: &JenkinsfileReconciler{}, 39 | }, 40 | }} 41 | for i := range tests { 42 | tt := tests[i] 43 | t.Run(tt.name, func(t *testing.T) { 44 | assert.NotNil(t, tt.instance.NamedReconciler) 45 | assert.NotEmpty(t, tt.instance.NamedReconciler.GetName()) 46 | assert.NotNil(t, tt.instance.GroupReconciler) 47 | assert.NotEmpty(t, tt.instance.GroupReconciler.GetGroupName()) 48 | }) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /controllers/jenkins/pipeline/setup_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pipeline_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | "github.com/onsi/ginkgo/reporters" 24 | . "github.com/onsi/gomega" 25 | ) 26 | 27 | func TestPipeline(t *testing.T) { 28 | RegisterFailHandler(Fail) 29 | junitReporter := reporters.NewJUnitReporter("pipelinerun-test.xml") 30 | RunSpecsWithDefaultAndCustomReporters(t, "test PipelineRun controller", []Reporter{junitReporter}) 31 | } 32 | -------------------------------------------------------------------------------- /controllers/jenkins/pipelinerun/setup_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pipelinerun 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/onsi/ginkgo/reporters" 23 | 24 | . "github.com/onsi/ginkgo" 25 | . "github.com/onsi/gomega" 26 | ) 27 | 28 | func TestPipelineRun(t *testing.T) { 29 | RegisterFailHandler(Fail) 30 | junitReporter := reporters.NewJUnitReporter("pipelinerun-test.xml") 31 | RunSpecsWithDefaultAndCustomReporters(t, "test PipelineRun controller", []Reporter{junitReporter}) 32 | } 33 | -------------------------------------------------------------------------------- /controllers/predicate/label.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package predicate 15 | 16 | import ( 17 | "sigs.k8s.io/controller-runtime/pkg/client" 18 | 19 | k8spredicate "sigs.k8s.io/controller-runtime/pkg/predicate" 20 | ) 21 | 22 | // Filter is a reconciler filter function 23 | type Filter func(object client.Object) (ok bool) 24 | 25 | // NewFilterHasLabel creats a filter that contains the specific label 26 | func NewFilterHasLabel(label string) Filter { 27 | return func(object client.Object) (ok bool) { 28 | _, ok = object.GetLabels()[label] 29 | return 30 | } 31 | } 32 | 33 | // NewPredicateFuncs creates a filter function 34 | func NewPredicateFuncs(filter Filter) k8spredicate.Funcs { 35 | return k8spredicate.NewPredicateFuncs(filter) 36 | } 37 | -------------------------------------------------------------------------------- /controllers/predicate/label_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package predicate 15 | 16 | import ( 17 | "testing" 18 | 19 | "github.com/stretchr/testify/assert" 20 | v1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | func TestNewFilterHasLabel(t *testing.T) { 25 | filter := NewFilterHasLabel("fake") 26 | assert.NotNil(t, filter) 27 | 28 | ok := filter(&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{ 29 | Labels: map[string]string{ 30 | "fake": "good", 31 | }, 32 | }}) 33 | assert.True(t, ok) 34 | ok = filter(&v1.ConfigMap{}) 35 | assert.False(t, ok) 36 | } 37 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | This is the right place if you want to know more details about `ks-devops`. 2 | 3 | * [webhook](webhook.md) 4 | * [cli](cli.md) 5 | * [installation](installation.md) 6 | * [projects](projects.md) 7 | * [e2e](e2e.md) 8 | * [Swagger Support](swagger.md) 9 | * [Addon management](addon.md) 10 | * [Pipeline Template Design](pipeline-template.md) 11 | * [API Permission](permission.md) 12 | 13 | ## Create a new CRD 14 | 15 | ```shell 16 | kubebuilder create api --group devops.kubesphere.io --version v1alpha3 --kind Todo 17 | ``` -------------------------------------------------------------------------------- /docs/cli.md: -------------------------------------------------------------------------------- 1 | You can manipulate KubeSphere DevOps via [CLI](./installation.md#kubesphere-cli). 2 | 3 | ## Create Pipeline 4 | 5 | ```shell 6 | ks pip create --ws simple --template java --project default --skip-check -b good 7 | ``` 8 | 9 | ## Run Pipeline 10 | 11 | ```shell 12 | ks pip run 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/faq.md: -------------------------------------------------------------------------------- 1 | Please feel free to checkout the following frequently asked questions, hopefully this document could help you. 2 | 3 | ## Pipeline cannot be triggered 4 | Effected versions: `v3.2.1` 5 | 6 | | Possible reason | Potential solution | 7 | |---|---| 8 | | The account was not synced due to the LDAP issues | Reset your account's password | 9 | | The token of Jenkins is incorrect | Restart the deployment `devops-controller` and `devops-apiserver` if you didn't change the token manually | 10 | -------------------------------------------------------------------------------- /docs/gc.md: -------------------------------------------------------------------------------- 1 | We prefer to use the built-in PipelineRun GC instead of Jenkins itself. Please feel free to configure [the `CronJob`](https://github.com/kubesphere-sigs/ks-devops-helm-chart/blob/464a1a9854561ef5666433b8d975b89cced07494/charts/ks-devops/templates/cronjob-gc.yaml) according to your requirement. 2 | 3 | Normally, you could find it from namespace `kubesphere-devops-system`. You could specifiy the following options: 4 | 5 | * `maxAge` is the maximum time to live for PipelineRuns 6 | * `maxCount` is the max number of the PipelineRuns 7 | 8 | See also the Helm chart [values setting](https://github.com/kubesphere-sigs/ks-devops-helm-chart/blob/464a1a9854561ef5666433b8d975b89cced07494/charts/ks-devops/values.yaml#L17). 9 | -------------------------------------------------------------------------------- /docs/pod-template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubesphere/ks-devops/a11e1c6b7a46b2eb031143b0468691f2e8eea9ea/docs/pod-template.md -------------------------------------------------------------------------------- /docs/swagger.md: -------------------------------------------------------------------------------- 1 | Before starting the APIServer, execute the following one command to clone Swagger UI: 2 | 3 | ```bash 4 | make swagger-ui 5 | ``` 6 | 7 | Then, start the APIServer and explore all API documentation via the Swagger UI: . 8 | 9 | 10 | * The URL pattern is like `http://ip:port/apidocs/?url=http://ip:port/apidocs.json` 11 | 12 | --- 13 | In kubesphere enabled DevOps, you could update service type of devops-apiserver to NodePort, and then via the Swagger UI: `http://ip:NodePort/apidocs/?url=http://ip:NodePort/apidocs.json`. 14 | -------------------------------------------------------------------------------- /docs/testing.md: -------------------------------------------------------------------------------- 1 | This document helps you to do some tests about the KubeSphere DevOps. 2 | 3 | ## Pressure test 4 | 5 | Before get stated, we need to install some tools. In this case, I use [hd](https://github.com/LinuxSuRen/http-downloader/) to install them. 6 | 7 | ```shell 8 | hd fetch 9 | hd i kd 10 | hd i names 11 | ``` 12 | 13 | The following command be able to create a lot of Pipelines: 14 | ```shell 15 | for a in {1..1000} 16 | do 17 | ks pip create --ws simple --project test --template simple --name $(names) 18 | done 19 | ``` 20 | then, run all the Pipelines 21 | 22 | ```shell 23 | 24 | for a in $(ks get pipeline -n testkjhx9 -o custom-columns=Name:metadata.name) 25 | do 26 | ks pip run -n testkjhx9 -p $a -b 27 | done 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/webhook-management.md: -------------------------------------------------------------------------------- 1 | For many components, they can receive webhook events from other system. For instance, Argo CD can receive webhook events 2 | from a git repository. 3 | 4 | The `GitRepository Webhook Controller` be able to manage the webhooks. You can install it without the whole ks-devops. 5 | 6 | ## Install 7 | 8 | ```shell 9 | kustomize build ../config/samples/gitRepository_webhooks | kubectl apply -f - 10 | ``` 11 | 12 | ## Get started 13 | 14 | First, please prepare a secret of your git repository: 15 | 16 | ```shell 17 | kubectl create secret generic github --from-literal=token=your-secret 18 | ``` 19 | 20 | then, please create the `Webhook` and `GitRepository`: 21 | 22 | ```shell 23 | kubectl apply -f ../config/samples/webhook.yaml 24 | kubectl apply -f ../config/samples/gitrepository.yaml 25 | ``` 26 | 27 | now, you can check your git repository. To see if it works well. 28 | 29 | ## More 30 | 31 | Currently, we support GitHub, Gitlab. But thanks to [drone/go-scm](https://github.com/drone/go-scm), 32 | it's possible to support more git providers. 33 | -------------------------------------------------------------------------------- /hack/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /hack/generate_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | GV="$1" 6 | 7 | ./hack/generate_group.sh all github.com/kubesphere/ks-devops/pkg/client github.com/kubesphere/ks-devops/api "${GV}" --output-base=./ -h "$PWD/hack/boilerplate.go.txt" 8 | -------------------------------------------------------------------------------- /pkg/api/devops/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package devops 17 | 18 | const ( 19 | // JenkinsAgentLabelsKey is the key of Jenkins agent labels. For example, you could find it in ConfigMap 20 | // kubesphere-devops-system/jenkins-agent-config 21 | JenkinsAgentLabelsKey = "agent.labels" 22 | ) 23 | -------------------------------------------------------------------------------- /pkg/api/devops/register.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package devops 17 | 18 | const ( 19 | // GroupName is the Kubernetes resource group name for Devops types. 20 | GroupName = "devops.kubesphere.io" 21 | 22 | // RenderResultAnnoKey is used as the annotation identifier for render result of Template. 23 | RenderResultAnnoKey = "/render-result" 24 | ) 25 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the devops v1alpha1 API group 18 | // +k8s:openapi-gen=true 19 | // +k8s:deepcopy-gen=package,register 20 | // +k8s:conversion-gen=github.com/kubesphere/ks-devops/api 21 | // +k8s:defaulter-gen=TypeMeta 22 | // +groupName=devops.kubesphere.io 23 | package v1alpha1 24 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha1/groupversion_info_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "testing" 23 | ) 24 | 25 | func TestResource(t *testing.T) { 26 | type args struct { 27 | resource string 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | want schema.GroupResource 33 | }{{ 34 | name: "normal case", 35 | args: args{ 36 | resource: "pipeline", 37 | }, 38 | want: Resource("pipeline"), 39 | }} 40 | for _, tt := range tests { 41 | t.Run(tt.name, func(t *testing.T) { 42 | assert.Equalf(t, tt.want, Resource(tt.args.resource), "Resource(%v)", tt.args.resource) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/addon_strategy_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha3 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestAddonInstallStrategy_IsValid(t *testing.T) { 25 | tests := []struct { 26 | name string 27 | a AddonInstallStrategy 28 | want bool 29 | }{{ 30 | name: "normal case - simple", 31 | a: AddonInstallStrategySimple, 32 | want: true, 33 | }, { 34 | name: "normal case - helm", 35 | a: AddonInstallStrategyHelm, 36 | want: true, 37 | }, { 38 | name: "normal case - operator", 39 | a: AddonInstallStrategyOperator, 40 | want: true, 41 | }, { 42 | name: "normal case - simple-operator", 43 | a: AddonInstallStrategySimpleOperator, 44 | want: true, 45 | }, { 46 | name: "a fake strategy", 47 | a: AddonInstallStrategy("fake"), 48 | want: false, 49 | }} 50 | for _, tt := range tests { 51 | t.Run(tt.name, func(t *testing.T) { 52 | assert.Equalf(t, tt.want, tt.a.IsValid(), "IsValid()") 53 | }) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/credential_types_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha3 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | func TestGetSupportedCredentialTypes(t *testing.T) { 26 | // test basic return 27 | types := GetSupportedCredentialTypes() 28 | assert.Equal(t, supportedCredentialTypes, types) 29 | 30 | // test unmodifiable 31 | // try to modify the types 32 | types = append(types, SecretTypeBasicAuth) 33 | // check if the return value is modified 34 | assert.NotEqual(t, types, GetSupportedCredentialTypes()) 35 | assert.Equal(t, supportedCredentialTypes, GetSupportedCredentialTypes()) 36 | } 37 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/groupversion_info_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha3 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "testing" 23 | ) 24 | 25 | func TestResource(t *testing.T) { 26 | type args struct { 27 | resource string 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | want schema.GroupResource 33 | }{{ 34 | name: "normal case", 35 | args: args{ 36 | resource: "pipeline", 37 | }, 38 | want: Resource("pipeline"), 39 | }} 40 | for _, tt := range tests { 41 | t.Run(tt.name, func(t *testing.T) { 42 | assert.Equalf(t, tt.want, Resource(tt.args.resource), "Resource(%v)", tt.args.resource) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/last_changes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package v1alpha3 17 | 18 | import "encoding/json" 19 | 20 | // +kubebuilder:object:generate=false 21 | 22 | // LastChanges represents a set of last SCM changes 23 | type LastChanges map[string]string 24 | 25 | // GetLastChanges returns the last changes 26 | func GetLastChanges(jsonText string) (lastChange LastChanges, err error) { 27 | lastChange = map[string]string{} 28 | err = json.Unmarshal([]byte(jsonText), &lastChange) 29 | return 30 | } 31 | 32 | // Update updates hash by ref 33 | func (l LastChanges) Update(ref, hash string) LastChanges { 34 | l[ref] = hash 35 | return l 36 | } 37 | 38 | // LastHash return last hash value 39 | func (l LastChanges) LastHash(ref string) (hash string) { 40 | return l[ref] 41 | } 42 | 43 | // String returns the string JSON format 44 | func (l LastChanges) String() string { 45 | data, _ := json.Marshal(l) 46 | return string(data) 47 | } 48 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/template_interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package v1alpha3 17 | 18 | import ( 19 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | // +kubebuilder:object:generate=false 24 | 25 | // TemplateObject is implemented by Template and ClusterTemplate. 26 | type TemplateObject interface { 27 | v1.Object 28 | runtime.Object 29 | // TemplateSpec returns TemplateSpec. 30 | TemplateSpec() TemplateSpec 31 | } 32 | -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/credential-kubeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": { 3 | "isLiteral": false, 4 | "value": "${[kubeconfigContent(credentialsId: 'config', variable: 'VARIABLE')]}" 5 | }, 6 | "children": [echo 1], 7 | "name": "withCredentials" 8 | } -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/credential-ssh.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": { 3 | "isLiteral": false, 4 | "value": "${[sshUserPrivateKey(credentialsId: 'config', keyFileVariable : 'KEYFILEVARIABLE' ,passphraseVariable : 'PASSPHRASEVARIABLE' ,usernameVariable : 'SSHUSERPRIVATEKEY')]}" 5 | }, 6 | "children": [echo 1], 7 | "name": "withCredentials" 8 | } -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/credential-string.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": { 3 | "isLiteral": false, 4 | "value": "${[string(credentialsId: 'config', variable: 'VARIABLE')]}" 5 | }, 6 | "children": [echo 1], 7 | "name": "withCredentials" 8 | } -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/docker-login.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": { 3 | "isLiteral": true, 4 | "value": "base" 5 | }, 6 | "children": [ 7 | { 8 | "arguments": { 9 | "isLiteral": false, 10 | "value": "${[usernamePassword(credentialsId: 'docker', passwordVariable: 'PASSWORDVARIABLE' ,usernameVariable : 'USERNAMEVARIABLE')]}" 11 | }, 12 | "children": [ 13 | { 14 | "arguments": [ 15 | { 16 | "key": "script", 17 | "value": { 18 | "isLiteral": true, 19 | "value": "docker login -u $USERNAMEVARIABLE -p $PASSWORDVARIABLE\ndocker build dir -t image:tag -f Dockerfile" 20 | } 21 | } 22 | ], 23 | "name": "sh" 24 | } 25 | ], 26 | "name": "withCredentials" 27 | } 28 | ], 29 | "name": "container" 30 | } -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/dsl-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": [ 3 | { 4 | "key": "message", 5 | "value": { 6 | "isLiteral": true, 7 | "value": "1" 8 | } 9 | } 10 | ], 11 | "name": "echo" 12 | } -------------------------------------------------------------------------------- /pkg/api/devops/v1alpha3/testdata/sh-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "arguments": [ 3 | { 4 | "key": "script", 5 | "value": { 6 | "isLiteral": true, 7 | "value": "echo 1" 8 | } 9 | } 10 | ], 11 | "name": "sh" 12 | } -------------------------------------------------------------------------------- /pkg/api/gitops/v1alpha1/groupversion_info_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "testing" 23 | ) 24 | 25 | func TestResource(t *testing.T) { 26 | type args struct { 27 | resource string 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | want schema.GroupResource 33 | }{{ 34 | name: "normal case", 35 | args: args{ 36 | resource: "application", 37 | }, 38 | want: Resource("application"), 39 | }} 40 | for _, tt := range tests { 41 | t.Run(tt.name, func(t *testing.T) { 42 | assert.Equalf(t, tt.want, Resource(tt.args.resource), "Resource(%v)", tt.args.resource) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/api/gitops/v1alpha1/image-updater_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestWriteMethod_GetValue(t *testing.T) { 25 | tests := []struct { 26 | name string 27 | w WriteMethod 28 | want string 29 | }{{ 30 | name: "built-in", 31 | w: WriteMethodBuiltIn, 32 | want: "argocd", 33 | }, { 34 | name: "git", 35 | w: WriteMethodGit, 36 | want: "git", 37 | }, { 38 | name: "invalid", 39 | w: WriteMethod("invalid"), 40 | want: "", 41 | }} 42 | for _, tt := range tests { 43 | t.Run(tt.name, func(t *testing.T) { 44 | assert.Equalf(t, tt.want, tt.w.GetValue(), "GetValue()") 45 | }) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pkg/apis/addtoscheme_devops_v1alpha3.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package apis 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha1" 21 | "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha3" 22 | iamv1beta1 "kubesphere.io/api/iam/v1beta1" 23 | ) 24 | 25 | func init() { 26 | // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back 27 | addToSchemes = append(addToSchemes, v1alpha3.SchemeBuilder.AddToScheme, v1alpha1.SchemeBuilder.AddToScheme) 28 | 29 | addToSchemes = append(addToSchemes, iamv1beta1.AddToScheme) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/apis/apis_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package apis 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/pkg/client/clientset/versioned/scheme" 21 | "testing" 22 | ) 23 | 24 | func TestAddToScheme(t *testing.T) { 25 | AddToScheme(scheme.Scheme) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apiserver/authentication/authenticators/bearertoken/bearertoken.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package bearertoken 18 | 19 | import ( 20 | "context" 21 | "time" 22 | 23 | "k8s.io/apiserver/pkg/authentication/user" 24 | 25 | jwt "github.com/kubesphere/ks-devops/pkg/jwt/token" 26 | "k8s.io/apiserver/pkg/authentication/authenticator" 27 | ) 28 | 29 | // tokenAuthenticator implements an simple auth which only check the format of target JWT token 30 | type tokenAuthenticator struct{} 31 | 32 | func New() authenticator.Token { 33 | return &tokenAuthenticator{} 34 | } 35 | 36 | func (a *tokenAuthenticator) AuthenticateToken(ctx context.Context, token string) (response *authenticator.Response, ok bool, err error) { 37 | issuer := jwt.NewTokenIssuer("", time.Second) 38 | 39 | var authenticated user.Info 40 | if authenticated, _, err = issuer.VerifyWithoutClaimsValidation(token); err == nil { 41 | response = &authenticator.Response{ 42 | User: &user.DefaultInfo{ 43 | Name: authenticated.GetName(), 44 | }} 45 | ok = true 46 | } else { 47 | ok = false 48 | } 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /pkg/apiserver/authentication/request/anonymous/anonymous.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package anonymous 18 | 19 | import ( 20 | "k8s.io/apiserver/pkg/authentication/authenticator" 21 | "k8s.io/apiserver/pkg/authentication/user" 22 | "net/http" 23 | "strings" 24 | ) 25 | 26 | // Authenticator implements an anonymous auth 27 | type Authenticator struct{} 28 | 29 | func NewAuthenticator() authenticator.Request { 30 | return &Authenticator{} 31 | } 32 | 33 | func (a *Authenticator) AuthenticateRequest(req *http.Request) (*authenticator.Response, bool, error) { 34 | if auth := strings.TrimSpace(req.Header.Get("Authorization")); auth == "" { 35 | return &authenticator.Response{ 36 | User: &user.DefaultInfo{ 37 | Name: "anonymous", 38 | Groups: []string{user.AllAuthenticated}, 39 | }, 40 | }, true, nil 41 | } 42 | return nil, false, nil 43 | } 44 | -------------------------------------------------------------------------------- /pkg/apiserver/runtime/runtime_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "testing" 23 | ) 24 | 25 | func TestNewWebServiceWithoutGroup(t *testing.T) { 26 | ws := NewWebServiceWithoutGroup(schema.GroupVersion{ 27 | Version: "v2", 28 | }) 29 | 30 | assert.NotNil(t, ws) 31 | assert.Equal(t, "/v2", ws.RootPath()) 32 | } 33 | 34 | func TestNewWebService(t *testing.T) { 35 | ws := NewWebService(schema.GroupVersion{ 36 | Group: "devops", 37 | Version: "v2", 38 | }) 39 | 40 | assert.NotNil(t, ws) 41 | assert.Equal(t, ApiRootPath+"/devops/v2", ws.RootPath()) 42 | } 43 | -------------------------------------------------------------------------------- /pkg/client/cache/cache.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package cache 18 | 19 | import "time" 20 | 21 | // NeverExpire represents a never expired time 22 | var NeverExpire = time.Duration(0) 23 | 24 | type Interface interface { 25 | // Keys retrieves all keys match the given pattern 26 | Keys(pattern string) ([]string, error) 27 | 28 | // Get retrieves the value of the given key, return error if key doesn't exist 29 | Get(key string) (string, error) 30 | 31 | // Set sets the value and living duration of the given key, zero duration means never expire 32 | Set(key string, value string, duration time.Duration) error 33 | 34 | // Del deletes the given key, no error returned if the key doesn't exists 35 | Del(keys ...string) error 36 | 37 | // Exists checks the existence of a give key 38 | Exists(keys ...string) (bool, error) 39 | 40 | // Expires updates object's expiration time, return err if key doesn't exist 41 | Expire(key string, duration time.Duration) error 42 | } 43 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | // Code generated by client-gen. DO NOT EDIT. 17 | 18 | // This package has the automatically generated clientset. 19 | package versioned 20 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated fake clientset. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/scheme/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package contains the scheme of the automatically generated clientset. 20 | package scheme 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1alpha1 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha1/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha1/generated_expansion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | type S2iBinaryExpansion interface{} 22 | 23 | type S2iBuilderExpansion interface{} 24 | 25 | type S2iBuilderTemplateExpansion interface{} 26 | 27 | type S2iRunExpansion interface{} 28 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha3/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1alpha3 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha3/fake/fake_devops_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | v1alpha3 "github.com/kubesphere/ks-devops/pkg/client/clientset/versioned/typed/devops/v1alpha3" 23 | rest "k8s.io/client-go/rest" 24 | testing "k8s.io/client-go/testing" 25 | ) 26 | 27 | type FakeDevopsV1alpha3 struct { 28 | *testing.Fake 29 | } 30 | 31 | func (c *FakeDevopsV1alpha3) DevOpsProjects() v1alpha3.DevOpsProjectInterface { 32 | return &FakeDevOpsProjects{c} 33 | } 34 | 35 | func (c *FakeDevopsV1alpha3) Pipelines(namespace string) v1alpha3.PipelineInterface { 36 | return &FakePipelines{c, namespace} 37 | } 38 | 39 | // RESTClient returns a RESTClient that is used to communicate 40 | // with API server by this client implementation. 41 | func (c *FakeDevopsV1alpha3) RESTClient() rest.Interface { 42 | var ret *rest.RESTClient 43 | return ret 44 | } 45 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/devops/v1alpha3/generated_expansion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha3 20 | 21 | type DevOpsProjectExpansion interface{} 22 | 23 | type PipelineExpansion interface{} 24 | -------------------------------------------------------------------------------- /pkg/client/devops/OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - linuxsuren 3 | 4 | reviewers: 5 | - runzexia 6 | - soulseen 7 | - shaowenchen 8 | - linuxsuren 9 | -------------------------------------------------------------------------------- /pkg/client/devops/configuration.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | // ConfigurationOperator provides APIs for operating devops configuration, like reloading. 20 | type ConfigurationOperator interface { 21 | // ReloadConfiguration reload devops configuration 22 | ReloadConfiguration() error 23 | 24 | // ApplyNewSource applies a new config file 25 | ApplyNewSource(string) error 26 | } 27 | -------------------------------------------------------------------------------- /pkg/client/devops/jclient/build.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package jclient 18 | 19 | import "github.com/kubesphere/ks-devops/pkg/client/devops" 20 | 21 | // GetProjectPipelineBuildByType returns a build 22 | func (j *JenkinsClient) GetProjectPipelineBuildByType(projectID, pipelineID string, status string) (*devops.Build, error) { 23 | return j.jenkins.GetProjectPipelineBuildByType(projectID, pipelineID, status) 24 | } 25 | 26 | // GetMultiBranchPipelineBuildByType returns a build 27 | func (j *JenkinsClient) GetMultiBranchPipelineBuildByType(projectID, pipelineID, branch string, status string) (*devops.Build, error) { 28 | return j.jenkins.GetMultiBranchPipelineBuildByType(projectID, pipelineID, branch, status) 29 | } 30 | -------------------------------------------------------------------------------- /pkg/client/devops/jclient/configuration.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package jclient 18 | 19 | import "github.com/jenkins-zh/jenkins-client/pkg/casc" 20 | 21 | // ReloadConfiguration reloads the Jenkins Configuration as Code YAML file 22 | func (j *JenkinsClient) ReloadConfiguration() (err error) { 23 | client := casc.Manager{} 24 | if j != nil { 25 | client.JenkinsCore = j.Core 26 | } 27 | err = client.Reload() 28 | return 29 | } 30 | 31 | // ApplyNewSource apply a new source 32 | func (j *JenkinsClient) ApplyNewSource(s string) (err error) { 33 | client := casc.Manager{} 34 | if j != nil { 35 | client.JenkinsCore = j.Core 36 | } 37 | if err = client.CheckNewSource(s); err == nil { 38 | err = client.Replace(s) 39 | } 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /pkg/client/devops/jclient/project.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package jclient 18 | 19 | // CreateDevOpsProject creates a devops project 20 | func (j *JenkinsClient) CreateDevOpsProject(projectID string) (string, error) { 21 | return j.jenkins.CreateDevOpsProject(projectID) 22 | } 23 | 24 | // DeleteDevOpsProject deletes a devops project 25 | func (j *JenkinsClient) DeleteDevOpsProject(projectID string) error { 26 | return j.jenkins.DeleteDevOpsProject(projectID) 27 | } 28 | 29 | // GetDevOpsProject returns the devops project 30 | func (j *JenkinsClient) GetDevOpsProject(projectID string) (string, error) { 31 | return j.jenkins.GetDevOpsProject(projectID) 32 | } 33 | -------------------------------------------------------------------------------- /pkg/client/devops/jenkins/README.md: -------------------------------------------------------------------------------- 1 | # Jenkins API Client for Go 2 | 3 | 4 | ## About 5 | 6 | Jenkins is the most popular Open Source Continuous Integration system. This Library will help you interact with Jenkins in a more developer-friendly way. 7 | 8 | Fork From https://github.com/bndr/gojenkins 9 | 10 | These are some of the features that are currently implemented: 11 | 12 | * Get information on test-results of completed/failed build 13 | * Ability to query Nodes, and manipulate them. Start, Stop, set Offline. 14 | * Ability to query Jobs, and manipulate them. 15 | * Get Plugins, Builds, Artifacts, Fingerprints 16 | * Validate Fingerprints of Artifacts 17 | * Get Current Queue, Cancel Tasks 18 | * etc. For all methods go to GoDoc Reference. 19 | 20 | Add some features: 21 | 22 | * Credentials Management 23 | * Pipeline Model Converter 24 | * RBAC control 25 | -------------------------------------------------------------------------------- /pkg/client/devops/jenkins/devops.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package jenkins 15 | 16 | import ( 17 | "net/http" 18 | ) 19 | 20 | func NewDevopsClient(options *Options) (*Jenkins, error) { 21 | // we have to create http client with no redirection 22 | client := &http.Client{ 23 | CheckRedirect: func(req *http.Request, via []*http.Request) error { 24 | return http.ErrUseLastResponse 25 | }, 26 | } 27 | 28 | password := options.Password 29 | if password == "" { 30 | password = options.ApiToken // use apiToken if without password 31 | } 32 | jenkins := CreateJenkins(client, options.Host, options.MaxConnections, options.Username, password) 33 | 34 | return jenkins, nil 35 | } 36 | -------------------------------------------------------------------------------- /pkg/client/devops/jenkins/project.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package jenkins 18 | 19 | import ( 20 | "github.com/emicklei/go-restful/v3" 21 | "k8s.io/klog/v2" 22 | 23 | "github.com/kubesphere/ks-devops/pkg/client/devops" 24 | ) 25 | 26 | func (j *Jenkins) CreateDevOpsProject(projectId string) (string, error) { 27 | _, err := j.CreateFolder(projectId, "") 28 | if err != nil { 29 | klog.Errorf("%+v", err) 30 | return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) 31 | } 32 | return projectId, nil 33 | } 34 | 35 | func (j *Jenkins) DeleteDevOpsProject(projectId string) (err error) { 36 | _, err = j.DeleteJob(projectId) 37 | if err != nil { 38 | return restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) 39 | } 40 | return 41 | } 42 | 43 | func (j *Jenkins) GetDevOpsProject(projectId string) (string, error) { 44 | job, err := j.GetJob(projectId) 45 | if err != nil { 46 | klog.Errorf("%+v", err) 47 | return "", restful.NewError(devops.GetDevOpsStatusCode(err), err.Error()) 48 | 49 | } 50 | return job.GetName(), nil 51 | } 52 | -------------------------------------------------------------------------------- /pkg/client/devops/jenkins/request_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package jenkins 18 | 19 | import ( 20 | "net/http" 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func newFakeRequester() *Requester { 27 | // init log 28 | new(Jenkins).initLoggers() 29 | 30 | return &Requester{ 31 | Base: "localhost", 32 | Client: http.DefaultClient, 33 | } 34 | } 35 | 36 | func newFakeAPIRequest() *APIRequest { 37 | return NewAPIRequest("POST", "/test", nil) 38 | } 39 | 40 | func TestRequesterDo(t *testing.T) { 41 | // test upload fail logic 42 | requester := newFakeRequester() 43 | fileNames := []string{"a.tmp", "b.tmp"} 44 | _, err := requester.Do(newFakeAPIRequest(), nil, fileNames) 45 | assert.NotNil(t, err) 46 | } 47 | 48 | func TestRequesterDoGet(t *testing.T) { 49 | // test upload fail logic 50 | requester := newFakeRequester() 51 | fileNames := []string{"a.tmp", "b.tmp"} 52 | _, err := requester.DoGet(newFakeAPIRequest(), nil, fileNames) 53 | assert.NotNil(t, err) 54 | } 55 | -------------------------------------------------------------------------------- /pkg/client/devops/project.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | /* 20 | * 21 | project operator, providing API for creating/getting/deleting projects 22 | The actual data of the project is stored in the CRD, 23 | so we only need to create the project with the corresponding ID in the CI/CD system. 24 | */ 25 | type ProjectOperator interface { 26 | CreateDevOpsProject(projectId string) (string, error) 27 | DeleteDevOpsProject(projectId string) error 28 | GetDevOpsProject(projectId string) (string, error) 29 | } 30 | -------------------------------------------------------------------------------- /pkg/client/devops/project_pipeline.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha3" 20 | 21 | type ProjectPipelineOperator interface { 22 | CreateProjectPipeline(projectId string, pipeline *v1alpha3.Pipeline) (string, error) 23 | DeleteProjectPipeline(projectId string, pipelineId string) (string, error) 24 | UpdateProjectPipeline(projectId string, pipeline *v1alpha3.Pipeline) (string, error) 25 | GetProjectPipelineConfig(projectId, pipelineId string) (*v1alpha3.Pipeline, error) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/client/git/message.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package git 18 | 19 | // VerifyResponse represents a response of SCM auth verify 20 | type VerifyResponse struct { 21 | // Message is the detail of the result 22 | Message string `json:"message"` 23 | // Code represents a group of cases 24 | Code int `json:"code"` 25 | CredentialID string `json:"credentialId,omitempty" description:"the id of credential"` 26 | } 27 | 28 | func VerifyPass() *VerifyResponse { 29 | return &VerifyResponse{ 30 | Message: "ok", 31 | } 32 | } 33 | 34 | func VerifyFailed(message string, code int) *VerifyResponse { 35 | return &VerifyResponse{ 36 | Message: message, 37 | Code: code, 38 | } 39 | } 40 | 41 | func VerifyResult(err error, code int) *VerifyResponse { 42 | if err == nil { 43 | return VerifyPass() 44 | } 45 | return VerifyFailed(err.Error(), code) 46 | } 47 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // xCode generated by informer-gen. DO NOT EDIT. 18 | 19 | package internalinterfaces 20 | 21 | import ( 22 | time "time" 23 | 24 | versioned "github.com/kubesphere/ks-devops/pkg/client/clientset/versioned" 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | cache "k8s.io/client-go/tools/cache" 28 | ) 29 | 30 | // NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. 31 | type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer 32 | 33 | // SharedInformerFactory a small interface to allow for adding an informer without an import cycle 34 | type SharedInformerFactory interface { 35 | Start(stopCh <-chan struct{}) 36 | InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer 37 | } 38 | 39 | // TweakListOptionsFunc is a function that transforms a v1.ListOptions. 40 | type TweakListOptionsFunc func(*v1.ListOptions) 41 | -------------------------------------------------------------------------------- /pkg/client/k8s/options_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package k8s 18 | 19 | import ( 20 | "github.com/spf13/pflag" 21 | "github.com/stretchr/testify/assert" 22 | "testing" 23 | ) 24 | 25 | func TestNewKubernetesOptions(t *testing.T) { 26 | options := NewKubernetesOptions() 27 | assert.NotNil(t, options) 28 | 29 | options.KubeConfig = "" 30 | assert.Equal(t, []error{}, options.Validate()) 31 | 32 | options.ApplyTo(options) 33 | 34 | flagSet := &pflag.FlagSet{} 35 | options.AddFlags(flagSet, options) 36 | assert.NotNil(t, flagSet.Lookup("kubeconfig")) 37 | assert.NotNil(t, flagSet.Lookup("master")) 38 | } 39 | -------------------------------------------------------------------------------- /pkg/client/listers/devops/v1alpha3/expansion_generated.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1alpha3 20 | 21 | // DevOpsProjectListerExpansion allows custom methods to be added to 22 | // DevOpsProjectLister. 23 | type DevOpsProjectListerExpansion interface{} 24 | 25 | // PipelineListerExpansion allows custom methods to be added to 26 | // PipelineLister. 27 | type PipelineListerExpansion interface{} 28 | 29 | // PipelineNamespaceListerExpansion allows custom methods to be added to 30 | // PipelineNamespaceLister. 31 | type PipelineNamespaceListerExpansion interface{} 32 | -------------------------------------------------------------------------------- /pkg/client/s3/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 KubeSphere Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package s3 18 | 19 | import ( 20 | "io" 21 | ) 22 | 23 | type Interface interface { 24 | //read the content, caller should close the io.ReadCloser. 25 | Read(key string) ([]byte, error) 26 | 27 | // Upload uploads a object to storage and returns object location if succeeded 28 | Upload(key, fileName string, body io.Reader) error 29 | 30 | GetDownloadURL(key string, fileName string) (string, error) 31 | 32 | // Delete deletes an object by its key 33 | Delete(key string) error 34 | } 35 | -------------------------------------------------------------------------------- /pkg/client/sonarqube/OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - linuxsuren 3 | 4 | reviewers: 5 | - runzexia 6 | - soulseen 7 | - shaowenchen 8 | - linuxsuren 9 | 10 | labels: 11 | - area/devops 12 | -------------------------------------------------------------------------------- /pkg/client/sonarqube/options_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package sonarqube 18 | 19 | import ( 20 | "github.com/spf13/pflag" 21 | "github.com/stretchr/testify/assert" 22 | "testing" 23 | ) 24 | 25 | func TestNewSonarQubeOptions(t *testing.T) { 26 | options := NewSonarQubeOptions() 27 | assert.NotNil(t, options) 28 | 29 | assert.Nil(t, options.Validate()) 30 | 31 | options.Host = "not-empty" 32 | options.ApplyTo(&Options{ 33 | Host: "host", 34 | Token: "token", 35 | }) 36 | assert.Equal(t, "not-empty", options.Host) 37 | assert.Equal(t, "", options.Token) 38 | 39 | flagSet := &pflag.FlagSet{} 40 | options.AddFlags(flagSet, options) 41 | assert.NotNil(t, flagSet.Lookup("sonarqube-host")) 42 | assert.NotNil(t, flagSet.Lookup("sonarqube-token")) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/client/sonarqube/sonarqube_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package sonarqube 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestNewSonarQubeClient(t *testing.T) { 25 | options := NewSonarQubeOptions() 26 | client, err := NewSonarQubeClient(options) 27 | assert.Nil(t, err) 28 | assert.NotNil(t, client) 29 | 30 | assert.NotNil(t, client.SonarQube()) 31 | } 32 | -------------------------------------------------------------------------------- /pkg/event/README.md: -------------------------------------------------------------------------------- 1 | # Event package for Pipeline Event Plugin 2 | 3 | This package is design to easily handle the data sent by the [pipeline-event](https://github.com/JohnNiang/pipeline-event-plugin) plugin. In the future, it needs to be independent into a separate project. If anyone is interested, you are very welcome to complete this task. 4 | -------------------------------------------------------------------------------- /pkg/event/common/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package common 18 | 19 | import ( 20 | "encoding/json" 21 | ) 22 | 23 | const ( 24 | // RunInitialize represents Jenkins run is initializing. 25 | RunInitialize string = "run.initialize" 26 | // RunStarted represents Jenkins run has started. 27 | RunStarted string = "run.started" 28 | // RunFinalized represents Jenkins run has finalized. 29 | RunFinalized string = "run.finalized" 30 | // RunCompleted represents Jenkins run has completed. 31 | RunCompleted string = "run.completed" 32 | // RunDeleted represents Jenkins run has been deleted. 33 | RunDeleted string = "run.deleted" 34 | ) 35 | 36 | // Event contains common fields of event except event data. 37 | type Event struct { 38 | Type string `json:"type"` 39 | Source string `json:"source"` 40 | ID string `json:"id"` 41 | Time string `json:"time"` 42 | DataType string `json:"dataType"` 43 | Data json.RawMessage `json:"data"` 44 | } 45 | -------------------------------------------------------------------------------- /pkg/event/workflowrun/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package workflowrun 18 | 19 | // Data contains WorkflowJob brief information and WorkflowRun detail. 20 | type Data struct { 21 | Actions Actions `json:"actions"` 22 | Building bool `json:"building"` 23 | Description string `json:"description"` 24 | DisplayName string `json:"displayName"` 25 | Duration int `json:"duration"` 26 | EstimatedDuration int `json:"estimatedDuration"` 27 | FullDisplayName string `json:"fullDisplayName"` 28 | ID string `json:"id"` 29 | KeepLog bool `json:"keepLog"` 30 | Number int `json:"number"` 31 | QueueID int `json:"queueId"` 32 | Result string `json:"result"` 33 | Timestamp int64 `json:"timestamp"` 34 | ParentFullName string `json:"_parentFullName"` 35 | ProjectName string `json:"_projectName"` 36 | IsMultiBranch bool `json:"_multiBranch"` 37 | } 38 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/helm/v2beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v2beta1 contains API Schema definitions for the helm v2beta1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=helm.toolkit.fluxcd.io 20 | package v2beta1 21 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/helm/v2beta1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v2beta1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | "sigs.k8s.io/controller-runtime/pkg/scheme" 22 | ) 23 | 24 | var ( 25 | // GroupVersion is group version used to register these objects 26 | GroupVersion = schema.GroupVersion{Group: "helm.toolkit.fluxcd.io", Version: "v2beta1"} 27 | 28 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 29 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 30 | 31 | // AddToScheme adds the types in this group-version to the given scheme. 32 | AddToScheme = SchemeBuilder.AddToScheme 33 | ) 34 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/kustomize/v1beta2/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1beta2 contains API Schema definitions for the kustomize.toolkit.fluxcd.io v1beta2 API group. 18 | // +kubebuilder:object:generate=true 19 | // +groupName=kustomize.toolkit.fluxcd.io 20 | package v1beta2 21 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/kustomize/v1beta2/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta2 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | "sigs.k8s.io/controller-runtime/pkg/scheme" 22 | ) 23 | 24 | var ( 25 | // GroupVersion is group version used to register these objects. 26 | GroupVersion = schema.GroupVersion{Group: "kustomize.toolkit.fluxcd.io", Version: "v1beta2"} 27 | 28 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme. 29 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 30 | 31 | // AddToScheme adds the types in this group-version to the given scheme. 32 | AddToScheme = SchemeBuilder.AddToScheme 33 | ) 34 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/kustomize/v1beta2/reference_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta2 18 | 19 | // CrossNamespaceSourceReference contains enough information to let you locate the 20 | // typed Kubernetes resource object at cluster level. 21 | type CrossNamespaceSourceReference struct { 22 | // API version of the referent. 23 | // +optional 24 | APIVersion string `json:"apiVersion,omitempty"` 25 | 26 | // Kind of the referent. 27 | // +kubebuilder:validation:Enum=OCIRepository;GitRepository;Bucket 28 | // +required 29 | Kind string `json:"kind"` 30 | 31 | // Name of the referent. 32 | // +required 33 | Name string `json:"name"` 34 | 35 | // Namespace of the referent, defaults to the namespace of the Kubernetes resource object that contains the reference. 36 | // +optional 37 | Namespace string `json:"namespace,omitempty"` 38 | } 39 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/meta/annotations.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | // ReconcileRequestStatus is a struct to embed in a status type, so that all types using the mechanism have the same 20 | // field. Use it like this: 21 | // 22 | // type FooStatus struct { 23 | // meta.ReconcileRequestStatus `json:",inline"` 24 | // // other status fields... 25 | // } 26 | type ReconcileRequestStatus struct { 27 | // LastHandledReconcileAt holds the value of the most recent 28 | // reconcile request value, so a change of the annotation value 29 | // can be detected. 30 | // +optional 31 | LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/meta/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package meta contains the generic metadata APIs for use by GitOps Toolkit components. 18 | // 19 | // It is intended only to help adhere to Kubernetes API conventions, utility integrations, and Flux project considered 20 | // best practices. It may therefore be suitable for usage by Kubernetes resources with no relationship to the GitOps 21 | // Toolkit. 22 | // +kubebuilder:object:generate=true 23 | package meta 24 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/source/v1beta2/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1beta2 contains API Schema definitions for the source v1beta2 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=source.toolkit.fluxcd.io 20 | package v1beta2 21 | -------------------------------------------------------------------------------- /pkg/external/fluxcd/source/v1beta2/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Flux authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta2 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | "sigs.k8s.io/controller-runtime/pkg/scheme" 22 | ) 23 | 24 | var ( 25 | // GroupVersion is group version used to register these objects. 26 | GroupVersion = schema.GroupVersion{Group: "source.toolkit.fluxcd.io", Version: "v1beta2"} 27 | 28 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme. 29 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 30 | 31 | // AddToScheme adds the types in this group-version to the given scheme. 32 | AddToScheme = SchemeBuilder.AddToScheme 33 | ) 34 | -------------------------------------------------------------------------------- /pkg/jwt/token/fake_issuer.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package token 18 | 19 | import ( 20 | "time" 21 | 22 | "k8s.io/apiserver/pkg/authentication/user" 23 | ) 24 | 25 | // FakeIssuer is a fake issue for the test purpose 26 | type FakeIssuer struct { 27 | Token string 28 | IssueToError error 29 | VerifyError error 30 | } 31 | 32 | // IssueTo is a fake function 33 | func (f *FakeIssuer) IssueTo(user user.Info, tokenType TokenType, expiresIn time.Duration) (string, error) { 34 | return f.Token, f.IssueToError 35 | } 36 | 37 | // Verify verifies a token, and return a user info if it's a valid token, otherwise return error 38 | func (f *FakeIssuer) Verify(string) (user.Info, TokenType, error) { 39 | return &user.DefaultInfo{}, "", f.VerifyError 40 | } 41 | 42 | // VerifyWithoutClaimsValidation verifies a token, but skip the claims validation 43 | func (f *FakeIssuer) VerifyWithoutClaimsValidation(token string) (user.Info, TokenType, error) { 44 | return f.Verify(token) 45 | } 46 | -------------------------------------------------------------------------------- /pkg/jwt/token/fake_issuer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package token 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "k8s.io/apiserver/pkg/authentication/user" 22 | "testing" 23 | ) 24 | 25 | func TestFakeIssuer_IssueTo(t *testing.T) { 26 | f := &FakeIssuer{ 27 | Token: "Token", 28 | IssueToError: nil, 29 | VerifyError: nil, 30 | } 31 | got, err := f.IssueTo(&user.DefaultInfo{}, "type", 0) 32 | assert.Equal(t, "Token", got) 33 | assert.Nil(t, err) 34 | 35 | _, _, err = f.Verify("token") 36 | assert.Nil(t, err) 37 | 38 | _, _, err = f.VerifyWithoutClaimsValidation("token") 39 | assert.Nil(t, err) 40 | } 41 | -------------------------------------------------------------------------------- /pkg/jwt/token/issuer.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package token 18 | 19 | import ( 20 | "time" 21 | 22 | "k8s.io/apiserver/pkg/authentication/user" 23 | ) 24 | 25 | const ( 26 | AccessToken TokenType = "access_token" 27 | RefreshToken TokenType = "refresh_token" 28 | StaticToken TokenType = "static_token" 29 | ) 30 | 31 | type TokenType string 32 | 33 | // Issuer issues token to user, tokens are required to perform mutating requests to resources 34 | type Issuer interface { 35 | // IssueTo issues a token a User, return error if issuing process failed 36 | IssueTo(user user.Info, tokenType TokenType, expiresIn time.Duration) (string, error) 37 | 38 | // Verify verifies a token, and return a user info if it's a valid token, otherwise return error 39 | Verify(string) (user.Info, TokenType, error) 40 | 41 | // VerifyWithoutClaimsValidation verifies a token, but skip the claims validation 42 | VerifyWithoutClaimsValidation(string) (user.Info, TokenType, error) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/kapis/devops/group.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha2/OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - linuxsuren 3 | 4 | reviewers: 5 | - runzexia 6 | - soulseen 7 | - shaowenchen 8 | - linuxsuren 9 | 10 | labels: 11 | - area/devops 12 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/common/options.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package common 17 | 18 | import ( 19 | "github.com/emicklei/go-restful/v3" 20 | "sigs.k8s.io/controller-runtime/pkg/client" 21 | ) 22 | 23 | // Options contain options needed by creating handlers. 24 | type Options struct { 25 | GenericClient client.Client 26 | } 27 | 28 | var ( 29 | // DevopsPathParameter is a path parameter definition for devops. 30 | DevopsPathParameter = restful.PathParameter("devops", "DevOps project name") 31 | ) 32 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/handler_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha3 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestNewSuccessGenericArrayResponse(t *testing.T) { 25 | type args struct { 26 | data []string 27 | } 28 | tests := []struct { 29 | name string 30 | args args 31 | want *GenericArrayResponse 32 | }{{ 33 | name: "normal", 34 | args: args{ 35 | data: []string{"good", "bad"}, 36 | }, 37 | want: &GenericArrayResponse{ 38 | Status: "success", 39 | Data: []string{"good", "bad"}, 40 | }, 41 | }} 42 | for _, tt := range tests { 43 | t.Run(tt.name, func(t *testing.T) { 44 | assert.Equalf(t, tt.want, NewSuccessGenericArrayResponse(tt.args.data), "NewSuccessGenericArrayResponse(%v)", tt.args.data) 45 | }) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/scm/testdata/orgs.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "login": "github", 4 | "id": 1, 5 | "url": "https://api.github.com/orgs/github", 6 | "repos_url": "https://api.github.com/orgs/github/repos", 7 | "events_url": "https://api.github.com/orgs/github/events", 8 | "hooks_url": "https://api.github.com/orgs/github/hooks", 9 | "issues_url": "https://api.github.com/orgs/github/issues", 10 | "members_url": "https://api.github.com/orgs/github/members{/member}", 11 | "public_members_url": "https://api.github.com/orgs/github/public_members{/member}", 12 | "avatar_url": "https://github.com/images/error/octocat_happy.gif", 13 | "description": "A great organization" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/scm/testdata/user.json: -------------------------------------------------------------------------------- 1 | { 2 | "login": "octocat", 3 | "id": 1, 4 | "avatar_url": "https://github.com/images/error/octocat_happy.gif", 5 | "gravatar_id": "", 6 | "url": "https://api.github.com/users/octocat", 7 | "html_url": "https://github.com/octocat", 8 | "followers_url": "https://api.github.com/users/octocat/followers", 9 | "following_url": "https://api.github.com/users/octocat/following{/other_user}", 10 | "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", 11 | "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", 12 | "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", 13 | "organizations_url": "https://api.github.com/users/octocat/orgs", 14 | "repos_url": "https://api.github.com/users/octocat/repos", 15 | "events_url": "https://api.github.com/users/octocat/events{/privacy}", 16 | "received_events_url": "https://api.github.com/users/octocat/received_events", 17 | "type": "User", 18 | "site_admin": false, 19 | "name": "monalisa octocat", 20 | "company": "GitHub", 21 | "blog": "https://github.com/blog", 22 | "location": "San Francisco", 23 | "email": "octocat@github.com", 24 | "hireable": false, 25 | "bio": "There once was...", 26 | "public_repos": 2, 27 | "public_gists": 1, 28 | "followers": 20, 29 | "following": 0, 30 | "created_at": "2008-01-14T04:33:35Z", 31 | "updated_at": "2008-01-14T04:33:35Z" 32 | } -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/scm/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package scm 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha3" 21 | ) 22 | 23 | type organization struct { 24 | Name string `json:"name"` 25 | // Avatar is the image of an organization which comes from a git provider 26 | // try to find a better way to have it. Now, keeping it just because we need to keep compatible with the Jenkins response 27 | // example: https://avatars.githubusercontent.com/jenkinsci 28 | Avatar string `json:"avatar"` 29 | } 30 | 31 | type repository struct { 32 | DefaultBranch string `json:"defaultBranch"` 33 | Name string `json:"name"` 34 | } 35 | 36 | type repositoryListResult struct { 37 | Repositories struct { 38 | Items []repository `json:"items"` 39 | } `json:"repositories"` 40 | } 41 | 42 | // GitRepositoryPageResult is the model of page result of GitRepositories. 43 | type GitRepositoryPageResult struct { 44 | Items []v1alpha3.GitRepository `json:"items"` 45 | TotalItems int `json:"totalItems"` 46 | } 47 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/scm/utils.go: -------------------------------------------------------------------------------- 1 | package scm 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "strings" 7 | 8 | "github.com/go-git/go-git/v5/plumbing/transport" 9 | "github.com/go-git/go-git/v5/plumbing/transport/http" 10 | "github.com/go-git/go-git/v5/plumbing/transport/ssh" 11 | gossh "golang.org/x/crypto/ssh" 12 | ) 13 | 14 | func getAuthMethod(repoURL, username, password string, sshKey []byte) (transport.AuthMethod, error) { 15 | switch { 16 | case strings.HasPrefix(repoURL, "http://"), strings.HasPrefix(repoURL, "https://"): 17 | if password == "" { 18 | return nil, errors.New("password/token required for HTTP URLs") 19 | } 20 | return &http.BasicAuth{Username: username, Password: password}, nil 21 | 22 | case strings.HasPrefix(repoURL, "git@"): 23 | fallthrough 24 | case strings.Contains(repoURL, "ssh://"): 25 | if len(sshKey) == 0 { 26 | return nil, errors.New("SSH private key required for SSH URLs") 27 | } 28 | 29 | publicKeys, err := ssh.NewPublicKeys(username, sshKey, password) 30 | if err != nil { 31 | return nil, fmt.Errorf("failed to create SSH auth: %w", err) 32 | } 33 | publicKeys.HostKeyCallback = gossh.InsecureIgnoreHostKey() 34 | 35 | return publicKeys, nil 36 | 37 | default: 38 | return nil, errors.New("unsupported repository URL scheme") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/template/handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package template 17 | 18 | import ( 19 | "github.com/kubesphere/ks-devops/pkg/kapis/devops/v1alpha3/common" 20 | "sigs.k8s.io/controller-runtime/pkg/client" 21 | ) 22 | 23 | type handler struct { 24 | client.Client 25 | } 26 | 27 | func newHandler(options *common.Options) *handler { 28 | return &handler{ 29 | Client: options.GenericClient, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pkg/kapis/devops/v1alpha3/template/handler_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package template 15 | 16 | import ( 17 | "reflect" 18 | "testing" 19 | 20 | "github.com/kubesphere/ks-devops/pkg/kapis/devops/v1alpha3/common" 21 | "k8s.io/client-go/kubernetes/scheme" 22 | "sigs.k8s.io/controller-runtime/pkg/client/fake" 23 | ) 24 | 25 | func Test_newHandler(t *testing.T) { 26 | fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() 27 | type args struct { 28 | options *common.Options 29 | } 30 | tests := []struct { 31 | name string 32 | args args 33 | want *handler 34 | }{{ 35 | name: "Should set handler correctly", 36 | args: args{ 37 | options: &common.Options{ 38 | GenericClient: fakeClient, 39 | }, 40 | }, 41 | want: &handler{ 42 | Client: fakeClient, 43 | }, 44 | }, 45 | } 46 | for _, tt := range tests { 47 | t.Run(tt.name, func(t *testing.T) { 48 | if got := newHandler(tt.args.options); !reflect.DeepEqual(got, tt.want) { 49 | t.Errorf("newHandler() = %v, want %v", got, tt.want) 50 | } 51 | }) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /pkg/kapis/gitops/v1alpha1/gitops/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 KubeSphere Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | package gitops 17 | 18 | import ( 19 | "github.com/kubesphere/ks-devops/pkg/api/gitops/v1alpha1" 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/client" 22 | ) 23 | 24 | func ToObjects(apps []v1alpha1.Application) []runtime.Object { 25 | objs := make([]runtime.Object, len(apps)) 26 | for i := range apps { 27 | objs[i] = &apps[i] 28 | } 29 | return objs 30 | } 31 | 32 | func ToClientObjects(apps []v1alpha1.Application) []client.Object { 33 | objs := make([]client.Object, len(apps)) 34 | for i := range apps { 35 | objs[i] = &apps[i] 36 | } 37 | return objs 38 | } 39 | -------------------------------------------------------------------------------- /pkg/kapis/oauth/register_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package oauth 18 | 19 | import ( 20 | "bytes" 21 | "github.com/emicklei/go-restful/v3" 22 | "github.com/stretchr/testify/assert" 23 | "net/http" 24 | "net/http/httptest" 25 | "testing" 26 | ) 27 | 28 | func TestAPIsExist(t *testing.T) { 29 | httpWriter := httptest.NewRecorder() 30 | 31 | AddToContainer(restful.DefaultContainer, nil) 32 | 33 | type args struct { 34 | method string 35 | uri string 36 | } 37 | tests := []struct { 38 | name string 39 | args args 40 | }{{ 41 | name: "authenticate", 42 | args: args{ 43 | method: http.MethodPost, 44 | uri: "/authenticate", 45 | }, 46 | }} 47 | for _, tt := range tests { 48 | t.Run(tt.name, func(t *testing.T) { 49 | httpRequest, _ := http.NewRequest(tt.args.method, 50 | "http://fake.com/oauth"+tt.args.uri, bytes.NewBuffer([]byte("{}"))) 51 | httpRequest.Header.Set("Content-Type", "application/json") 52 | restful.DefaultContainer.Dispatch(httpWriter, httpRequest) 53 | assert.NotEqual(t, httpWriter.Code, 404) 54 | }) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /pkg/kapis/proxy/register.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "github.com/emicklei/go-restful/v3" 8 | "github.com/kubesphere/ks-devops/pkg/api/devops" 9 | "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha1" 10 | "github.com/kubesphere/ks-devops/pkg/api/devops/v1alpha3" 11 | "github.com/kubesphere/ks-devops/pkg/kapis/devops/v1alpha2" 12 | ) 13 | 14 | func AddToContainer(container *restful.Container) { 15 | versions := []string{v1alpha1.GroupVersion.Version, v1alpha2.GroupVersion.Version, v1alpha3.GroupVersion.Version} 16 | for _, version := range versions { 17 | proxyWS := new(restful.WebService) 18 | proxyWS.Path("/" + version). 19 | Consumes(restful.MIME_JSON). 20 | Produces(restful.MIME_JSON) 21 | 22 | for _, method := range []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete, http.MethodPatch, http.MethodConnect, http.MethodHead, http.MethodOptions, http.MethodTrace} { 23 | proxyWS.Route(proxyWS.Method(method).Path("/{subpath:*}").To(func(req *restful.Request, resp *restful.Response) { 24 | // Rewrite the URL to include /kapis 25 | originalPath := req.Request.URL.Path 26 | newPath := fmt.Sprintf("/kapis/%s%s", devops.GroupName, originalPath) 27 | 28 | // Forward the request to the container with the rewritten path 29 | req.Request.URL.Path = newPath 30 | container.Dispatch(resp, req.Request) 31 | })) 32 | } 33 | 34 | container.Add(proxyWS) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pkg/models/devops/OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - linuxsuren 3 | 4 | reviewers: 5 | - runzexia 6 | - soulseen 7 | - shaowenchen 8 | - linuxsuren 9 | 10 | labels: 11 | - area/devops 12 | -------------------------------------------------------------------------------- /pkg/models/devops/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import ( 20 | "time" 21 | ) 22 | 23 | const ( 24 | StatusActive = "active" 25 | StatusDeleted = "deleted" 26 | StatusDeleting = "deleting" 27 | StatusFailed = "failed" 28 | StatusPending = "pending" 29 | StatusWorking = "working" 30 | StatusSuccessful = "successful" 31 | ) 32 | 33 | const ( 34 | StatusColumn = "status" 35 | StatusTimeColumn = "status_time" 36 | ) 37 | 38 | // GetSyncNowTime returns unified sync current time 39 | func GetSyncNowTime() string { 40 | return time.Now().String() 41 | } 42 | 43 | type StringMap map[string]string 44 | -------------------------------------------------------------------------------- /pkg/models/devops/common_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestGetSyncNowTime(t *testing.T) { 25 | assert.NotEmpty(t, GetSyncNowTime()) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/models/devops/jkerror.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | type JkError struct { 20 | Message string `json:"message"` 21 | Code int `json:"code"` 22 | } 23 | 24 | func (err *JkError) Error() string { 25 | return err.Message 26 | } 27 | -------------------------------------------------------------------------------- /pkg/models/devops/jkerror_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestJkError_Error(t *testing.T) { 25 | err := &JkError{Message: "message"} 26 | assert.Equal(t, "message", err.Error()) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/models/devops/project_credential_handler.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import ( 20 | "k8s.io/klog/v2" 21 | 22 | "github.com/kubesphere/ks-devops/pkg/client/devops" 23 | ) 24 | 25 | type ProjectCredentialGetter interface { 26 | GetProjectCredentialUsage(projectId, credentialId string) (*devops.Credential, error) 27 | } 28 | 29 | type projectCredentialGetter struct { 30 | devopsClient devops.Interface 31 | } 32 | 33 | // GetProjectCredentialUsage get the usage of Credential 34 | func (o *projectCredentialGetter) GetProjectCredentialUsage(projectId, credentialId string) (*devops.Credential, error) { 35 | credential, err := o.devopsClient.GetCredentialInProject(projectId, 36 | credentialId) 37 | if err != nil { 38 | klog.Errorf("%+v", err) 39 | return nil, err 40 | } 41 | return credential, nil 42 | } 43 | 44 | func NewProjectCredentialOperator(devopsClient devops.Interface) ProjectCredentialGetter { 45 | return &projectCredentialGetter{devopsClient: devopsClient} 46 | } 47 | -------------------------------------------------------------------------------- /pkg/models/devops/project_pipeline_sonar_handler_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package devops 18 | 19 | import ( 20 | "github.com/stretchr/testify/assert" 21 | "testing" 22 | ) 23 | 24 | func TestNewPipelineSonarGetter(t *testing.T) { 25 | getter := NewPipelineSonarGetter(nil, nil) 26 | assert.NotNil(t, getter) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/models/pipelinerun/pipelinerun.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pipelinerun 18 | 19 | import "github.com/jenkins-zh/jenkins-client/pkg/job" 20 | 21 | // NodeDetail contains metadata of node and an array of steps. 22 | type NodeDetail struct { 23 | job.Node 24 | Steps []Step `json:"steps,omitempty"` 25 | } 26 | 27 | // Step conatains metadata of step with approvable. 28 | type Step struct { 29 | job.Step 30 | // Approvable is a transient field for different users and should not be persisted. 31 | Approvable bool `json:"approvable,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/server/errors/errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package errors 18 | 19 | import ( 20 | "fmt" 21 | "net/http" 22 | 23 | "github.com/emicklei/go-restful/v3" 24 | ) 25 | 26 | type Error struct { 27 | Message string `json:"message" description:"error message"` 28 | } 29 | 30 | var None = Error{Message: "success"} 31 | 32 | func (e Error) Error() string { 33 | return e.Message 34 | } 35 | 36 | func Wrap(err error) error { 37 | return Error{Message: err.Error()} 38 | } 39 | 40 | func New(format string, args ...interface{}) error { 41 | return Error{Message: fmt.Sprintf(format, args...)} 42 | } 43 | 44 | func GetServiceErrorCode(err error) int { 45 | if svcErr, ok := err.(restful.ServiceError); ok { 46 | return svcErr.Code 47 | } else { 48 | return http.StatusInternalServerError 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/store/fake/fake_core_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fake 18 | 19 | import ( 20 | "errors" 21 | "github.com/stretchr/testify/assert" 22 | "testing" 23 | ) 24 | 25 | func TestFakeStore(t *testing.T) { 26 | store := NewFakeStore() 27 | assert.NotNil(t, store) 28 | 29 | assert.Empty(t, store.Get("fake")) 30 | store.Set("fake", "fake") 31 | assert.Equal(t, "fake", store.Get("fake")) 32 | 33 | assert.Empty(t, store.GetAllLog()) 34 | store.SetAllLog("log") 35 | assert.Equal(t, "log", store.GetAllLog()) 36 | 37 | assert.Empty(t, store.GetStages()) 38 | store.SetStages("stages") 39 | assert.Equal(t, "stages", store.GetStages()) 40 | 41 | assert.Empty(t, store.GetStatus()) 42 | store.SetStatus("status") 43 | assert.Equal(t, "status", store.GetStatus()) 44 | 45 | assert.Empty(t, store.GetStepLog(1, 1)) 46 | store.SetStepLog(1, 1, "step") 47 | assert.Equal(t, "step", store.GetStepLog(1, 1)) 48 | 49 | assert.Nil(t, store.Save()) 50 | assert.NotNil(t, store.WithError(errors.New("fake")).Save()) 51 | } 52 | -------------------------------------------------------------------------------- /pkg/store/store/types_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package store 18 | 19 | import "testing" 20 | 21 | func TestStepLogKey(t *testing.T) { 22 | type args struct { 23 | stage int 24 | step int 25 | } 26 | tests := []struct { 27 | name string 28 | args args 29 | want string 30 | }{{ 31 | name: "normal", 32 | args: args{ 33 | stage: 1, 34 | step: 2, 35 | }, 36 | want: "log-step-1-2", 37 | }} 38 | for _, tt := range tests { 39 | t.Run(tt.name, func(t *testing.T) { 40 | if got := StepLogKey(tt.args.stage, tt.args.step); got != tt.want { 41 | t.Errorf("StepLogKey() = %v, want %v", got, tt.want) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/utils/hashutil/MD5.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019-2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package hashutil 18 | 19 | import ( 20 | "encoding/hex" 21 | "io" 22 | 23 | "code.cloudfoundry.org/bytefmt" 24 | "github.com/kubesphere/ks-devops/pkg/utils/readerutils" 25 | ) 26 | 27 | // GetMD5 returns the md5 value from a reader 28 | func GetMD5(reader io.ReadCloser) (result string, err error) { 29 | md5reader := readerutils.NewMD5Reader(reader) 30 | data := make([]byte, bytefmt.KILOBYTE) 31 | for { 32 | _, err = md5reader.Read(data) 33 | if err != nil { 34 | if err == io.EOF { 35 | break 36 | } 37 | return 38 | } 39 | } 40 | if err = reader.Close(); err == nil { 41 | result = hex.EncodeToString(md5reader.MD5()) 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /pkg/utils/hashutil/MD5_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package hashutil 15 | 16 | import ( 17 | "bytes" 18 | "io" 19 | "io/ioutil" 20 | "testing" 21 | ) 22 | 23 | func TestGetMD5(t *testing.T) { 24 | type args struct { 25 | reader io.ReadCloser 26 | } 27 | tests := []struct { 28 | name string 29 | args args 30 | want string 31 | wantErr bool 32 | }{{ 33 | name: "normal", 34 | args: args{reader: ioutil.NopCloser(bytes.NewBufferString("abc"))}, 35 | want: "900150983cd24fb0d6963f7d28e17f72", 36 | wantErr: false, 37 | }} 38 | for _, tt := range tests { 39 | t.Run(tt.name, func(t *testing.T) { 40 | got, err := GetMD5(tt.args.reader) 41 | if (err != nil) != tt.wantErr { 42 | t.Errorf("GetMD5() error = %v, wantErr %v", err, tt.wantErr) 43 | return 44 | } 45 | if got != tt.want { 46 | t.Errorf("GetMD5() got = %v, want %v", got, tt.want) 47 | } 48 | }) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/utils/idutils/id_utils_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package idutils 18 | 19 | import ( 20 | "fmt" 21 | "sort" 22 | "testing" 23 | ) 24 | 25 | func TestGetUuid(t *testing.T) { 26 | fmt.Println(GetUuid("")) 27 | } 28 | 29 | func TestGetUuid36(t *testing.T) { 30 | fmt.Println(GetUuid36("")) 31 | } 32 | 33 | func TestGetManyUuid(t *testing.T) { 34 | var strSlice []string 35 | for i := 0; i < 10000; i++ { 36 | testID := GetUuid("") 37 | strSlice = append(strSlice, testID) 38 | } 39 | sort.Strings(strSlice) 40 | } 41 | -------------------------------------------------------------------------------- /pkg/utils/readerutils/MD5Reader.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019-2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package readerutils 18 | 19 | import ( 20 | "crypto/md5" 21 | "hash" 22 | "io" 23 | ) 24 | 25 | // MD5Reader is a reader to read the dm5 26 | type MD5Reader struct { 27 | md5 hash.Hash 28 | body io.Reader 29 | } 30 | 31 | // Read reads the data 32 | func (reader *MD5Reader) Read(b []byte) (n int, err error) { 33 | n, err = reader.body.Read(b) 34 | if err == nil { 35 | n, err = reader.md5.Write(b[:n]) 36 | } 37 | return 38 | } 39 | 40 | // MD5 returns the data 41 | func (reader *MD5Reader) MD5() []byte { 42 | return reader.md5.Sum(nil) 43 | } 44 | 45 | // NewMD5Reader creates a md5 reader 46 | func NewMD5Reader(reader io.Reader) *MD5Reader { 47 | return &MD5Reader{ 48 | md5: md5.New(), 49 | body: reader, 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkg/utils/readerutils/MD5Reader_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package readerutils 15 | 16 | import ( 17 | "bytes" 18 | "github.com/stretchr/testify/assert" 19 | "testing" 20 | ) 21 | 22 | func TestNewMD5Reader(t *testing.T) { 23 | buf := bytes.NewBufferString("abc") 24 | reader := NewMD5Reader(buf) 25 | assert.NotNil(t, reader) 26 | assert.Equal(t, "\xd4\x1d\x8cُ\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~", string(reader.MD5())) 27 | count, err := reader.Read([]byte("abc")) 28 | assert.Equal(t, 3, count) 29 | assert.Nil(t, err) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/utils/sliceutil/sliceutils.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package sliceutil 18 | 19 | // RemoveString removes an item from a slice with a custom function 20 | func RemoveString(slice []string, remove func(item string) bool) []string { 21 | for i := 0; i < len(slice); i++ { 22 | if remove(slice[i]) { 23 | slice = append(slice[:i], slice[i+1:]...) 24 | i-- 25 | } 26 | } 27 | return slice 28 | } 29 | 30 | // SameItem returns a function to check if the item is same to 31 | func SameItem(target string) func(item string) bool { 32 | return func(item string) bool { 33 | return target == item 34 | } 35 | } 36 | 37 | // HasString checks if there is a same string existing in a slice 38 | func HasString(slice []string, str string) bool { 39 | for _, s := range slice { 40 | if s == str { 41 | return true 42 | } 43 | } 44 | return false 45 | } 46 | 47 | // AddToSlice adds an item to a slice without duplicated 48 | func AddToSlice(item string, array []string) []string { 49 | if !HasString(array, item) { 50 | array = append(array, item) 51 | } 52 | return array 53 | } 54 | -------------------------------------------------------------------------------- /pkg/utils/stringutils/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package stringutils 18 | 19 | import "fmt" 20 | 21 | // ErrorOverride appends a message if the error is not nil 22 | func ErrorOverride(err error, format string, a ...interface{}) error { 23 | if err != nil { 24 | err = fmt.Errorf(format, a...) 25 | } 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /pkg/utils/stringutils/error_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package stringutils 18 | 19 | import ( 20 | "github.com/kubesphere/ks-devops/pkg/server/errors" 21 | "testing" 22 | ) 23 | 24 | func TestErrorOverride(t *testing.T) { 25 | type args struct { 26 | err error 27 | format string 28 | a []interface{} 29 | } 30 | tests := []struct { 31 | name string 32 | args args 33 | wantErr bool 34 | }{{ 35 | name: "error is nil", 36 | args: args{ 37 | err: nil, 38 | }, 39 | wantErr: false, 40 | }, { 41 | name: "error is not nil", 42 | args: args{ 43 | err: errors.New("an error"), 44 | format: "msg", 45 | }, 46 | wantErr: true, 47 | }} 48 | for _, tt := range tests { 49 | t.Run(tt.name, func(t *testing.T) { 50 | if err := ErrorOverride(tt.args.err, tt.args.format, tt.args.a...); (err != nil) != tt.wantErr { 51 | t.Errorf("ErrorOverride() error = %v, wantErr %v", err, tt.wantErr) 52 | } 53 | }) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pkg/utils/stringutils/string.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2022 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package stringutils 18 | 19 | import ( 20 | "unicode/utf8" 21 | ) 22 | 23 | // Reverse makes the string reversed 24 | func Reverse(s string) string { 25 | size := len(s) 26 | buf := make([]byte, size) 27 | for start := 0; start < size; { 28 | r, n := utf8.DecodeRuneInString(s[start:]) 29 | start += n 30 | utf8.EncodeRune(buf[size-start:], r) 31 | } 32 | return string(buf) 33 | } 34 | 35 | // SetOrDefault uses a default value or the original 36 | func SetOrDefault(val string, defVal string) string { 37 | if val == "" { 38 | return defVal 39 | } 40 | return val 41 | } 42 | -------------------------------------------------------------------------------- /test/api/README.md: -------------------------------------------------------------------------------- 1 | Please run the following command to start the API testing in the current directory. 2 | 3 | ```shell 4 | atest run -p '*.yaml' 5 | ``` -------------------------------------------------------------------------------- /test/api/data/devops_v1alpha3_steptemplate.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: devops.kubesphere.io/v1alpha3 2 | kind: ClusterStepTemplate 3 | metadata: 4 | name: steptemplate-sample 5 | spec: 6 | runtime: shell 7 | template: | 8 | echo 1 9 | -------------------------------------------------------------------------------- /test/api/testcase-1.yaml: -------------------------------------------------------------------------------- 1 | name: 'get all templates' 2 | prepare: 3 | kubernetes: 4 | - data/devops_v1alpha3_steptemplate.yaml 5 | 6 | request: 7 | method: GET 8 | api: http://localhost:9090/v1alpha3/clustersteptemplates 9 | 10 | expect: 11 | statusCode: 200 12 | content-type: application/json 13 | 14 | clean: 15 | cleanPrepare: true 16 | -------------------------------------------------------------------------------- /test/api/testcase-2.yaml: -------------------------------------------------------------------------------- 1 | name: 'get a particular template' 2 | 3 | prepare: 4 | kubernetes: 5 | - data/devops_v1alpha3_steptemplate.yaml 6 | 7 | request: 8 | method: GET 9 | api: http://localhost:9090/v1alpha3/clustersteptemplates/steptemplate-sample 10 | 11 | expect: 12 | statusCode: 200 13 | content-type: application/json 14 | 15 | clean: 16 | cleanPrepare: true 17 | -------------------------------------------------------------------------------- /test/api/testcase-render.yaml: -------------------------------------------------------------------------------- 1 | name: render 2 | 3 | prepare: 4 | kubernetes: 5 | - data/devops_v1alpha3_steptemplate.yaml 6 | 7 | request: 8 | method: GET 9 | api: http://localhost:9090/v1alpha3/clustersteptemplates/steptemplate-sample/render 10 | 11 | expect: 12 | statusCode: 200 13 | content-type: application/json 14 | body: | 15 | { 16 | "data": "sh '''\necho 1\n\n'''" 17 | } 18 | 19 | clean: 20 | cleanPrepare: true 21 | -------------------------------------------------------------------------------- /test/e2e/cases/chart-install/e2e.yaml: -------------------------------------------------------------------------------- 1 | setup: 2 | env: kind 3 | file: ../../common/kind-$K8S_VERSION.yaml 4 | timeout: 60m 5 | steps: 6 | - name: Install ks-devops via helm chart 7 | command: | 8 | helm repo add ks-devops https://kubesphere-sigs.github.io/ks-devops-helm-chart/ 9 | helm repo update 10 | helm install devops ks-devops/ks-devops -n kubesphere-devops-system --create-namespace \ 11 | --set jenkins.ksAuth.enabled=true \ 12 | --set image.pullPolicy=Never \ 13 | --set image.registry=kubespheredev \ 14 | --set image.controller.tag=e2e \ 15 | --set image.apiserver.tag=e2e \ 16 | --set image.tools.tag=e2e 17 | wait: 18 | - namespace: kubesphere-devops-system 19 | resource: deployment 20 | for: condition=Available 21 | - namespace: kubesphere-devops-system 22 | resource: pod/s2ioperator-0 23 | for: condition=Ready 24 | kind: 25 | import-images: 26 | - kubespheredev/devops-controller:e2e 27 | - kubespheredev/devops-apiserver:e2e 28 | - kubespheredev/devops-tools:e2e 29 | expose-ports: 30 | - namespace: kubesphere-devops-system 31 | resource: deployment/devops-apiserver 32 | port: 9090 33 | 34 | verify: 35 | retry: 36 | count: 60 37 | interval: 1s 38 | cases: 39 | - query: "kubectl get pod -n kubesphere-devops-system -o yaml | yq e '{.items[].metadata.name: .items[].status.phase}' -" 40 | expected: ./expected.yaml 41 | -------------------------------------------------------------------------------- /test/e2e/cases/chart-install/expected.yaml: -------------------------------------------------------------------------------- 1 | {{ range $name, $phase := . }} 2 | {{ if or (eq $phase "Running") (eq $phase "Succeeded") }} 3 | {{ $name }}: {{ $phase }} 4 | {{ end }} 5 | {{ end }} 6 | -------------------------------------------------------------------------------- /test/e2e/common/kind-1.19.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | # patch the generated kubeadm config with some extra settings 4 | kubeadmConfigPatches: 5 | - | 6 | apiVersion: kubelet.config.k8s.io/v1beta1 7 | kind: KubeletConfiguration 8 | evictionHard: 9 | nodefs.available: "0%" 10 | # patch it further using a JSON 6902 patch 11 | kubeadmConfigPatchesJSON6902: 12 | - group: kubeadm.k8s.io 13 | version: v1beta2 14 | kind: ClusterConfiguration 15 | patch: | 16 | - op: add 17 | path: /apiServer/certSANs/- 18 | value: ks-devops-e2e 19 | # 1 control plane node and 1 workers 20 | nodes: 21 | # the control plane node config 22 | - role: control-plane 23 | image: kindest/node:v1.19.11 24 | # the one worker 25 | - role: worker 26 | image: kindest/node:v1.19.11 27 | -------------------------------------------------------------------------------- /test/e2e/common/kind-1.20.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | # patch the generated kubeadm config with some extra settings 4 | kubeadmConfigPatches: 5 | - | 6 | apiVersion: kubelet.config.k8s.io/v1beta1 7 | kind: KubeletConfiguration 8 | evictionHard: 9 | nodefs.available: "0%" 10 | # patch it further using a JSON 6902 patch 11 | kubeadmConfigPatchesJSON6902: 12 | - group: kubeadm.k8s.io 13 | version: v1beta2 14 | kind: ClusterConfiguration 15 | patch: | 16 | - op: add 17 | path: /apiServer/certSANs/- 18 | value: ks-devops-e2e 19 | # 1 control plane node and 1 workers 20 | nodes: 21 | # the control plane node config 22 | - role: control-plane 23 | image: kindest/node:v1.20.7 24 | # the one worker 25 | - role: worker 26 | image: kindest/node:v1.20.7 27 | -------------------------------------------------------------------------------- /test/e2e/common/kind-1.21.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | # patch the generated kubeadm config with some extra settings 4 | kubeadmConfigPatches: 5 | - | 6 | apiVersion: kubelet.config.k8s.io/v1beta1 7 | kind: KubeletConfiguration 8 | evictionHard: 9 | nodefs.available: "0%" 10 | # patch it further using a JSON 6902 patch 11 | kubeadmConfigPatchesJSON6902: 12 | - group: kubeadm.k8s.io 13 | version: v1beta2 14 | kind: ClusterConfiguration 15 | patch: | 16 | - op: add 17 | path: /apiServer/certSANs/- 18 | value: ks-devops-e2e 19 | # 1 control plane node and 1 workers 20 | nodes: 21 | # the control plane node config 22 | - role: control-plane 23 | image: kindest/node:v1.21.2 24 | # the one worker 25 | - role: worker 26 | image: kindest/node:v1.21.2 27 | -------------------------------------------------------------------------------- /test/e2e/common/kind-1.22.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | # patch the generated kubeadm config with some extra settings 4 | kubeadmConfigPatches: 5 | - | 6 | apiVersion: kubelet.config.k8s.io/v1beta1 7 | kind: KubeletConfiguration 8 | evictionHard: 9 | nodefs.available: "0%" 10 | # patch it further using a JSON 6902 patch 11 | kubeadmConfigPatchesJSON6902: 12 | - group: kubeadm.k8s.io 13 | version: v1beta2 14 | kind: ClusterConfiguration 15 | patch: | 16 | - op: add 17 | path: /apiServer/certSANs/- 18 | value: ks-devops-e2e 19 | # 1 control plane node and 1 workers 20 | nodes: 21 | # the control plane node config 22 | - role: control-plane 23 | image: kindest/node:v1.22.2 24 | # the one worker 25 | - role: worker 26 | image: kindest/node:v1.22.2 27 | -------------------------------------------------------------------------------- /test/e2e/common/kind-1.23.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | # patch the generated kubeadm config with some extra settings 4 | kubeadmConfigPatches: 5 | - | 6 | apiVersion: kubelet.config.k8s.io/v1beta1 7 | kind: KubeletConfiguration 8 | evictionHard: 9 | nodefs.available: "0%" 10 | # patch it further using a JSON 6902 patch 11 | kubeadmConfigPatchesJSON6902: 12 | - group: kubeadm.k8s.io 13 | version: v1beta2 14 | kind: ClusterConfiguration 15 | patch: | 16 | - op: add 17 | path: /apiServer/certSANs/- 18 | value: ks-devops-e2e 19 | # 1 control plane node and 1 workers 20 | nodes: 21 | # the control plane node config 22 | - role: control-plane 23 | image: kindest/node:v1.23.12 24 | # the one worker 25 | - role: worker 26 | image: kindest/node:v1.23.12 27 | --------------------------------------------------------------------------------