├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── enhancement.md │ ├── failing-test.md │ └── support.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── build-and-test.yml │ └── test-and-push.yml ├── .gitignore ├── .golangci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── OWNERS ├── PROJECT ├── README.md ├── README_ARCHIVED.md ├── SECURITY_CONTACTS ├── charts ├── index.yaml └── kubefed │ ├── .gitignore │ ├── .helmignore │ ├── Chart.yaml │ ├── LICENSE │ ├── README.md │ ├── charts │ └── controllermanager │ │ ├── Chart.yaml │ │ ├── crds │ │ └── crds.yaml │ │ └── templates │ │ ├── _helpers.tpl │ │ ├── aggregate_clusterroles.yaml │ │ ├── clusterrole.yaml │ │ ├── clusterrolebindings.yaml │ │ ├── deployments.yaml │ │ ├── kubefedconfig.yaml │ │ ├── post-install-job.yaml │ │ ├── rolebindings.yaml │ │ ├── roles.yaml │ │ ├── service.yaml │ │ ├── serviceaccounts.yaml │ │ └── webhook.yaml │ ├── crds │ └── crds.yaml │ ├── templates │ ├── _helpers.tpl │ └── federatedtypeconfig.yaml │ └── values.yaml ├── cmd ├── controller-manager │ ├── app │ │ ├── controller-manager.go │ │ ├── leaderelection │ │ │ └── leaderelection.go │ │ └── options │ │ │ └── options.go │ └── main.go ├── hyperfed │ └── main.go ├── kubefedctl │ └── main.go └── webhook │ ├── app │ └── webhook.go │ └── main.go ├── code-of-conduct.md ├── config ├── enabletypedirectives │ ├── clusterroles.rbac.authorization.k8s.io.yaml │ ├── configmaps.yaml │ ├── deployments.apps.yaml │ ├── ingresses.networking.k8s.io.yaml │ ├── jobs.batch.yaml │ ├── namespaces.yaml │ ├── replicasets.apps.yaml │ ├── secrets.yaml │ ├── serviceaccounts.yaml │ └── services.yaml └── kubefedconfig.yaml ├── docs ├── OWNERS ├── cluster-registration.md ├── concepts.md ├── development.md ├── environments │ ├── gke.md │ ├── icp.md │ ├── kind.md │ └── minikube.md ├── images │ ├── concepts.png │ ├── ingressdns-with-externaldns.png │ ├── propagation.png │ └── servicedns-with-externaldns.png ├── installation.md ├── keps │ ├── 20200302-kubefed-metrics.md │ ├── 20200619-federated-resource-status.md │ ├── 20200619-kubefed-pull-reconciliation.md │ └── images │ │ ├── kubefedArch.jpg │ │ ├── kubefedv2Example.jpg │ │ └── kubefedv2_seconditeration.jpg ├── releasing.md └── userguide.md ├── example ├── config │ └── kubefedconfig.yaml ├── sample1 │ ├── configmap.yaml │ ├── deployment.yaml │ ├── federatedclusterrole.yaml │ ├── federatedclusterrolebinding.yaml │ ├── federatedconfigmap.yaml │ ├── federateddeployment.yaml │ ├── federatedingress.yaml │ ├── federatedjob.yaml │ ├── federatednamespace.yaml │ ├── federatedsecret.yaml │ ├── federatedservice.yaml │ ├── federatedserviceaccount.yaml │ ├── namespace.yaml │ └── service.yaml └── scheduling │ └── federateddeployment-rsp.yaml ├── go.mod ├── go.sum ├── hack ├── boilerplate.go.txt ├── doc.go ├── verify-docfiles.sh ├── verify-errpkg.sh └── verify-klog.sh ├── images └── kubefed │ └── Dockerfile ├── pkg ├── apis │ ├── addtoscheme_core_v1alpha1.go │ ├── addtoscheme_core_v1beta1.go │ ├── addtoscheme_scheduling_v1alpha1.go │ ├── apis.go │ ├── core │ │ ├── common │ │ │ ├── constants.go │ │ │ └── util.go │ │ ├── group.go │ │ ├── typeconfig │ │ │ ├── interface.go │ │ │ └── util.go │ │ ├── v1alpha1 │ │ │ ├── clusterpropagatedversion_types.go │ │ │ ├── federatedservicestatus_types.go │ │ │ ├── groupversion_info.go │ │ │ ├── propagatedversion_types.go │ │ │ └── zz_generated.deepcopy.go │ │ └── v1beta1 │ │ │ ├── defaults │ │ │ ├── defaults.go │ │ │ └── defaults_test.go │ │ │ ├── federatedtypeconfig_types.go │ │ │ ├── groupversion_info.go │ │ │ ├── kubefedcluster_types.go │ │ │ ├── kubefedcluster_types_test.go │ │ │ ├── kubefedconfig_types.go │ │ │ ├── suite_test.go │ │ │ ├── validation │ │ │ ├── validation.go │ │ │ └── validation_test.go │ │ │ └── zz_generated.deepcopy.go │ └── scheduling │ │ ├── group.go │ │ └── v1alpha1 │ │ ├── groupversion_info.go │ │ ├── replicaschedulingpreference_types.go │ │ └── zz_generated.deepcopy.go ├── client │ └── generic │ │ ├── genericclient.go │ │ └── scheme │ │ └── register.go ├── controller │ ├── doc.go │ ├── federatedtypeconfig │ │ └── controller.go │ ├── kubefedcluster │ │ ├── clusterclient.go │ │ ├── controller.go │ │ ├── controller_integration_test.go │ │ └── controller_test.go │ ├── schedulingmanager │ │ └── controller.go │ ├── schedulingpreference │ │ └── controller.go │ ├── status │ │ └── controller.go │ ├── sync │ │ ├── accessor.go │ │ ├── controller.go │ │ ├── dispatch │ │ │ ├── checkunmanaged.go │ │ │ ├── managed.go │ │ │ ├── operation.go │ │ │ ├── retain.go │ │ │ ├── retain_test.go │ │ │ └── unmanaged.go │ │ ├── resource.go │ │ ├── resource_test.go │ │ ├── status │ │ │ ├── status.go │ │ │ └── status_test.go │ │ └── version │ │ │ ├── adapter.go │ │ │ ├── cluster.go │ │ │ ├── manager.go │ │ │ └── namespaced.go │ ├── testdata │ │ └── fixtures │ │ │ └── crds.yaml │ ├── util │ │ ├── backoff.go │ │ ├── cluster_util.go │ │ ├── constants.go │ │ ├── controllerconfig.go │ │ ├── delaying_deliverer.go │ │ ├── delaying_deliverer_test.go │ │ ├── deletionannotation.go │ │ ├── deletionannotation_test.go │ │ ├── federated_informer.go │ │ ├── federatedstatus.go │ │ ├── finalizers │ │ │ ├── finalizers.go │ │ │ └── finalizers_test.go │ │ ├── genericinformer.go │ │ ├── handlers.go │ │ ├── handlers_test.go │ │ ├── managedlabel.go │ │ ├── meta.go │ │ ├── meta_test.go │ │ ├── naming.go │ │ ├── orphaninganotation.go │ │ ├── overrides.go │ │ ├── placement.go │ │ ├── placement_test.go │ │ ├── planner │ │ │ ├── planner.go │ │ │ └── planner_test.go │ │ ├── podanalyzer │ │ │ ├── pod_helper.go │ │ │ └── pod_helper_test.go │ │ ├── propagatedversion.go │ │ ├── qualifiedname.go │ │ ├── resourceclient.go │ │ ├── resourceinformer.go │ │ ├── safe_map.go │ │ ├── worker.go │ │ └── worker_test.go │ └── webhook │ │ ├── federatedtypeconfig │ │ └── webhook.go │ │ ├── kubefedcluster │ │ └── webhook.go │ │ ├── kubefedconfig │ │ └── webhook.go │ │ └── util.go ├── doc.go ├── features │ └── features.go ├── kubefedctl │ ├── disable.go │ ├── enable │ │ ├── deprecatedapis.go │ │ ├── deprecatedapis_test.go │ │ ├── directive.go │ │ ├── enable.go │ │ ├── schema.go │ │ ├── util.go │ │ └── validation.go │ ├── federate │ │ ├── federate.go │ │ ├── federate_test.go │ │ └── util.go │ ├── join.go │ ├── join_test.go │ ├── kubefedctl.go │ ├── options │ │ └── options.go │ ├── orphaning │ │ ├── disable.go │ │ ├── enable.go │ │ ├── orphaning.go │ │ └── status.go │ ├── suite_test.go │ ├── unjoin.go │ ├── util │ │ ├── util.go │ │ └── yaml_writer.go │ └── version.go ├── metrics │ └── metrics.go ├── schedulingtypes │ ├── interface.go │ ├── plugin.go │ ├── plugin_test.go │ ├── replicascheduler.go │ ├── resources.go │ └── typeregistry.go └── version │ ├── base.go │ └── version.go ├── scripts ├── build-release-artifacts.sh ├── build-release.sh ├── check-directive-fixtures.sh ├── create-clusters.sh ├── create-gh-release.sh ├── delete-clusters.sh ├── delete-kubefed.sh ├── deploy-federated-nginx.sh ├── deploy-kubefed-latest.sh ├── deploy-kubefed.sh ├── download-binaries.sh ├── download-e2e-binaries.sh ├── fix-ca-for-k3s.sh ├── fix-joined-kind-clusters.sh ├── pre-commit.sh ├── sync-up-helm-chart.sh ├── update-bindata.sh └── util.sh ├── staticcheck.conf ├── test ├── common │ ├── bindata.go │ ├── crudtester.go │ ├── fixtures.go │ ├── fixtures │ │ ├── clusterroles.rbac.authorization.k8s.io.yaml │ │ ├── configmaps.yaml │ │ ├── deployments.apps.yaml │ │ ├── ingresses.networking.k8s.io.yaml │ │ ├── jobs.batch.yaml │ │ ├── namespaces.yaml │ │ ├── replicasets.apps.yaml │ │ ├── secrets.yaml │ │ ├── serviceaccounts.yaml │ │ └── services.yaml │ ├── resource_helper.go │ ├── testobjects.go │ ├── typeconfig.go │ ├── util.go │ └── validation.go └── e2e │ ├── crd.go │ ├── crud.go │ ├── defaulting.go │ ├── deleteoptions.go │ ├── e2e.go │ ├── e2e_test.go │ ├── federate.go │ ├── framework │ ├── cleanup.go │ ├── cluster.go │ ├── controller.go │ ├── enable.go │ ├── framework.go │ ├── ginkgowrapper │ │ └── wrapper.go │ ├── logger.go │ ├── test_context.go │ ├── unmanaged.go │ ├── util.go │ └── wait.go │ ├── ftccontroller.go │ ├── kubefedcluster.go │ ├── leaderelection.go │ ├── not_ready.go │ ├── placement.go │ ├── scale.go │ ├── schedulermanager.go │ ├── scheduling.go │ ├── validation.go │ └── version.go ├── third-party └── k8s.io │ └── repo-infra │ ├── .bazelignore │ ├── .bazelrc │ ├── .bazelversion │ ├── .gitignore │ ├── .golangci.yml │ ├── .kazelcfg.json │ ├── BUILD.bazel │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── OWNERS │ ├── README.md │ ├── SECURITY.md │ ├── SECURITY_CONTACTS │ ├── WORKSPACE │ ├── cmd │ └── kazel │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── config.go │ │ ├── diff.go │ │ ├── generator.go │ │ ├── generator_test.go │ │ ├── kazel.go │ │ ├── kazel_test.go │ │ └── sourcerer.go │ ├── code-of-conduct.md │ ├── defs │ ├── BUILD.bazel │ ├── build.bzl │ ├── deb.bzl │ ├── diff_test.sh │ ├── gcs_uploader.py │ ├── go.bzl │ ├── pkg.bzl │ ├── rpm.bzl │ ├── run_in_workspace.bzl │ ├── testdata │ │ ├── testfile.txt │ │ ├── testfile.txt.md5.expected │ │ ├── testfile.txt.sha1.expected │ │ └── testfile.txt.sha512.expected │ ├── testgen │ │ ├── BUILD.bazel │ │ └── main.go │ └── testpkg │ │ ├── BUILD.bazel │ │ └── pkg.go │ ├── go.mod │ ├── go.sum │ ├── go │ ├── BUILD.bazel │ └── sdk_versions.bzl │ ├── hack │ ├── BUILD.bazel │ ├── tools.go │ ├── update-bazel.sh │ ├── update-deps.sh │ ├── update-gofmt.sh │ ├── verify-bazel.sh │ ├── verify-deps.sh │ ├── verify-gofmt.sh │ ├── verify-golangci-lint.sh │ ├── verify_boilerplate.py │ └── verify_boilerplate_test.py │ ├── load.bzl │ ├── presubmit.sh │ ├── repos.bzl │ ├── tools │ ├── CROSSTOOL │ └── build_tar │ │ ├── BUILD.bazel │ │ └── buildtar.go │ └── verify │ ├── BUILD.bazel │ ├── README.md │ ├── boilerplate │ ├── BUILD.bazel │ ├── boilerplate.Dockerfile.txt │ ├── boilerplate.Makefile.txt │ ├── boilerplate.bzl.txt │ ├── boilerplate.go.txt │ ├── boilerplate.py.txt │ ├── boilerplate.sh.txt │ └── test │ │ ├── fail.go │ │ ├── fail.py │ │ ├── pass.go │ │ └── pass.py │ ├── go_install_from_commit.sh │ ├── verify-bazel.sh │ ├── verify-boilerplate.sh │ ├── verify-errexit.sh │ └── verify-go-src.sh └── tools ├── go.mod ├── go.sum └── tools.go /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug encountered while operating KubeFed 4 | 5 | --- 6 | 7 | 8 | 9 | 10 | **What happened**: 11 | 12 | **What you expected to happen**: 13 | 14 | **How to reproduce it (as minimally and precisely as possible)**: 15 | 16 | **Anything else we need to know?**: 17 | 18 | **Environment**: 19 | - Kubernetes version (use `kubectl version`) 20 | - KubeFed version 21 | - Scope of installation (namespaced or cluster) 22 | - Others 23 | 24 | 25 | /kind bug -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement Request 3 | about: Suggest an enhancement to the KubeFed project 4 | 5 | --- 6 | 7 | 8 | **What would you like to be added**: 9 | 10 | **Why is this needed**: 11 | 12 | 13 | /kind feature 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/failing-test.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Failing Test 3 | about: Report test failures in KubeFed CI jobs 4 | 5 | --- 6 | 7 | 8 | 9 | **Which test(s) are failing**: 10 | 11 | **Since when has it been failing**: 12 | 13 | **Reason for failure**: 14 | 15 | **Anything else we need to know**: 16 | 17 | 18 | /kind failing-test 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support Request 3 | about: Support request or question relating to KubeFed 4 | 5 | --- 6 | 7 | 15 | 16 | 17 | 18 | /triage support 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | **What this PR does / why we need it**: 9 | 10 | **Which issue(s) this PR fixes** *(optional, in `fixes #(, fixes #, ...)` format, will close the issue(s) when PR gets merged)*: 11 | Fixes # 12 | 13 | **Special notes for your reviewer**: 14 | -------------------------------------------------------------------------------- /.github/workflows/build-and-test.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build-and-test: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | 12 | - uses: actions/setup-go@v2 13 | with: 14 | go-version: '~1.16' 15 | 16 | - name: Run tests 17 | run: | 18 | ./hack/verify-docfiles.sh && echo "Skipping build - only doc files have changed!" || \ 19 | DOWNLOAD_BINARIES=y bash -x ./scripts/pre-commit.sh 20 | -------------------------------------------------------------------------------- /.github/workflows/test-and-push.yml: -------------------------------------------------------------------------------- 1 | name: Test and Push 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | branches: 8 | - "master" 9 | 10 | jobs: 11 | push: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - uses: actions/setup-go@v2 18 | with: 19 | go-version: '~1.16' 20 | 21 | - name: Run tests 22 | run: DOWNLOAD_BINARIES=y bash -x ./scripts/pre-commit.sh 23 | 24 | - name: Login to quay.io 25 | uses: docker/login-action@v1 26 | with: 27 | registry: quay.io 28 | username: ${{ secrets.QUAY_USERNAME }} 29 | password: ${{ secrets.QUAY_ROBOT_TOKEN }} 30 | 31 | - name: Push Docker images 32 | run: make push 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /apiserver.local.config 2 | /bin 3 | /default.etcd 4 | /kubeconfig 5 | /config/crds/ 6 | # Ignore binaries built by the makefile to avoid accidentally committing them 7 | /images/kubefed/hyperfed 8 | /images/kubefed/controller-manager 9 | 10 | # editor and IDE paraphernalia 11 | .idea 12 | .vscode 13 | 14 | # macOS paraphernalia 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | timeout: 5m 3 | skip-dirs: 4 | - third-party 5 | 6 | linters: 7 | disable-all: true 8 | enable: 9 | - deadcode 10 | - errcheck 11 | - goconst 12 | - gocritic 13 | - goimports 14 | - gosimple 15 | - govet 16 | - ineffassign 17 | - nolintlint 18 | - prealloc 19 | - staticcheck 20 | - structcheck 21 | - stylecheck 22 | - typecheck 23 | - unparam 24 | - unused 25 | - varcheck 26 | - whitespace 27 | 28 | linters-settings: 29 | goimports: 30 | local-prefixes: sigs.k8s.io/kubefed 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing Guidelines 2 | This repo contains an alpha release of some of the foundational aspects of Kubernetes Cluster Federation. All the contribution is done via GitHub. Please also read the contributors guide: https://github.com/kubernetes/community/blob/master/contributors/guide/README.md 3 | 4 | ## Sign the CLA 5 | Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests. Please see https://github.com/kubernetes/community/blob/master/CLA.md for more information 6 | 7 | ## Learn About Kubernetes Cluster Federation 8 | If you want to learn about KubeFed, please read through the doc: 9 | https://github.com/kubernetes-sigs/kubefed#kubernetes-cluster-federation 10 | 11 | To learn how to use Kubernetes Cluster Federation, please read through the User Guide: 12 | https://github.com/kubernetes-sigs/kubefed/blob/master/docs/userguide.md 13 | 14 | If you are interested in contributing to Kubernetes Cluster Federation, please read through the Development Guide: 15 | https://github.com/kubernetes-sigs/kubefed/blob/master/docs/development.md 16 | 17 | 18 | ## Submitting a Pull Request (PR) 19 | 1. Sign the CLA. 20 | 2. Submit an issue by describing your proposed change to the repo in question. 21 | 3. The repo owners will respond to your issue rapidly. 22 | 4. Fork the repo, make your changes and test it. 23 | 5. Submit a PR. 24 | 25 | ## Code reviews 26 | All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. 27 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | reviewers: 2 | - jimmidyson 3 | - font 4 | - gyliu513 5 | - irfanurrehman 6 | - pmorie 7 | - xunpan 8 | - hectorj2f 9 | - makkes 10 | approvers: 11 | - jimmidyson 12 | - font 13 | - irfanurrehman 14 | - pmorie 15 | - xunpan 16 | - hectorj2f 17 | -------------------------------------------------------------------------------- /PROJECT: -------------------------------------------------------------------------------- 1 | version: "1" 2 | domain: kubefed.io 3 | repo: sigs.k8s.io/kubefed 4 | multigroup: true 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Cluster Federation (archived) 2 | 3 | This repository has been archived and is no longer active development. Please 4 | see the [current subprojects](https://github.com/kubernetes/community/tree/master/sig-multicluster#subprojects) 5 | of SIG Multicluster to track ongoing work. 6 | 7 | See [this discussion](https://groups.google.com/g/kubernetes-sig-multicluster/c/lciAVj-_ShE) for context. -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Team to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | font 14 | marun 15 | -------------------------------------------------------------------------------- /charts/kubefed/.gitignore: -------------------------------------------------------------------------------- 1 | requirements.lock 2 | -------------------------------------------------------------------------------- /charts/kubefed/.helmignore: -------------------------------------------------------------------------------- 1 | # Ignore common backup files 2 | *.swp 3 | *~ 4 | -------------------------------------------------------------------------------- /charts/kubefed/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | description: KubeFed helm chart 3 | name: kubefed 4 | version: 0.0.6 5 | kubeVersion: ">= 1.16.0-0" 6 | dependencies: 7 | - name: controllermanager 8 | version: 0.0.6 9 | repository: "https://localhost/" # Required but unused. 10 | condition: controllermanager.enabled 11 | 12 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | appVersion: "0.8.1" 3 | description: A Helm chart for KubeFed Controller Manager 4 | name: controllermanager 5 | version: 0.0.6 6 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "controllermanager.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "controllermanager.fullname" -}} 15 | {{- if .Values.fullnameOverride -}} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 17 | {{- else -}} 18 | {{- $name := default .Chart.Name .Values.nameOverride -}} 19 | {{- if contains $name .Release.Name -}} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 21 | {{- else -}} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 23 | {{- end -}} 24 | {{- end -}} 25 | {{- end -}} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "controllermanager.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/kubefedconfig.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: KubeFedConfig 3 | metadata: 4 | name: kubefed 5 | namespace: {{ .Release.Namespace }} 6 | spec: 7 | scope: {{ .Values.global.scope | default "Cluster" | quote }} 8 | controllerDuration: 9 | availableDelay: {{ .Values.clusterAvailableDelay | default "20s" | quote }} 10 | unavailableDelay: {{ .Values.clusterUnavailableDelay | default "60s" | quote }} 11 | cacheSyncTimeout: {{ .Values.cacheSyncTimeout | default "5m" | quote }} 12 | leaderElect: 13 | leaseDuration: {{ .Values.leaderElectLeaseDuration | default "15s" | quote }} 14 | renewDeadline: {{ .Values.leaderElectRenewDeadline | default "10s" | quote }} 15 | retryPeriod: {{ .Values.leaderElectRetryPeriod | default "5s" | quote }} 16 | resourceLock: {{ .Values.leaderElectResourceLock | default "configmaps" | quote }} 17 | clusterHealthCheck: 18 | period: {{ .Values.clusterHealthCheckPeriod | default "10s" | quote }} 19 | failureThreshold: {{ .Values.clusterHealthCheckFailureThreshold | default 3 }} 20 | successThreshold: {{ .Values.clusterHealthCheckSuccessThreshold | default 1 }} 21 | timeout: {{ .Values.clusterHealthCheckTimeout | default "3s" | quote }} 22 | syncController: 23 | maxConcurrentReconciles: {{ .Values.syncController.maxConcurrentReconciles | default 1 }} 24 | adoptResources: {{ .Values.syncController.adoptResources | default "Enabled" | quote }} 25 | statusController: 26 | maxConcurrentReconciles: {{ .Values.statusController.maxConcurrentReconciles | default 1 }} 27 | featureGates: 28 | {{- if .Values.featureGates }} 29 | - name: PushReconciler 30 | configuration: {{ .Values.featureGates.PushReconciler | default "Enabled" | quote }} 31 | - name: SchedulerPreferences 32 | configuration: {{ .Values.featureGates.SchedulerPreferences | default "Enabled" | quote }} 33 | # NOTE: Commented feature gate to fix https://github.com/kubernetes-sigs/kubefed/issues/1333 34 | #- name: RawResourceStatusCollection 35 | # configuration: {{ .Values.featureGates.RawResourceStatusCollection | default "Disabled" | quote }} 36 | {{- end }} 37 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/rolebindings.yaml: -------------------------------------------------------------------------------- 1 | {{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }} 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: RoleBinding 4 | metadata: 5 | name: kubefed-rolebinding 6 | namespace: {{ .Release.Namespace }} 7 | roleRef: 8 | apiGroup: rbac.authorization.k8s.io 9 | kind: Role 10 | name: kubefed-role 11 | subjects: 12 | - kind: ServiceAccount 13 | name: kubefed-controller 14 | namespace: {{ .Release.Namespace }} 15 | {{- end }} 16 | --- 17 | apiVersion: rbac.authorization.k8s.io/v1 18 | kind: RoleBinding 19 | metadata: 20 | name: kubefed-config-rolebinding 21 | namespace: {{ .Release.Namespace }} 22 | roleRef: 23 | apiGroup: rbac.authorization.k8s.io 24 | kind: Role 25 | name: kubefed-config-role 26 | subjects: 27 | - kind: ServiceAccount 28 | name: kubefed-controller 29 | namespace: {{ .Release.Namespace }} 30 | --- 31 | # Grant admission webhook access to core.kubefed.io in the KubeFed system 32 | # namespace only, regardless of kubefed deployment scope. 33 | apiVersion: rbac.authorization.k8s.io/v1 34 | kind: RoleBinding 35 | metadata: 36 | name: kubefed-admission-webhook-rolebinding 37 | namespace: {{ .Release.Namespace }} 38 | roleRef: 39 | apiGroup: rbac.authorization.k8s.io 40 | kind: Role 41 | name: kubefed-admission-webhook-role 42 | subjects: 43 | - kind: ServiceAccount 44 | name: kubefed-admission-webhook 45 | namespace: {{ .Release.Namespace }} 46 | --- 47 | # Allow the admission webhook to read the config for terminating 48 | # authentication. 49 | apiVersion: rbac.authorization.k8s.io/v1 50 | kind: RoleBinding 51 | metadata: 52 | # TODO(font) For namespace scoped deployments, create a unique resource name in 53 | # the kube-system namespace using the namespace. This is needed because 54 | # admission-webhooks do not currently support the ability to have 55 | # namespace-scoped RBAC permissions only. 56 | {{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }} 57 | name: kubefed-admission-webhook:{{ .Release.Namespace }}:apiextension-viewer 58 | {{ else }} 59 | name: kubefed-admission-webhook:apiextension-viewer 60 | {{ end }} 61 | namespace: kube-system 62 | roleRef: 63 | apiGroup: rbac.authorization.k8s.io 64 | kind: Role 65 | name: extension-apiserver-authentication-reader 66 | subjects: 67 | - kind: ServiceAccount 68 | name: kubefed-admission-webhook 69 | namespace: {{ .Release.Namespace }} 70 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/roles.yaml: -------------------------------------------------------------------------------- 1 | {{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }} 2 | --- 3 | apiVersion: rbac.authorization.k8s.io/v1 4 | kind: Role 5 | metadata: 6 | labels: 7 | api: kubefed 8 | kubebuilder.k8s.io: 1.0.0 9 | name: kubefed-role 10 | namespace: {{ .Release.Namespace }} 11 | rules: 12 | - apiGroups: 13 | - scheduling.kubefed.io 14 | resources: 15 | - '*' 16 | verbs: 17 | - get 18 | - watch 19 | - list 20 | - update 21 | - patch 22 | - apiGroups: 23 | - multiclusterdns.kubefed.io 24 | resources: 25 | - '*' 26 | verbs: 27 | - get 28 | - watch 29 | - list 30 | - create 31 | - update 32 | - patch 33 | - apiGroups: 34 | - core.kubefed.io 35 | resources: 36 | - '*' 37 | verbs: 38 | - get 39 | - watch 40 | - list 41 | - create 42 | - update 43 | - patch 44 | - delete 45 | - apiGroups: 46 | - types.kubefed.io 47 | resources: 48 | - '*' 49 | verbs: 50 | - get 51 | - watch 52 | - list 53 | - update 54 | - patch 55 | - apiGroups: 56 | - "" 57 | resources: 58 | - events 59 | verbs: 60 | - get 61 | - create 62 | - update 63 | - patch 64 | {{- end }} 65 | --- 66 | apiVersion: rbac.authorization.k8s.io/v1 67 | kind: Role 68 | metadata: 69 | labels: 70 | api: kubefed 71 | kubebuilder.k8s.io: 1.0.0 72 | name: kubefed-config-role 73 | namespace: {{ .Release.Namespace }} 74 | rules: 75 | - apiGroups: 76 | - "" 77 | resources: 78 | - configmaps 79 | verbs: 80 | - get 81 | - create 82 | - update 83 | - patch 84 | - apiGroups: 85 | - "" 86 | resources: 87 | - secrets 88 | verbs: 89 | - get 90 | --- 91 | # Only need access to these core namespaced resources in the KubeFed system 92 | # namespace regardless of kubefed deployment scope. 93 | apiVersion: rbac.authorization.k8s.io/v1 94 | kind: Role 95 | metadata: 96 | labels: 97 | api: kubefed 98 | kubebuilder.k8s.io: 1.0.0 99 | name: kubefed-admission-webhook-role 100 | namespace: {{ .Release.Namespace }} 101 | rules: 102 | - apiGroups: 103 | - core.kubefed.io 104 | resources: 105 | - federatedtypeconfigs 106 | - kubefedclusters 107 | - kubefedconfigs 108 | verbs: 109 | - get 110 | - watch 111 | - list 112 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: kubefed-admission-webhook 5 | namespace: {{ .Release.Namespace }} 6 | {{- if .Values.service.labels }} 7 | labels: 8 | {{ toYaml .Values.service.labels | indent 4 }} 9 | {{- end }} 10 | spec: 11 | selector: 12 | kubefed-admission-webhook: "true" 13 | ports: 14 | - port: 443 15 | targetPort: 8443 16 | --- 17 | apiVersion: v1 18 | kind: Service 19 | metadata: 20 | name: kubefed-controller-manager-metrics-service 21 | namespace: {{ .Release.Namespace }} 22 | {{- if .Values.service.labels }} 23 | labels: 24 | {{ toYaml .Values.service.labels | indent 4 }} 25 | {{- end }} 26 | annotations: 27 | prometheus.io/port: "9090" 28 | prometheus.io/scheme: http 29 | prometheus.io/scrape: "true" 30 | spec: 31 | selector: 32 | kubefed-control-plane: "controller-manager" 33 | ports: 34 | - name: metrics 35 | port: 9090 36 | targetPort: metrics 37 | -------------------------------------------------------------------------------- /charts/kubefed/charts/controllermanager/templates/serviceaccounts.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: kubefed-controller 5 | namespace: {{ .Release.Namespace }} 6 | --- 7 | apiVersion: v1 8 | kind: ServiceAccount 9 | metadata: 10 | namespace: {{ .Release.Namespace }} 11 | name: kubefed-admission-webhook 12 | -------------------------------------------------------------------------------- /charts/kubefed/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "kubefed.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "kubefed.fullname" -}} 15 | {{- if .Values.fullnameOverride -}} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 17 | {{- else -}} 18 | {{- $name := default .Chart.Name .Values.nameOverride -}} 19 | {{- if contains $name .Release.Name -}} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 21 | {{- else -}} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 23 | {{- end -}} 24 | {{- end -}} 25 | {{- end -}} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "kubefed.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | -------------------------------------------------------------------------------- /cmd/controller-manager/app/options/options.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 contains flags and options for initializing controller-manager 18 | package options 19 | 20 | import ( 21 | "github.com/spf13/pflag" 22 | 23 | apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 24 | 25 | "sigs.k8s.io/kubefed/pkg/controller/util" 26 | ) 27 | 28 | // Options contains everything necessary to create and run controller-manager. 29 | type Options struct { 30 | Config *util.ControllerConfig 31 | FeatureGates map[string]bool 32 | Scope apiextv1.ResourceScope 33 | LeaderElection *util.LeaderElectionConfiguration 34 | ClusterHealthCheckConfig *util.ClusterHealthCheckConfig 35 | } 36 | 37 | // AddFlags adds flags to fs and binds them to options. 38 | func (o *Options) AddFlags(fs *pflag.FlagSet) { 39 | fs.StringVar(&o.Config.KubeFedNamespace, "kubefed-namespace", "", "The namespace the KubeFed control plane is deployed in.") 40 | } 41 | 42 | func NewOptions() *Options { 43 | return &Options{ 44 | Config: new(util.ControllerConfig), 45 | FeatureGates: make(map[string]bool), 46 | LeaderElection: new(util.LeaderElectionConfiguration), 47 | ClusterHealthCheckConfig: new(util.ClusterHealthCheckConfig), 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cmd/controller-manager/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | "fmt" 21 | "os" 22 | 23 | _ "sigs.k8s.io/controller-runtime/pkg/metrics" // for workqueue metrics registration 24 | 25 | genericapiserver "k8s.io/apiserver/pkg/server" 26 | _ "k8s.io/client-go/plugin/pkg/client/auth" // Load all client auth plugins for GCP, Azure, Openstack, etc 27 | "k8s.io/component-base/logs" 28 | 29 | "sigs.k8s.io/kubefed/cmd/controller-manager/app" 30 | ) 31 | 32 | // Controller-manager main. 33 | func main() { 34 | logs.InitLogs() 35 | defer logs.FlushLogs() 36 | 37 | stopChan := genericapiserver.SetupSignalHandler() 38 | 39 | if err := app.NewControllerManagerCommand(stopChan).Execute(); err != nil { 40 | fmt.Fprintf(os.Stderr, "%v\n", err) 41 | os.Exit(1) //nolint:gocritic 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cmd/kubefedctl/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | // kubefedctl is a tool for managing a KubeFed control plane. 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | _ "k8s.io/client-go/plugin/pkg/client/auth" // Load all client auth plugins for GCP, Azure, Openstack, etc 25 | "k8s.io/component-base/logs" 26 | 27 | "sigs.k8s.io/kubefed/pkg/kubefedctl" 28 | ) 29 | 30 | func main() { 31 | logs.InitLogs() 32 | defer logs.FlushLogs() 33 | 34 | if err := kubefedctl.NewKubeFedCtlCommand(os.Stdout).Execute(); err != nil { 35 | fmt.Fprintf(os.Stderr, "%v\n", err) 36 | os.Exit(1) //nolint:gocritic 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /cmd/webhook/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | "fmt" 21 | "os" 22 | 23 | "k8s.io/component-base/logs" 24 | "sigs.k8s.io/controller-runtime/pkg/manager/signals" 25 | 26 | "sigs.k8s.io/kubefed/cmd/webhook/app" 27 | ) 28 | 29 | func main() { 30 | logs.InitLogs() 31 | defer logs.FlushLogs() 32 | 33 | if err := app.NewWebhookCommand(signals.SetupSignalHandler().Done()).Execute(); err != nil { 34 | fmt.Fprintf(os.Stderr, "%v\n", err) 35 | os.Exit(1) //nolint:gocritic 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /config/enabletypedirectives/clusterroles.rbac.authorization.k8s.io.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: clusterroles.rbac.authorization.k8s.io 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/configmaps.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: configmaps 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/deployments.apps.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: deployments.apps 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/ingresses.networking.k8s.io.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: ingresses.networking.k8s.io 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/jobs.batch.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: jobs.batch 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/namespaces.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: namespaces 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/replicasets.apps.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: replicasets.apps 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/secrets.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: secrets 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/serviceaccounts.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: serviceaccounts 5 | -------------------------------------------------------------------------------- /config/enabletypedirectives/services.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: EnableTypeDirective 3 | metadata: 4 | name: services 5 | -------------------------------------------------------------------------------- /config/kubefedconfig.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: KubeFedConfig 3 | metadata: 4 | name: kubefed 5 | namespace: kube-federation-system 6 | spec: 7 | scope: Cluster 8 | controllerDuration: 9 | availableDelay: 20s 10 | unavailableDelay: 60s 11 | cacheSyncTimeout: 5m 12 | leaderElect: 13 | leaseDuration: 1500ms 14 | renewDeadline: 1000ms 15 | resourceLock: configmaps 16 | retryPeriod: 500ms 17 | featureGates: 18 | - name: PushReconciler 19 | configuration: "Enabled" 20 | - name: RawResourceStatusCollection 21 | configuration: "Enabled" 22 | - name: SchedulerPreferences 23 | configuration: "Enabled" 24 | clusterHealthCheck: 25 | failureThreshold: 3 26 | period: 10s 27 | successThreshold: 1 28 | timeout: 3s 29 | syncController: 30 | maxConcurrentReconciles: 1 31 | adoptResources: Enabled 32 | statusController: 33 | maxConcurrentReconciles: 1 34 | -------------------------------------------------------------------------------- /docs/OWNERS: -------------------------------------------------------------------------------- 1 | reviewers: 2 | - gyliu513 3 | - font 4 | - irfanurrehman 5 | - danehans 6 | approvers: 7 | - font 8 | - irfanurrehman 9 | - pmorie 10 | - gyliu513 11 | -------------------------------------------------------------------------------- /docs/environments/minikube.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [Minikube](#minikube) 6 | 7 | 8 | 9 | # Minikube 10 | 11 | [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube/) 12 | provides one of the quickest way to set-up clusters for use with KubeFed. 13 | 14 | **NOTE:** You will need to use a minikube version that supports 15 | deploying a kubernetes cluster >= 1.13. [Recently 16 | released](https://github.com/kubernetes/minikube/releases/latest) 17 | versions of minikube (>= `0.32.0`) will satisfy this requirement. 18 | 19 | Once you have minikube installed run: 20 | 21 | ```bash 22 | minikube start -p cluster1 --kubernetes-version v1.13.4 23 | minikube start -p cluster2 --kubernetes-version v1.13.4 24 | ``` 25 | 26 | Even though the `minikube` cluster has been started, you'll want to verify all 27 | your `minikube` components are up and ready by examining the state of the 28 | kubernetes components in the clusters via: 29 | 30 | ```bash 31 | kubectl get all --all-namespaces 32 | ``` 33 | 34 | After all pods reach a Running status, you can return to the [User Guide](../userguide.md) to deploy the cluster 35 | registry and KubeFed control plane. 36 | -------------------------------------------------------------------------------- /docs/images/concepts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/images/concepts.png -------------------------------------------------------------------------------- /docs/images/ingressdns-with-externaldns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/images/ingressdns-with-externaldns.png -------------------------------------------------------------------------------- /docs/images/propagation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/images/propagation.png -------------------------------------------------------------------------------- /docs/images/servicedns-with-externaldns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/images/servicedns-with-externaldns.png -------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [Installing KubeFed](#installing-kubefed) 6 | - [Prerequisites](#prerequisites) 7 | - [kubefedctl CLI](#kubefedctl-cli) 8 | - [Creating Clusters](#creating-clusters) 9 | - [Deployment Image](#deployment-image) 10 | - [Helm Chart Deployment](#helm-chart-deployment) 11 | 12 | 13 | 14 | # Installing KubeFed 15 | 16 | ## Prerequisites 17 | 18 | ### kubefedctl CLI 19 | 20 | `kubefedctl` is the KubeFed command line utility. You can download 21 | the latest binary from the [release page](https://github.com/kubernetes-sigs/kubefed/releases). 22 | 23 | ```bash 24 | VERSION= 25 | OS= 26 | ARCH=amd64 27 | curl -LO https://github.com/kubernetes-sigs/kubefed/releases/download/v${VERSION}/kubefedctl-${VERSION}-${OS}-${ARCH}.tgz 28 | tar -zxvf kubefedctl-*.tgz 29 | chmod u+x kubefedctl 30 | sudo mv kubefedctl /usr/local/bin/ # make sure the location is in the PATH 31 | ``` 32 | 33 | **NOTE:** `kubefedctl` is built for Linux and OSX only in the release package. 34 | 35 | ### Creating Clusters 36 | 37 | The following is a list of Kubernetes environments that have been tested and are supported by the KubeFed community. 38 | 39 | - [kind](./environments/kind.md) 40 | - [Minikube](./environments/minikube.md) 41 | - [Google Kubernetes Engine (GKE)](./environments/gke.md) 42 | - [IBM Cloud Private](./environments/icp.md) 43 | 44 | After completing the steps in one of the above guides, return here to continue the deployment. 45 | 46 | **IMPORTANT:** You must set the correct context in your cluster(s) using the command below. 47 | 48 | ```bash 49 | kubectl config use-context cluster1 50 | ``` 51 | ### Deployment Image 52 | 53 | If you follow this user guide without any changes you will be using the latest master image tagged as [`canary`](development.md#test-latest-master-changes-canary). 54 | 55 | ## Helm Chart Deployment 56 | 57 | You can refer to [helm chart installation guide](https://github.com/kubernetes-sigs/kubefed/blob/master/charts/kubefed/README.md) for instructions on installing KubeFed. 58 | -------------------------------------------------------------------------------- /docs/keps/images/kubefedArch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/keps/images/kubefedArch.jpg -------------------------------------------------------------------------------- /docs/keps/images/kubefedv2Example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/keps/images/kubefedv2Example.jpg -------------------------------------------------------------------------------- /docs/keps/images/kubefedv2_seconditeration.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-retired/kubefed/d6f10d29c3785dc55abc954dec0afeddce4893ef/docs/keps/images/kubefedv2_seconditeration.jpg -------------------------------------------------------------------------------- /example/config/kubefedconfig.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: core.kubefed.io/v1beta1 2 | kind: KubeFedConfig 3 | metadata: 4 | name: kubefed 5 | namespace: kube-federation-system 6 | spec: 7 | scope: Cluster 8 | controllerDuration: 9 | availableDelay: 20s 10 | unavailableDelay: 60s 11 | clusterMonitorPeriod: 40s 12 | leaderElect: 13 | leaseDuration: 15s 14 | renewDeadline: 10s 15 | retryPeriod: 5s 16 | resourceLock: configmaps 17 | featureGates: 18 | - name: PushReconciler 19 | configuration: "Enabled" 20 | - name: RawResourceStatusCollection 21 | configuration: "Enabled" 22 | - name: SchedulerPreferences 23 | configuration: "Enabled" 24 | -------------------------------------------------------------------------------- /example/sample1/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: web-file 5 | data: 6 | index.html: "Hello from Kubernetes Cluster Federation!" 7 | 8 | -------------------------------------------------------------------------------- /example/sample1/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | containers: 18 | - image: nginx 19 | name: nginx 20 | volumeMounts: 21 | - name: web-file 22 | mountPath: /usr/share/nginx/html/ 23 | volumes: 24 | - name: web-file 25 | configMap: 26 | name: web-file 27 | -------------------------------------------------------------------------------- /example/sample1/federatedclusterrole.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedClusterRole 3 | metadata: 4 | name: test-clusterrole 5 | spec: 6 | template: 7 | rules: 8 | - apiGroups: 9 | - '*' 10 | resources: 11 | - '*' 12 | verbs: 13 | - '*' 14 | placement: 15 | clusters: 16 | - name: cluster2 17 | - name: cluster1 18 | -------------------------------------------------------------------------------- /example/sample1/federatedclusterrolebinding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedClusterRoleBinding 3 | metadata: 4 | name: test-clusterrolebinding 5 | spec: 6 | template: 7 | subjects: 8 | - kind: Group 9 | name: test-user 10 | apiGroup: rbac.authorization.k8s.io 11 | roleRef: 12 | kind: ClusterRole 13 | name: cluster-admin 14 | apiGroup: rbac.authorization.k8s.io 15 | placement: 16 | clusters: 17 | - name: cluster2 18 | - name: cluster1 19 | -------------------------------------------------------------------------------- /example/sample1/federatedconfigmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedConfigMap 3 | metadata: 4 | name: test-configmap 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | data: 9 | A: ala ma kota 10 | placement: 11 | clusters: 12 | - name: cluster2 13 | - name: cluster1 14 | overrides: 15 | - clusterName: cluster2 16 | clusterOverrides: 17 | - path: /data 18 | value: 19 | foo: bar 20 | -------------------------------------------------------------------------------- /example/sample1/federateddeployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedDeployment 3 | metadata: 4 | name: test-deployment 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | metadata: 9 | labels: 10 | app: nginx 11 | spec: 12 | replicas: 3 13 | selector: 14 | matchLabels: 15 | app: nginx 16 | template: 17 | metadata: 18 | labels: 19 | app: nginx 20 | spec: 21 | containers: 22 | - image: nginx 23 | name: nginx 24 | placement: 25 | clusters: 26 | - name: cluster2 27 | - name: cluster1 28 | overrides: 29 | - clusterName: cluster2 30 | clusterOverrides: 31 | - path: "/spec/replicas" 32 | value: 5 33 | - path: "/spec/template/spec/containers/0/image" 34 | value: "nginx:1.17.0-alpine" 35 | - path: "/metadata/annotations" 36 | op: "add" 37 | value: 38 | foo: bar 39 | - path: "/metadata/annotations/foo" 40 | op: "remove" 41 | -------------------------------------------------------------------------------- /example/sample1/federatedingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedIngress 3 | metadata: 4 | name: test-ingress 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | spec: 9 | rules: 10 | - host: ingress.example.com 11 | http: 12 | paths: 13 | - backend: 14 | serviceName: test-service 15 | servicePort: 80 16 | placement: 17 | clusters: 18 | - name: cluster2 19 | - name: cluster1 20 | -------------------------------------------------------------------------------- /example/sample1/federatedjob.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedJob 3 | metadata: 4 | name: test-job 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | spec: 9 | parallelism: 1 10 | selector: 11 | matchLabels: 12 | app: busybox 13 | manualSelector: true 14 | template: 15 | metadata: 16 | labels: 17 | app: busybox 18 | spec: 19 | terminationGracePeriodSeconds: 0 20 | restartPolicy: Never 21 | containers: 22 | - name: busybox 23 | image: busybox 24 | command: ["/bin/sh", "-c", "trap : TERM INT; (while true; do sleep 1000; done) & wait"] 25 | placement: 26 | clusters: 27 | - name: cluster2 28 | - name: cluster1 29 | overrides: 30 | - clusterName: cluster2 31 | clusterOverrides: 32 | - path: /spec/parallelism 33 | value: 2 34 | -------------------------------------------------------------------------------- /example/sample1/federatednamespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedNamespace 3 | metadata: 4 | name: test-namespace 5 | namespace: test-namespace 6 | spec: 7 | placement: 8 | clusters: 9 | - name: cluster2 10 | - name: cluster1 11 | -------------------------------------------------------------------------------- /example/sample1/federatedsecret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedSecret 3 | metadata: 4 | name: test-secret 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | data: 9 | A: YWxhIG1hIGtvdGE= 10 | type: Opaque 11 | placement: 12 | clusters: 13 | - name: cluster2 14 | - name: cluster1 15 | overrides: 16 | - clusterName: cluster2 17 | clusterOverrides: 18 | - path: /data 19 | value: 20 | A: null 21 | -------------------------------------------------------------------------------- /example/sample1/federatedservice.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedService 3 | metadata: 4 | name: test-service 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | spec: 9 | selector: 10 | app: nginx 11 | type: NodePort 12 | ports: 13 | - name: http 14 | port: 80 15 | placement: 16 | clusters: 17 | - name: cluster2 18 | - name: cluster1 19 | -------------------------------------------------------------------------------- /example/sample1/federatedserviceaccount.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: types.kubefed.io/v1beta1 2 | kind: FederatedServiceAccount 3 | metadata: 4 | name: test-serviceaccount 5 | namespace: test-namespace 6 | spec: 7 | template: 8 | automountServiceAccountToken: true 9 | placement: 10 | clusters: 11 | - name: cluster2 12 | - name: cluster1 13 | -------------------------------------------------------------------------------- /example/sample1/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: test-namespace 5 | -------------------------------------------------------------------------------- /example/sample1/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx 5 | labels: 6 | app: nginx 7 | spec: 8 | ports: 9 | - nodePort: 30080 10 | port: 80 11 | protocol: TCP 12 | targetPort: 80 13 | selector: 14 | app: nginx 15 | type: NodePort 16 | -------------------------------------------------------------------------------- /example/scheduling/federateddeployment-rsp.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: scheduling.kubefed.io/v1alpha1 2 | kind: ReplicaSchedulingPreference 3 | metadata: 4 | name: test-deployment 5 | namespace: test-namespace 6 | spec: 7 | targetKind: FederatedDeployment 8 | totalReplicas: 10 9 | rebalance: true 10 | clusters: 11 | cluster1: 12 | weight: 2 13 | cluster2: 14 | weight: 3 15 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/kubefed 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/evanphx/json-patch v4.12.0+incompatible 7 | github.com/ghodss/yaml v1.0.0 8 | github.com/json-iterator/go v1.1.11 9 | github.com/onsi/ginkgo v1.16.4 10 | github.com/onsi/gomega v1.15.0 11 | github.com/pborman/uuid v1.2.1 12 | github.com/pkg/errors v0.9.1 13 | github.com/prometheus/client_golang v1.11.0 14 | github.com/spf13/cobra v1.1.3 15 | github.com/spf13/pflag v1.0.5 16 | github.com/stretchr/testify v1.7.0 17 | golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 18 | k8s.io/api v0.22.2 19 | k8s.io/apiextensions-apiserver v0.22.2 20 | k8s.io/apimachinery v0.22.2 21 | k8s.io/apiserver v0.22.2 22 | k8s.io/client-go v0.22.2 23 | k8s.io/component-base v0.22.2 24 | k8s.io/klog/v2 v2.9.0 25 | k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e 26 | k8s.io/kubectl v0.22.2 27 | k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a 28 | sigs.k8s.io/controller-runtime v0.10.3 29 | sigs.k8s.io/yaml v1.2.0 30 | ) 31 | -------------------------------------------------------------------------------- /hack/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | -------------------------------------------------------------------------------- /hack/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 hack 18 | -------------------------------------------------------------------------------- /hack/verify-docfiles.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eou pipefail 18 | 19 | GIT_COMMIT_SHA=${GITHUB_SHA:-$(git rev-parse HEAD)} 20 | 21 | CHANGED_FILES=$(git diff --name-only master..."${GIT_COMMIT_SHA}") 22 | 23 | [[ -z $CHANGED_FILES ]] && exit 1 24 | 25 | for CHANGED_FILE in $CHANGED_FILES; do 26 | if ! [[ $CHANGED_FILE =~ ^docs/ || $CHANGED_FILE =~ .md$ ]]; then 27 | exit 1 28 | fi 29 | done 30 | -------------------------------------------------------------------------------- /hack/verify-errpkg.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -euo pipefail 18 | 19 | SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 20 | REPO_ROOT="$(cd "${SCRIPT_ROOT}/.." && pwd)" 21 | pushd ${REPO_ROOT} > /dev/null 22 | 23 | find_files() { 24 | find . -not \( \ 25 | \( \ 26 | -wholename '*/third-party/*' \ 27 | -o -wholename '*/pkg/client/*' \ 28 | -o -wholename '*/*deepcopy.go' \ 29 | -o -wholename '*/test/common/bindata.go' \ 30 | -o -wholename '*/doc.go' \ 31 | \) -prune \ 32 | \) -name '*.go' 33 | } 34 | 35 | ERRORPKG="grep -l fmt.Errorf" 36 | bad_files=$(find_files | xargs $ERRORPKG) || true 37 | popd > /dev/null 38 | 39 | if [[ -n "${bad_files}" ]]; then 40 | echo "Please Switch from fmt.Errorf to \`errors\` to fix the following files:" 41 | echo "${bad_files}" 42 | exit 1 43 | fi 44 | -------------------------------------------------------------------------------- /hack/verify-klog.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -euo pipefail 18 | 19 | SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 20 | REPO_ROOT="$(cd "${SCRIPT_ROOT}/.." && pwd)" 21 | pushd ${REPO_ROOT} > /dev/null 22 | 23 | find_files() { 24 | find . -not \( \ 25 | \( \ 26 | -wholename '*/third-party/*' \ 27 | -o -wholename '*/pkg/client/*' \ 28 | -o -wholename '*/doc.go' \ 29 | \) -prune \ 30 | \) -name '*.go' 31 | } 32 | 33 | ERRORPKG="grep -l glog" 34 | bad_files=$(find_files | xargs $ERRORPKG) || true 35 | popd > /dev/null 36 | 37 | if [[ -n "${bad_files}" ]]; then 38 | echo "Please Switch from glog to klog to fix the following files:" 39 | echo "${bad_files}" 40 | exit 1 41 | fi 42 | -------------------------------------------------------------------------------- /images/kubefed/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Kubernetes 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 | FROM alpine:latest 17 | RUN apk --no-cache add ca-certificates 18 | RUN adduser -D -g hyperfed -u 1001 hyperfed 19 | 20 | RUN mkdir -p /hyperfed 21 | 22 | WORKDIR /hyperfed/ 23 | COPY /hyperfed . 24 | RUN ln -s hyperfed controller-manager \ 25 | && ln -s hyperfed kubefedctl \ 26 | && ln -s hyperfed webhook 27 | 28 | RUN chown -R hyperfed:hyperfed /hyperfed 29 | 30 | USER hyperfed 31 | ENTRYPOINT ["./controller-manager"] 32 | -------------------------------------------------------------------------------- /pkg/apis/addtoscheme_core_v1alpha1.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | "sigs.k8s.io/kubefed/pkg/apis/core/v1alpha1" 21 | ) 22 | 23 | func init() { 24 | // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back 25 | AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apis/addtoscheme_core_v1beta1.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1" 21 | ) 22 | 23 | func init() { 24 | // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back 25 | AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apis/addtoscheme_scheduling_v1alpha1.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | "sigs.k8s.io/kubefed/pkg/apis/scheduling/v1alpha1" 21 | ) 22 | 23 | func init() { 24 | // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back 25 | AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apis/apis.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 contains Kubernetes API groups. 18 | package apis 19 | 20 | import ( 21 | "k8s.io/apimachinery/pkg/runtime" 22 | ) 23 | 24 | // AddToSchemes may be used to add all resources defined in the project to a Scheme 25 | var AddToSchemes runtime.SchemeBuilder 26 | 27 | // AddToScheme adds all Resources to the Scheme 28 | func AddToScheme(s *runtime.Scheme) error { 29 | return AddToSchemes.AddToScheme(s) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/apis/core/common/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | type ClusterConditionType string 20 | 21 | // These are valid conditions of a cluster. 22 | const ( 23 | // ClusterReady means the cluster is ready to accept workloads. 24 | ClusterReady ClusterConditionType = "Ready" 25 | // ClusterOffline means the cluster is temporarily down or not reachable 26 | ClusterOffline ClusterConditionType = "Offline" 27 | // ClusterConfigMalformed means the cluster's configuration may be malformed. 28 | ClusterConfigMalformed ClusterConditionType = "ConfigMalformed" 29 | ) 30 | 31 | const ( 32 | NamespaceName = "namespaces" 33 | ) 34 | -------------------------------------------------------------------------------- /pkg/apis/core/common/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | "fmt" 21 | "strings" 22 | ) 23 | 24 | func PropagatedVersionName(kind, resourceName string) string { 25 | return fmt.Sprintf("%s%s", PropagatedVersionPrefix(kind), resourceName) 26 | } 27 | 28 | func PropagatedVersionPrefix(kind string) string { 29 | return fmt.Sprintf("%s-", strings.ToLower(kind)) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/apis/core/group.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 contains core API versions 18 | package core 19 | -------------------------------------------------------------------------------- /pkg/apis/core/typeconfig/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 typeconfig 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // Interface defines how to interact with a FederatedTypeConfig 24 | type Interface interface { 25 | GetObjectMeta() metav1.ObjectMeta 26 | GetTargetType() metav1.APIResource 27 | GetNamespaced() bool 28 | GetPropagationEnabled() bool 29 | GetFederatedType() metav1.APIResource 30 | GetStatusType() *metav1.APIResource 31 | GetStatusEnabled() bool 32 | GetFederatedNamespaced() bool 33 | IsNamespace() bool 34 | } 35 | -------------------------------------------------------------------------------- /pkg/apis/core/typeconfig/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 typeconfig 18 | 19 | import ( 20 | "fmt" 21 | 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | ) 24 | 25 | // GroupQualifiedName returns the plural name of the api resource 26 | // optionally qualified by its group: 27 | // 28 | // '[.]' 29 | // 30 | // This is the naming scheme for FederatedTypeConfig resources. The 31 | // scheme ensures that, for a given KubeFed control plane, 32 | // federation of a target type will be configured by at most one 33 | // FederatedTypeConfig. 34 | func GroupQualifiedName(apiResource metav1.APIResource) string { 35 | if len(apiResource.Group) == 0 { 36 | return apiResource.Name 37 | } 38 | return fmt.Sprintf("%s.%s", apiResource.Name, apiResource.Group) 39 | } 40 | -------------------------------------------------------------------------------- /pkg/apis/core/v1alpha1/clusterpropagatedversion_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // ClusterPropagatedVersionSpec defines the desired state of ClusterPropagatedVersion 24 | type ClusterPropagatedVersionSpec struct { 25 | } 26 | 27 | // +kubebuilder:object:root=true 28 | // +kubebuilder:resource:path=clusterpropagatedversions,scope=Cluster 29 | // +kubebuilder:subresource:status 30 | 31 | // ClusterPropagatedVersion holds version information about the state 32 | // propagated from KubeFed APIs (configured by FederatedTypeConfig 33 | // resources) to member clusters. The name of a ClusterPropagatedVersion 34 | // encodes the kind and name of the resource it stores information for 35 | // (i.e. -). If a target resource has 36 | // a populated metadata.Generation field, the generation will be 37 | // stored with a prefix of `gen:` as the version for the cluster. If 38 | // metadata.Generation is not available, metadata.ResourceVersion will 39 | // be stored with a prefix of `rv:` as the version for the cluster. 40 | type ClusterPropagatedVersion struct { 41 | metav1.TypeMeta `json:",inline"` 42 | metav1.ObjectMeta `json:"metadata,omitempty"` 43 | 44 | // +optional 45 | Status PropagatedVersionStatus `json:"status,omitempty"` 46 | } 47 | 48 | // +kubebuilder:object:root=true 49 | 50 | // ClusterPropagatedVersionList contains a list of ClusterPropagatedVersion 51 | type ClusterPropagatedVersionList struct { 52 | metav1.TypeMeta `json:",inline"` 53 | metav1.ListMeta `json:"metadata,omitempty"` 54 | Items []ClusterPropagatedVersion `json:"items"` 55 | } 56 | 57 | func init() { 58 | SchemeBuilder.Register(&ClusterPropagatedVersion{}, &ClusterPropagatedVersionList{}) 59 | } 60 | -------------------------------------------------------------------------------- /pkg/apis/core/v1alpha1/federatedservicestatus_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | corev1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // FederatedServiceClusterStatus is the observed status of the resource for a named cluster 25 | type FederatedServiceClusterStatus struct { 26 | ClusterName string `json:"clusterName"` 27 | Status corev1.ServiceStatus `json:"status"` 28 | } 29 | 30 | // +kubebuilder:object:root=true 31 | // +kubebuilder:resource:path=federatedservicestatuses 32 | 33 | type FederatedServiceStatus struct { 34 | metav1.TypeMeta `json:",inline"` 35 | metav1.ObjectMeta `json:"metadata,omitempty"` 36 | 37 | // +optional 38 | ClusterStatus []FederatedServiceClusterStatus `json:"clusterStatus,omitempty"` 39 | } 40 | 41 | // +kubebuilder:object:root=true 42 | 43 | // FederatedServiceStatusList contains a list of FederatedServiceStatus 44 | type FederatedServiceStatusList struct { 45 | metav1.TypeMeta `json:",inline"` 46 | metav1.ListMeta `json:"metadata,omitempty"` 47 | Items []FederatedServiceStatus `json:"items"` 48 | } 49 | 50 | func init() { 51 | SchemeBuilder.Register(&FederatedServiceStatus{}, &FederatedServiceStatusList{}) 52 | } 53 | -------------------------------------------------------------------------------- /pkg/apis/core/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | // NOTE: Boilerplate only. Ignore this file. 18 | 19 | // Package v1alpha1 contains API Schema definitions for the core v1alpha1 API group 20 | // +kubebuilder:object:generate=true 21 | // +groupName=core.kubefed.io 22 | package v1alpha1 23 | 24 | import ( 25 | "k8s.io/apimachinery/pkg/runtime/schema" 26 | "sigs.k8s.io/controller-runtime/pkg/scheme" 27 | ) 28 | 29 | var ( 30 | // SchemeGroupVersion is group version used to register these objects 31 | SchemeGroupVersion = schema.GroupVersion{Group: "core.kubefed.io", Version: "v1alpha1"} 32 | 33 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 34 | SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} 35 | 36 | // AddToScheme adds the types in this group-version to the given scheme. 37 | AddToScheme = SchemeBuilder.AddToScheme 38 | ) 39 | -------------------------------------------------------------------------------- /pkg/apis/core/v1beta1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | // NOTE: Boilerplate only. Ignore this file. 18 | 19 | // Package v1beta1 contains API Schema definitions for the core v1beta1 API group 20 | // +kubebuilder:object:generate=true 21 | // +groupName=core.kubefed.io 22 | package v1beta1 23 | 24 | import ( 25 | "k8s.io/apimachinery/pkg/runtime/schema" 26 | "sigs.k8s.io/controller-runtime/pkg/scheme" 27 | ) 28 | 29 | var ( 30 | // SchemeGroupVersion is group version used to register these objects 31 | SchemeGroupVersion = schema.GroupVersion{Group: "core.kubefed.io", Version: "v1beta1"} 32 | 33 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 34 | SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} 35 | 36 | // AddToScheme adds the types in this group-version to the given scheme. 37 | AddToScheme = SchemeBuilder.AddToScheme 38 | ) 39 | -------------------------------------------------------------------------------- /pkg/apis/core/v1beta1/suite_test.go: -------------------------------------------------------------------------------- 1 | package v1beta1 2 | 3 | import ( 4 | "path/filepath" 5 | "testing" 6 | 7 | . "github.com/onsi/ginkgo" 8 | . "github.com/onsi/gomega" 9 | 10 | "k8s.io/client-go/kubernetes/scheme" 11 | "k8s.io/client-go/rest" 12 | "sigs.k8s.io/controller-runtime/pkg/client" 13 | "sigs.k8s.io/controller-runtime/pkg/envtest" 14 | "sigs.k8s.io/controller-runtime/pkg/envtest/printer" 15 | logf "sigs.k8s.io/controller-runtime/pkg/log" 16 | "sigs.k8s.io/controller-runtime/pkg/log/zap" 17 | ) 18 | 19 | var cfg *rest.Config 20 | var k8sClient client.Client 21 | var testEnv *envtest.Environment 22 | 23 | func TestAPIs(t *testing.T) { 24 | RegisterFailHandler(Fail) 25 | 26 | RunSpecsWithDefaultAndCustomReporters(t, 27 | "v1beta1 Suite", 28 | []Reporter{printer.NewlineReporter{}}) 29 | } 30 | 31 | var _ = BeforeSuite(func(done Done) { 32 | logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) 33 | 34 | By("bootstrapping test environment") 35 | testEnv = &envtest.Environment{ 36 | CRDInstallOptions: envtest.CRDInstallOptions{ 37 | ErrorIfPathMissing: true, 38 | Paths: []string{ 39 | filepath.Join("..", "..", "..", "..", "charts", "kubefed", "charts", "controllermanager", "crds"), 40 | }, 41 | }, 42 | } 43 | 44 | err := SchemeBuilder.AddToScheme(scheme.Scheme) 45 | Expect(err).NotTo(HaveOccurred()) 46 | 47 | cfg, err = testEnv.Start() 48 | Expect(err).ToNot(HaveOccurred()) 49 | Expect(cfg).ToNot(BeNil()) 50 | 51 | k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) 52 | Expect(err).ToNot(HaveOccurred()) 53 | Expect(k8sClient).ToNot(BeNil()) 54 | 55 | close(done) 56 | }, 60) 57 | 58 | var _ = AfterSuite(func() { 59 | By("tearing down the test environment") 60 | err := testEnv.Stop() 61 | Expect(err).ToNot(HaveOccurred()) 62 | }) 63 | -------------------------------------------------------------------------------- /pkg/apis/scheduling/group.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 scheduling contains scheduling API versions 18 | package scheduling 19 | -------------------------------------------------------------------------------- /pkg/apis/scheduling/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | // NOTE: Boilerplate only. Ignore this file. 18 | 19 | // Package v1alpha1 contains API Schema definitions for the scheduling v1alpha1 API group 20 | // +kubebuilder:object:generate=true 21 | // +groupName=scheduling.kubefed.io 22 | package v1alpha1 23 | 24 | import ( 25 | "k8s.io/apimachinery/pkg/runtime/schema" 26 | "sigs.k8s.io/controller-runtime/pkg/scheme" 27 | ) 28 | 29 | var ( 30 | // SchemeGroupVersion is group version used to register these objects 31 | SchemeGroupVersion = schema.GroupVersion{Group: "scheduling.kubefed.io", Version: "v1alpha1"} 32 | 33 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 34 | SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} 35 | 36 | // AddToScheme is required by pkg/client/... 37 | AddToScheme = SchemeBuilder.AddToScheme 38 | ) 39 | 40 | // Resource is required by pkg/client/listers/... 41 | func Resource(resource string) schema.GroupResource { 42 | return SchemeGroupVersion.WithResource(resource).GroupResource() 43 | } 44 | -------------------------------------------------------------------------------- /pkg/client/generic/scheme/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 scheme 18 | 19 | import ( 20 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtime "k8s.io/apimachinery/pkg/runtime" 22 | schema "k8s.io/apimachinery/pkg/runtime/schema" 23 | "k8s.io/apimachinery/pkg/runtime/serializer" 24 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 25 | k8sscheme "k8s.io/client-go/kubernetes/scheme" 26 | 27 | fedapis "sigs.k8s.io/kubefed/pkg/apis" 28 | ) 29 | 30 | var Scheme = runtime.NewScheme() 31 | var Codecs = serializer.NewCodecFactory(Scheme) 32 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 33 | var localSchemeBuilder = runtime.SchemeBuilder{ 34 | fedapis.AddToScheme, 35 | k8sscheme.AddToScheme, 36 | } 37 | 38 | func init() { 39 | v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 40 | utilruntime.Must(AddToScheme(Scheme)) 41 | } 42 | 43 | var AddToScheme = localSchemeBuilder.AddToScheme 44 | -------------------------------------------------------------------------------- /pkg/controller/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 controller 18 | -------------------------------------------------------------------------------- /pkg/controller/sync/resource_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 sync 18 | 19 | import ( 20 | "strings" 21 | "testing" 22 | 23 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 24 | 25 | kfenable "sigs.k8s.io/kubefed/pkg/kubefedctl/enable" 26 | ) 27 | 28 | func TestGetTemplateHash(t *testing.T) { 29 | template := &unstructured.Unstructured{} 30 | yaml := ` 31 | kind: foo 32 | spec: 33 | template: 34 | spec: 35 | foo: 36 | ` 37 | err := kfenable.DecodeYAML(strings.NewReader(yaml), template) 38 | if err != nil { 39 | t.Fatalf("An unexpected error occurred: %v", err) 40 | } 41 | hash, err := GetTemplateHash(template.Object) 42 | if err != nil { 43 | t.Fatalf("An unexpected error occurred: %v", err) 44 | } 45 | expectedHash := "a5b8d4352d5aed51c51b93900258ccf3" 46 | if hash != expectedHash { 47 | t.Fatalf("Expected %s, got %s", expectedHash, hash) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pkg/controller/sync/version/adapter.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 version 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 22 | 23 | fedv1a1 "sigs.k8s.io/kubefed/pkg/apis/core/v1alpha1" 24 | "sigs.k8s.io/kubefed/pkg/controller/util" 25 | ) 26 | 27 | type VersionAdapter interface { 28 | TypeName() string 29 | 30 | // Create an empty instance of the version type 31 | NewObject() runtimeclient.Object 32 | // Create an empty instance of list version type 33 | NewListObject() runtimeclient.ObjectList 34 | // Create a populated instance of the version type 35 | NewVersion(qualifiedName util.QualifiedName, ownerReference metav1.OwnerReference, status *fedv1a1.PropagatedVersionStatus) runtimeclient.Object 36 | 37 | // Type-agnostic access / mutation of the Status field of a version resource 38 | GetStatus(obj runtimeclient.Object) *fedv1a1.PropagatedVersionStatus 39 | SetStatus(obj runtimeclient.Object, status *fedv1a1.PropagatedVersionStatus) 40 | } 41 | 42 | func NewVersionAdapter(namespaced bool) VersionAdapter { 43 | if namespaced { 44 | return &namespacedVersionAdapter{} 45 | } 46 | return &clusterVersionAdapter{} 47 | } 48 | -------------------------------------------------------------------------------- /pkg/controller/sync/version/cluster.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 version 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 22 | 23 | fedv1a1 "sigs.k8s.io/kubefed/pkg/apis/core/v1alpha1" 24 | "sigs.k8s.io/kubefed/pkg/controller/util" 25 | ) 26 | 27 | type clusterVersionAdapter struct{} 28 | 29 | func (*clusterVersionAdapter) TypeName() string { 30 | return "ClusterPropagatedVersion" 31 | } 32 | 33 | func (*clusterVersionAdapter) NewListObject() runtimeclient.ObjectList { 34 | return &fedv1a1.ClusterPropagatedVersionList{} 35 | } 36 | 37 | func (*clusterVersionAdapter) NewObject() runtimeclient.Object { 38 | return &fedv1a1.ClusterPropagatedVersion{} 39 | } 40 | 41 | func (*clusterVersionAdapter) NewVersion(qualifiedName util.QualifiedName, ownerReference metav1.OwnerReference, status *fedv1a1.PropagatedVersionStatus) runtimeclient.Object { 42 | return &fedv1a1.ClusterPropagatedVersion{ 43 | ObjectMeta: metav1.ObjectMeta{ 44 | Name: qualifiedName.Name, 45 | OwnerReferences: []metav1.OwnerReference{ownerReference}, 46 | }, 47 | Status: *status, 48 | } 49 | } 50 | 51 | func (*clusterVersionAdapter) GetStatus(obj runtimeclient.Object) *fedv1a1.PropagatedVersionStatus { 52 | version := obj.(*fedv1a1.ClusterPropagatedVersion) 53 | status := version.Status 54 | return &status 55 | } 56 | 57 | func (*clusterVersionAdapter) SetStatus(obj runtimeclient.Object, status *fedv1a1.PropagatedVersionStatus) { 58 | version := obj.(*fedv1a1.ClusterPropagatedVersion) 59 | version.Status = *status 60 | } 61 | -------------------------------------------------------------------------------- /pkg/controller/sync/version/namespaced.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 version 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 22 | 23 | fedv1a1 "sigs.k8s.io/kubefed/pkg/apis/core/v1alpha1" 24 | "sigs.k8s.io/kubefed/pkg/controller/util" 25 | ) 26 | 27 | type namespacedVersionAdapter struct{} 28 | 29 | func (*namespacedVersionAdapter) TypeName() string { 30 | return "PropagatedVersion" 31 | } 32 | 33 | func (*namespacedVersionAdapter) NewListObject() runtimeclient.ObjectList { 34 | return &fedv1a1.PropagatedVersionList{} 35 | } 36 | 37 | func (*namespacedVersionAdapter) NewObject() runtimeclient.Object { 38 | return &fedv1a1.PropagatedVersion{} 39 | } 40 | 41 | func (*namespacedVersionAdapter) NewVersion(qualifiedName util.QualifiedName, ownerReference metav1.OwnerReference, status *fedv1a1.PropagatedVersionStatus) runtimeclient.Object { 42 | return &fedv1a1.PropagatedVersion{ 43 | ObjectMeta: metav1.ObjectMeta{ 44 | Namespace: qualifiedName.Namespace, 45 | Name: qualifiedName.Name, 46 | OwnerReferences: []metav1.OwnerReference{ownerReference}, 47 | }, 48 | Status: *status, 49 | } 50 | } 51 | 52 | func (*namespacedVersionAdapter) GetStatus(obj runtimeclient.Object) *fedv1a1.PropagatedVersionStatus { 53 | version := obj.(*fedv1a1.PropagatedVersion) 54 | status := version.Status 55 | return &status 56 | } 57 | 58 | func (*namespacedVersionAdapter) SetStatus(obj runtimeclient.Object, status *fedv1a1.PropagatedVersionStatus) { 59 | version := obj.(*fedv1a1.PropagatedVersion) 60 | version.Status = *status 61 | } 62 | -------------------------------------------------------------------------------- /pkg/controller/util/backoff.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 util 18 | 19 | import ( 20 | "time" 21 | 22 | "k8s.io/client-go/util/flowcontrol" 23 | ) 24 | 25 | func StartBackoffGC(backoff *flowcontrol.Backoff, stopCh <-chan struct{}) { 26 | go func() { 27 | for { 28 | select { 29 | case <-time.After(time.Minute): 30 | backoff.GC() 31 | case <-stopCh: 32 | return 33 | } 34 | } 35 | }() 36 | } 37 | -------------------------------------------------------------------------------- /pkg/controller/util/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 util 18 | 19 | import ( 20 | "time" 21 | ) 22 | 23 | const ( 24 | // Providing 0 duration to an informer indicates that resync should be delayed as long as possible 25 | NoResyncPeriod = 0 * time.Second 26 | 27 | SyncedPollPeriod = 10 * time.Second 28 | 29 | NamespaceName = "namespaces" 30 | NamespaceKind = "Namespace" 31 | 32 | ServiceKind = "Service" 33 | 34 | ServiceAccountKind = "ServiceAccount" 35 | 36 | // The following fields are used to interact with unstructured 37 | // resources. 38 | 39 | // Common fields 40 | SpecField = "spec" 41 | StatusField = "status" 42 | MetadataField = "metadata" 43 | 44 | // Service fields 45 | HealthCheckNodePortField = "healthCheckNodePort" 46 | ClusterIPField = "clusterIP" 47 | ClusterIPsField = "clusterIPs" 48 | PortsField = "ports" 49 | 50 | // ServiceAccount fields 51 | SecretsField = "secrets" 52 | 53 | // Scale types 54 | ReplicasField = "replicas" 55 | RetainReplicasField = "retainReplicas" 56 | 57 | // Template fields 58 | TemplateField = "template" 59 | 60 | // Placement fields 61 | PlacementField = "placement" 62 | ClusterSelectorField = "clusterSelector" 63 | MatchLabelsField = "matchLabels" 64 | 65 | // Override fields 66 | OverridesField = "overrides" 67 | ClusterNameField = "clusterName" 68 | ClusterOverridesField = "clusterOverrides" 69 | PathField = "path" 70 | ValueField = "value" 71 | 72 | // Cluster reference 73 | ClustersField = "clusters" 74 | NameField = "name" 75 | ) 76 | 77 | type ReconciliationStatus int 78 | 79 | const ( 80 | StatusAllOK ReconciliationStatus = iota 81 | StatusNeedsRecheck 82 | StatusError 83 | StatusNotSynced 84 | ) 85 | -------------------------------------------------------------------------------- /pkg/controller/util/delaying_deliverer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 util 18 | 19 | import ( 20 | "testing" 21 | "time" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestDelayingDeliverer(t *testing.T) { 27 | targetChannel := make(chan *DelayingDelivererItem) 28 | now := time.Now() 29 | d := NewDelayingDelivererWithChannel(targetChannel) 30 | d.Start() 31 | defer d.Stop() 32 | startupDelay := time.Second 33 | d.DeliverAt("a", "aaa", now.Add(startupDelay+2*time.Millisecond)) 34 | d.DeliverAt("b", "bbb", now.Add(startupDelay+3*time.Millisecond)) 35 | d.DeliverAt("c", "ccc", now.Add(startupDelay+1*time.Millisecond)) 36 | d.DeliverAt("e", "eee", now.Add(time.Hour)) 37 | d.DeliverAt("e", "eee", now) 38 | 39 | d.DeliverAt("d", "ddd", now.Add(time.Hour)) 40 | 41 | i0 := <-targetChannel 42 | assert.Equal(t, "e", i0.Key) 43 | assert.Equal(t, "eee", i0.Value.(string)) 44 | assert.Equal(t, now, i0.DeliveryTime) 45 | 46 | i1 := <-targetChannel 47 | received1 := time.Now() 48 | assert.True(t, received1.Sub(now).Nanoseconds() > startupDelay.Nanoseconds()) 49 | assert.Equal(t, "c", i1.Key) 50 | 51 | i2 := <-targetChannel 52 | assert.Equal(t, "a", i2.Key) 53 | 54 | i3 := <-targetChannel 55 | assert.Equal(t, "b", i3.Key) 56 | 57 | select { 58 | case <-targetChannel: 59 | t.Fatalf("Nothing should be received") 60 | case <-time.After(time.Second): 61 | // Ok. Expected 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pkg/controller/util/federatedstatus.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 util 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // FederatedResource is a generic representation of a federated type 24 | type FederatedResource struct { 25 | metav1.TypeMeta `json:",inline"` 26 | metav1.ObjectMeta `json:"metadata,omitempty"` 27 | 28 | ClusterStatus []ResourceClusterStatus `json:"clusterStatus,omitempty"` 29 | } 30 | 31 | // ResourceClusterStatus defines the status of federated resource within a cluster 32 | type ResourceClusterStatus struct { 33 | ClusterName string `json:"clusterName,omitempty"` 34 | Status map[string]interface{} `json:"status,omitempty"` 35 | } 36 | -------------------------------------------------------------------------------- /pkg/controller/util/handlers.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 util 18 | 19 | import ( 20 | "reflect" 21 | 22 | "k8s.io/client-go/tools/cache" 23 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 24 | ) 25 | 26 | // Returns cache.ResourceEventHandlerFuncs that trigger the given function 27 | // on all object changes. 28 | func NewTriggerOnAllChanges(triggerFunc func(runtimeclient.Object)) *cache.ResourceEventHandlerFuncs { 29 | return &cache.ResourceEventHandlerFuncs{ 30 | DeleteFunc: func(old interface{}) { 31 | if deleted, ok := old.(cache.DeletedFinalStateUnknown); ok { 32 | // This object might be stale but ok for our current usage. 33 | old = deleted.Obj 34 | if old == nil { 35 | return 36 | } 37 | } 38 | oldObj := old.(runtimeclient.Object) 39 | triggerFunc(oldObj) 40 | }, 41 | AddFunc: func(cur interface{}) { 42 | curObj := cur.(runtimeclient.Object) 43 | triggerFunc(curObj) 44 | }, 45 | UpdateFunc: func(old, cur interface{}) { 46 | curObj := cur.(runtimeclient.Object) 47 | if !reflect.DeepEqual(old, cur) { 48 | triggerFunc(curObj) 49 | } 50 | }, 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /pkg/controller/util/handlers_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 util 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 24 | 25 | apiv1 "k8s.io/api/core/v1" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/client-go/tools/cache" 28 | ) 29 | 30 | func TestHandlers(t *testing.T) { 31 | // There is a single service ns1/s1 in cluster mycluster. 32 | service := apiv1.Service{ 33 | ObjectMeta: metav1.ObjectMeta{ 34 | Namespace: "ns1", 35 | Name: "s1", 36 | }, 37 | } 38 | service2 := apiv1.Service{ 39 | ObjectMeta: metav1.ObjectMeta{ 40 | Namespace: "ns1", 41 | Name: "s1", 42 | Annotations: map[string]string{ 43 | "A": "B", 44 | }, 45 | }, 46 | } 47 | triggerChan := make(chan interface{}, 1) 48 | triggered := func() bool { 49 | select { 50 | case <-triggerChan: 51 | return true 52 | default: 53 | return false 54 | } 55 | } 56 | triggeredWith := func(obj interface{}) bool { 57 | select { 58 | case triggeredObj := <-triggerChan: 59 | return triggeredObj == obj 60 | default: 61 | return false 62 | } 63 | } 64 | 65 | trigger := NewTriggerOnAllChanges( 66 | func(obj runtimeclient.Object) { 67 | triggerChan <- obj 68 | }) 69 | 70 | trigger.OnAdd(&service) 71 | assert.True(t, triggered()) 72 | trigger.OnDelete(&service) 73 | assert.True(t, triggeredWith(&service)) 74 | trigger.OnDelete( 75 | cache.DeletedFinalStateUnknown{Key: "ns1/s1", Obj: &service}) 76 | assert.True(t, triggeredWith(&service)) 77 | trigger.OnDelete( 78 | cache.DeletedFinalStateUnknown{Key: "ns1/s1", Obj: nil}) 79 | assert.False(t, triggered()) 80 | trigger.OnUpdate(&service, &service) 81 | assert.False(t, triggered()) 82 | trigger.OnUpdate(&service, &service2) 83 | assert.True(t, triggered()) 84 | } 85 | -------------------------------------------------------------------------------- /pkg/controller/util/managedlabel.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 util 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 21 | ) 22 | 23 | const ( 24 | ManagedByKubeFedLabelKey = "kubefed.io/managed" 25 | ManagedByKubeFedLabelValue = "true" 26 | UnmanagedByKubeFedLabelValue = "false" 27 | ) 28 | 29 | // HasManagedLabel indicates whether the given object has the managed 30 | // label. 31 | func HasManagedLabel(obj *unstructured.Unstructured) bool { 32 | labels := obj.GetLabels() 33 | if labels == nil { 34 | return false 35 | } 36 | return labels[ManagedByKubeFedLabelKey] == ManagedByKubeFedLabelValue 37 | } 38 | 39 | // IsExplicitlyUnmanaged indicates whether the given object has the managed 40 | // label with value false. 41 | func IsExplicitlyUnmanaged(obj *unstructured.Unstructured) bool { 42 | labels := obj.GetLabels() 43 | if labels == nil { 44 | return false 45 | } 46 | return labels[ManagedByKubeFedLabelKey] == UnmanagedByKubeFedLabelValue 47 | } 48 | 49 | // AddManagedLabel ensures that the given object has the managed 50 | // label. 51 | func AddManagedLabel(obj *unstructured.Unstructured) { 52 | labels := obj.GetLabels() 53 | if labels == nil { 54 | labels = make(map[string]string) 55 | } 56 | labels[ManagedByKubeFedLabelKey] = ManagedByKubeFedLabelValue 57 | obj.SetLabels(labels) 58 | } 59 | 60 | // RemoveManagedLabel ensures that the given object does not have the 61 | // managed label. 62 | func RemoveManagedLabel(obj *unstructured.Unstructured) { 63 | labels := obj.GetLabels() 64 | if labels == nil || labels[ManagedByKubeFedLabelKey] != ManagedByKubeFedLabelValue { 65 | return 66 | } 67 | delete(labels, ManagedByKubeFedLabelKey) 68 | obj.SetLabels(labels) 69 | } 70 | -------------------------------------------------------------------------------- /pkg/controller/util/naming.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 util 18 | 19 | // The functions in this file are exposed as variables to allow them 20 | // to be overridden for testing purposes. Simulated scale testing 21 | // requires being able to change the namespace of target resources 22 | // (NamespaceForCluster and QualifiedNameForCluster) and ensure that 23 | // the namespace of a federated resource will always be the kubefed 24 | // system namespace (NamespaceForResource). 25 | 26 | func namespaceForCluster(clusterName, namespace string) string { 27 | return namespace 28 | } 29 | 30 | // NamespaceForCluster returns the namespace to use for the given cluster. 31 | var NamespaceForCluster = namespaceForCluster 32 | 33 | func namespaceForResource(resourceNamespace, fedNamespace string) string { 34 | return resourceNamespace 35 | } 36 | 37 | // NamespaceForResource returns either the kubefed namespace or 38 | // resource namespace. 39 | var NamespaceForResource = namespaceForResource 40 | 41 | func qualifiedNameForCluster(clusterName string, qualifiedName QualifiedName) QualifiedName { 42 | return qualifiedName 43 | } 44 | 45 | // QualifiedNameForCluster returns the qualified name to use for the 46 | // given cluster. 47 | var QualifiedNameForCluster = qualifiedNameForCluster 48 | -------------------------------------------------------------------------------- /pkg/controller/util/orphaninganotation.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 util 18 | 19 | import "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 20 | 21 | const ( 22 | // If this annotation is present on a federated resource, resources in the 23 | // member clusters managed by the federated resource should be orphaned. 24 | // If the annotation is not present (the default), resources in member 25 | // clusters will be deleted before the federated resource is deleted. 26 | OrphanManagedResourcesAnnotation = "kubefed.io/orphan" 27 | OrphanedManagedResourcesValue = "true" 28 | ) 29 | 30 | // IsOrphaningEnabled checks status of "orphaning enable" (OrphanManagedResources: OrphanedManagedResourceslValue') 31 | // annotation on a resource. 32 | func IsOrphaningEnabled(obj *unstructured.Unstructured) bool { 33 | annotations := obj.GetAnnotations() 34 | if annotations == nil { 35 | return false 36 | } 37 | return annotations[OrphanManagedResourcesAnnotation] == OrphanedManagedResourcesValue 38 | } 39 | 40 | // Enables the orphaning mode 41 | func EnableOrphaning(obj *unstructured.Unstructured) { 42 | annotations := obj.GetAnnotations() 43 | if annotations == nil { 44 | annotations = make(map[string]string) 45 | } 46 | annotations[OrphanManagedResourcesAnnotation] = OrphanedManagedResourcesValue 47 | obj.SetAnnotations(annotations) 48 | } 49 | 50 | // Disables the orphaning mode 51 | func DisableOrphaning(obj *unstructured.Unstructured) { 52 | annotations := obj.GetAnnotations() 53 | if annotations == nil { 54 | return 55 | } 56 | delete(annotations, OrphanManagedResourcesAnnotation) 57 | obj.SetAnnotations(annotations) 58 | } 59 | -------------------------------------------------------------------------------- /pkg/controller/util/qualifiedname.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes 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 util 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/meta" 23 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 24 | ) 25 | 26 | // QualifiedName comprises a resource name with an optional namespace. 27 | // If namespace is provided, a QualifiedName will be rendered as 28 | // "/". If not, it will be rendered as "name". This 29 | // is intended to allow the FederatedTypeAdapter interface and its 30 | // consumers to operate on both namespaces and namespace-qualified 31 | // resources. 32 | 33 | type QualifiedName struct { 34 | Namespace string 35 | Name string 36 | } 37 | 38 | func NewQualifiedName(obj runtimeclient.Object) QualifiedName { 39 | accessor, err := meta.Accessor(obj) 40 | if err != nil { 41 | // TODO(marun) This should never happen, but if it does, the 42 | // resulting empty name. 43 | return QualifiedName{} 44 | } 45 | return QualifiedName{ 46 | Namespace: accessor.GetNamespace(), 47 | Name: accessor.GetName(), 48 | } 49 | } 50 | 51 | // String returns the general purpose string representation 52 | func (n QualifiedName) String() string { 53 | if len(n.Namespace) == 0 { 54 | return n.Name 55 | } 56 | return fmt.Sprintf("%s/%s", n.Namespace, n.Name) 57 | } 58 | -------------------------------------------------------------------------------- /pkg/controller/util/resourceclient.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 util 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "k8s.io/client-go/dynamic" 23 | "k8s.io/client-go/rest" 24 | ) 25 | 26 | type ResourceClient interface { 27 | Resources(namespace string) dynamic.ResourceInterface 28 | Kind() string 29 | } 30 | 31 | type resourceClient struct { 32 | client dynamic.Interface 33 | apiResource schema.GroupVersionResource 34 | namespaced bool 35 | kind string 36 | } 37 | 38 | func NewResourceClient(config *rest.Config, apiResource *metav1.APIResource) (ResourceClient, error) { 39 | resource := schema.GroupVersionResource{ 40 | Group: apiResource.Group, 41 | Version: apiResource.Version, 42 | Resource: apiResource.Name, 43 | } 44 | client, err := dynamic.NewForConfig(config) 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | return &resourceClient{ 50 | client: client, 51 | apiResource: resource, 52 | namespaced: apiResource.Namespaced, 53 | kind: apiResource.Kind, 54 | }, nil 55 | } 56 | 57 | func (c *resourceClient) Resources(namespace string) dynamic.ResourceInterface { 58 | // TODO(marun) Consider returning Interface instead of 59 | // ResourceInterface to allow callers to decide if they want to 60 | // invoke Namespace(). Either that, or replace the use of 61 | // ResourceClient with the controller-runtime generic client. 62 | if c.namespaced { 63 | return c.client.Resource(c.apiResource).Namespace(namespace) 64 | } 65 | return c.client.Resource(c.apiResource) 66 | } 67 | 68 | func (c *resourceClient) Kind() string { 69 | return c.kind 70 | } 71 | -------------------------------------------------------------------------------- /pkg/controller/util/safe_map.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 util 18 | 19 | import ( 20 | "sync" 21 | ) 22 | 23 | type SafeMap struct { 24 | sync.RWMutex 25 | m map[string]interface{} 26 | } 27 | 28 | func NewSafeMap() *SafeMap { 29 | return &SafeMap{ 30 | m: make(map[string]interface{}), 31 | } 32 | } 33 | 34 | func (s *SafeMap) Store(key string, value interface{}) { 35 | s.Lock() 36 | defer s.Unlock() 37 | s.m[key] = value 38 | } 39 | 40 | func (s *SafeMap) Get(key string) (interface{}, bool) { 41 | s.RLock() 42 | defer s.RUnlock() 43 | value, ok := s.m[key] 44 | return value, ok 45 | } 46 | 47 | func (s *SafeMap) GetAll() []interface{} { 48 | s.RLock() 49 | defer s.RUnlock() 50 | vals := []interface{}{} 51 | for _, val := range s.m { 52 | vals = append(vals, val) 53 | } 54 | return vals 55 | } 56 | 57 | func (s *SafeMap) Delete(key string) { 58 | s.Lock() 59 | defer s.Unlock() 60 | delete(s.m, key) 61 | } 62 | 63 | func (s *SafeMap) DeleteAll() { 64 | s.Lock() 65 | defer s.Unlock() 66 | for key := range s.m { 67 | delete(s.m, key) 68 | } 69 | } 70 | 71 | func (s *SafeMap) Size() int { 72 | s.Lock() 73 | defer s.Unlock() 74 | return len(s.m) 75 | } 76 | -------------------------------------------------------------------------------- /pkg/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 pkg 18 | -------------------------------------------------------------------------------- /pkg/features/features.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 features 18 | 19 | import ( 20 | utilfeature "k8s.io/apiserver/pkg/util/feature" 21 | "k8s.io/component-base/featuregate" 22 | "k8s.io/klog/v2" 23 | ) 24 | 25 | const ( 26 | // Every feature gate should add method here following this template: 27 | // 28 | // // owner: @username 29 | // // alpha: v1.X 30 | // MyFeature featuregate.Feature = "MyFeature" 31 | 32 | // owner: @marun 33 | // alpha: v0.1 34 | // 35 | // PushReconciler ensures that managed resources in member clusters represent the state declared in federated resources. 36 | PushReconciler featuregate.Feature = "PushReconciler" 37 | 38 | // owner: @irfanurrehman 39 | // alpha: v0.1 40 | // 41 | // Scheduler controllers which dynamically schedules workloads based on user preferences. 42 | SchedulerPreferences featuregate.Feature = "SchedulerPreferences" 43 | 44 | // owner: @hectorj2f 45 | // beta: v0.5 46 | // 47 | // RawResourceStatusCollection enables the collection of the status of target types when enabled 48 | RawResourceStatusCollection featuregate.Feature = "RawResourceStatusCollection" 49 | ) 50 | 51 | func init() { 52 | if err := utilfeature.DefaultMutableFeatureGate.Add(DefaultKubeFedFeatureGates); err != nil { 53 | klog.Fatalf("Unexpected error: %v", err) 54 | } 55 | } 56 | 57 | // DefaultKubeFedFeatureGates consists of all known KubeFed-specific 58 | // feature keys. To add a new feature, define a key for it above and 59 | // add it here. 60 | var DefaultKubeFedFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ 61 | SchedulerPreferences: {Default: true, PreRelease: featuregate.Alpha}, 62 | PushReconciler: {Default: true, PreRelease: featuregate.Beta}, 63 | RawResourceStatusCollection: {Default: false, PreRelease: featuregate.Beta}, 64 | } 65 | -------------------------------------------------------------------------------- /pkg/kubefedctl/enable/deprecatedapis_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 enable 18 | 19 | import ( 20 | "testing" 21 | 22 | fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1" 23 | ) 24 | 25 | func TestIsEquivalentAPI(t *testing.T) { 26 | for k, gvs := range equivalentAPIs { 27 | baseAPI := fedv1b1.APIResource{ 28 | PluralName: k, 29 | Group: gvs[0].Group, 30 | Version: gvs[0].Version, 31 | } 32 | 33 | for _, gv := range gvs[1:] { 34 | api := fedv1b1.APIResource{ 35 | PluralName: k, 36 | Group: gv.Group, 37 | Version: gv.Version, 38 | } 39 | 40 | if !IsEquivalentAPI(&baseAPI, &api) { 41 | t.Fatalf("An unexpected error occurred: %q and %q should be equivalent.", baseAPI, api) 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/kubefedctl/enable/directive.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 enable 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | 22 | "sigs.k8s.io/kubefed/pkg/kubefedctl/options" 23 | ) 24 | 25 | // EnableTypeDirectiveSpec defines the desired state of EnableTypeDirective. 26 | type EnableTypeDirectiveSpec struct { 27 | // The API version of the target type. 28 | // +optional 29 | TargetVersion string `json:"targetVersion,omitempty"` 30 | 31 | // The name of the API group to use for generated federated types. 32 | // +optional 33 | FederatedGroup string `json:"federatedGroup,omitempty"` 34 | 35 | // The API version to use for generated federated types. 36 | // +optional 37 | FederatedVersion string `json:"federatedVersion,omitempty"` 38 | } 39 | 40 | // TODO(marun) This should become a proper API type and drive enabling 41 | // type federation via a controller. For now its only purpose is to 42 | // enable loading of configuration from disk. 43 | type EnableTypeDirective struct { 44 | metav1.TypeMeta `json:",inline"` 45 | metav1.ObjectMeta `json:"metadata,omitempty"` 46 | 47 | Spec EnableTypeDirectiveSpec `json:"spec,omitempty"` 48 | } 49 | 50 | func (ft *EnableTypeDirective) SetDefaults() { 51 | ft.Spec.FederatedGroup = options.DefaultFederatedGroup 52 | ft.Spec.FederatedVersion = options.DefaultFederatedVersion 53 | } 54 | 55 | func NewEnableTypeDirective() *EnableTypeDirective { 56 | ft := &EnableTypeDirective{} 57 | ft.SetDefaults() 58 | return ft 59 | } 60 | -------------------------------------------------------------------------------- /pkg/kubefedctl/util/yaml_writer.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 util 18 | 19 | import ( 20 | "io" 21 | 22 | "github.com/ghodss/yaml" 23 | "github.com/pkg/errors" 24 | 25 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 26 | ) 27 | 28 | func WriteUnstructuredToYaml(unstructuredObj *unstructured.Unstructured, w io.Writer) error { 29 | // If status is included in the yaml, attempting to create it in a 30 | // kube API will cause an error. 31 | obj := unstructuredObj.DeepCopy() 32 | unstructured.RemoveNestedField(obj.Object, "status") 33 | unstructured.RemoveNestedField(obj.Object, "metadata", "creationTimestamp") 34 | 35 | errMsg := "Error encoding unstructured object to yaml" 36 | objJSON, err := obj.MarshalJSON() 37 | if err != nil { 38 | return errors.Wrap(err, errMsg) 39 | } 40 | 41 | data, err := yaml.JSONToYAML(objJSON) 42 | if err != nil { 43 | return errors.Wrap(err, errMsg) 44 | } 45 | _, err = w.Write(data) 46 | if err != nil { 47 | return errors.Wrap(err, errMsg) 48 | } 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/kubefedctl/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 kubefedctl 18 | 19 | import ( 20 | "fmt" 21 | "io" 22 | 23 | "github.com/spf13/cobra" 24 | 25 | "sigs.k8s.io/kubefed/pkg/version" 26 | ) 27 | 28 | var ( 29 | versionLong = ` 30 | Version prints the version info of this command.` 31 | versionExample = ` 32 | # Print kubefed command version 33 | kubefed version` 34 | ) 35 | 36 | // NewCmdVersion prints out the release version info for this command binary. 37 | func NewCmdVersion(out io.Writer) *cobra.Command { 38 | cmd := &cobra.Command{ 39 | Use: "version", 40 | Short: "Print the version info", 41 | Long: versionLong, 42 | Example: versionExample, 43 | Run: func(cmd *cobra.Command, args []string) { 44 | fmt.Fprintf(out, "kubefedctl version: %s\n", fmt.Sprintf("%#v", version.Get())) 45 | }, 46 | } 47 | 48 | return cmd 49 | } 50 | -------------------------------------------------------------------------------- /pkg/schedulingtypes/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 schedulingtypes 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 22 | 23 | "sigs.k8s.io/kubefed/pkg/apis/core/typeconfig" 24 | "sigs.k8s.io/kubefed/pkg/controller/util" 25 | ) 26 | 27 | type Scheduler interface { 28 | SchedulingKind() string 29 | ObjectType() runtimeclient.Object 30 | 31 | Start() 32 | HasSynced() bool 33 | Stop() 34 | Reconcile(obj runtimeclient.Object, qualifiedName util.QualifiedName) util.ReconciliationStatus 35 | 36 | StartPlugin(typeConfig typeconfig.Interface, nsAPIResource *metav1.APIResource) error 37 | StopPlugin(kind string) 38 | } 39 | 40 | type SchedulerEventHandlers struct { 41 | KubeFedEventHandler func(runtimeclient.Object) 42 | ClusterEventHandler func(runtimeclient.Object) 43 | ClusterLifecycleHandlers *util.ClusterLifecycleHandlerFuncs 44 | } 45 | 46 | type SchedulerFactory func(controllerConfig *util.ControllerConfig, eventHandlers SchedulerEventHandlers) (Scheduler, error) 47 | -------------------------------------------------------------------------------- /pkg/schedulingtypes/resources.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 schedulingtypes 18 | 19 | import ( 20 | "reflect" 21 | "strings" 22 | 23 | corev1 "k8s.io/api/core/v1" 24 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 26 | ) 27 | 28 | var ( 29 | Pod = GetResourceKind(&corev1.Pod{}) 30 | ) 31 | 32 | var PodResource = &metav1.APIResource{ 33 | Name: GetPluralName(Pod), 34 | Group: corev1.SchemeGroupVersion.Group, 35 | Version: corev1.SchemeGroupVersion.Version, 36 | Kind: Pod, 37 | Namespaced: true, 38 | } 39 | 40 | func GetResourceKind(obj runtimeclient.Object) string { 41 | t := reflect.TypeOf(obj) 42 | if t.Kind() != reflect.Ptr { 43 | panic("All types must be pointers to structs.") 44 | } 45 | 46 | t = t.Elem() 47 | return t.Name() 48 | } 49 | 50 | func GetPluralName(name string) string { 51 | return strings.ToLower(name) + "s" 52 | } 53 | -------------------------------------------------------------------------------- /pkg/schedulingtypes/typeregistry.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 schedulingtypes 18 | 19 | import ( 20 | "fmt" 21 | ) 22 | 23 | type SchedulingType struct { 24 | Kind string 25 | SchedulerFactory SchedulerFactory 26 | } 27 | 28 | // Mapping of qualified target name (e.g. deployment.apps) targeted 29 | // for scheduling with scheduling type 30 | var typeRegistry = make(map[string]SchedulingType) 31 | 32 | func RegisterSchedulingType(kind string, schedulingType SchedulingType) { 33 | existing, ok := typeRegistry[kind] 34 | if ok { 35 | panic(fmt.Sprintf("Kind %q is already registered for scheduling with %q", kind, existing.Kind)) 36 | } 37 | typeRegistry[kind] = schedulingType 38 | } 39 | 40 | func SchedulingTypes() map[string]SchedulingType { 41 | result := make(map[string]SchedulingType) 42 | for key, value := range typeRegistry { 43 | result[key] = value 44 | } 45 | return result 46 | } 47 | 48 | func GetSchedulingType(kind string) *SchedulingType { 49 | schedulingType, ok := typeRegistry[kind] 50 | if ok { 51 | return &schedulingType 52 | } 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /pkg/version/base.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 version 18 | 19 | // Base version information. 20 | // 21 | // This is the fallback data used when version information from git is not 22 | // provided via go ldflags (via Makefile). 23 | var ( 24 | version = "v0.0.1-alpha.0" // output of "git describe" 25 | // the prerequisite is that the branch should be 26 | // tagged using the correct versioning strategy. 27 | 28 | gitCommit = "unknown" // sha1 from git, output of $(git rev-parse HEAD) 29 | gitTreeState = "unknown" // state of git tree, either "clean" or "dirty" 30 | 31 | buildDate = "unknown" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') 32 | ) 33 | -------------------------------------------------------------------------------- /pkg/version/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 version 18 | 19 | import ( 20 | "fmt" 21 | "runtime" 22 | ) 23 | 24 | type Info struct { 25 | Version string `json:"gitVersion"` 26 | GitCommit string `json:"gitCommit"` 27 | GitTreeState string `json:"gitTreeState"` 28 | BuildDate string `json:"buildDate"` 29 | GoVersion string `json:"goVersion"` 30 | Compiler string `json:"compiler"` 31 | Platform string `json:"platform"` 32 | } 33 | 34 | // Get returns the overall codebase version. It's for detecting 35 | // what code a binary was built from. 36 | func Get() Info { 37 | // These variables typically come from -ldflags settings and in 38 | // their absence fallback to the settings in pkg/version/base.go 39 | return Info{ 40 | Version: version, 41 | GitCommit: gitCommit, 42 | GitTreeState: gitTreeState, 43 | BuildDate: buildDate, 44 | GoVersion: runtime.Version(), 45 | Compiler: runtime.Compiler, 46 | Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /scripts/check-directive-fixtures.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This script ensures that enable type directives are not merged to 18 | # the tree without corresponding fixture to ensure federation of the 19 | # target type will be tested. 20 | 21 | set -o errexit 22 | set -o nounset 23 | set -o pipefail 24 | 25 | ROOT_DIR="$(cd "$(dirname "$0")/.." ; pwd)" 26 | 27 | function check-directive-fixtures() { 28 | local directives=( "${ROOT_DIR}/config/enabletypedirectives/"*.yaml ) 29 | for file in "${directives[@]}"; do 30 | local filename="$(basename "${file}")" 31 | local expected_file="${ROOT_DIR}/test/common/fixtures/${filename}" 32 | if [[ ! -f "${expected_file}" ]]; then 33 | echo "Fixture is missing for ${file}" >&2 34 | echo "Please add fixture with filename ${expected_file}" >&2 35 | exit 1 36 | fi 37 | done 38 | } 39 | 40 | check-directive-fixtures 41 | -------------------------------------------------------------------------------- /scripts/delete-clusters.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This script handles the deletion of multiple clusters using kind as well as 18 | # the deletion of the container registry. 19 | 20 | set -o errexit 21 | set -o nounset 22 | set -o pipefail 23 | 24 | NUM_CLUSTERS="${NUM_CLUSTERS:-2}" 25 | 26 | function delete-clusters() { 27 | local num_clusters=${1} 28 | 29 | for i in $(seq "${num_clusters}"); do 30 | # The context name has been changed when creating clusters by 'create-cluster.sh'. 31 | # This will result in the context can't be removed by kind when deleting a cluster. 32 | # So, we need to change context name back and let kind take care about it. 33 | kubectl config rename-context "cluster${i}" "kind-cluster${i}" 34 | 35 | kind delete cluster --name "cluster${i}" 36 | done 37 | } 38 | 39 | echo "Deleting ${NUM_CLUSTERS} clusters" 40 | delete-clusters "${NUM_CLUSTERS}" 41 | 42 | echo "Complete" 43 | -------------------------------------------------------------------------------- /scripts/deploy-kubefed-latest.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | 21 | # Call the deploy script with the name of the latest image. 22 | "$(dirname "${BASH_SOURCE}")"/deploy-kubefed.sh quay.io/kubernetes-multicluster/kubefed:latest "${@}" 23 | -------------------------------------------------------------------------------- /scripts/download-e2e-binaries.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This script automates the download of e2e binaries used in testing of 18 | # KubeFed. 19 | 20 | set -o errexit 21 | set -o nounset 22 | set -o pipefail 23 | 24 | logEnd() { 25 | local msg='done.' 26 | [ "$1" -eq 0 ] || msg='Error downloading assets' 27 | echo "$msg" 28 | } 29 | trap 'logEnd $?' EXIT 30 | 31 | echo "About to download some binaries. This might take a while..." 32 | 33 | root_dir="$(cd "$(dirname "$0")/.." ; pwd)" 34 | dest_dir="${root_dir}/bin" 35 | mkdir -p "${dest_dir}" 36 | 37 | # kind 38 | platform="$(uname -s|tr A-Z a-z)" 39 | kind_version="v0.14.0" 40 | kind_path="${dest_dir}/kind" 41 | kind_url="https://github.com/kubernetes-sigs/kind/releases/download/${kind_version}/kind-${platform}-amd64" 42 | curl -fLo "${kind_path}" "${kind_url}" && chmod +x "${kind_path}" 43 | 44 | # Pull the busybox image (used in tests of workload types) 45 | docker pull busybox 46 | 47 | echo "# kind installation: ${kind_path}" 48 | -------------------------------------------------------------------------------- /scripts/fix-ca-for-k3s.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Usage: 18 | # % ./scripts/fix-ca-for-k3s.sh [member-cluster] ... 19 | # 20 | # Description: 21 | # This script fixes up the configuration for member clusters 22 | # running older versions of k3s (< v0.7.0). (https://k3s.io/) 23 | # Namely it updates caBundle for the member clusters to match with 24 | # the ones in KUBECONFIG. It's intended to be run after joining 25 | # member clusters successfully. 26 | # Note that this is not necessary for k3s v0.7.0. 27 | # 28 | # Background: 29 | # In k3s < v0.7.0, different endpoints and certificates are configured for 30 | # users (KUBECONFIG) and pods (service accounts). 31 | # Because "kubefedctl join" uses the endpoint from KUBECONFIG and 32 | # the certificate from a service account in the member cluster, 33 | # the kubefed controller manager fails to communicate with the 34 | # member clusters, producing the messages like the following. 35 | # 36 | # x509: certificate signed by unknown authority 37 | # 38 | # k3s v0.7.0 has been changed to use the same CA cert to sign them. [1] 39 | # Thus this workaround is no longer necessary. 40 | # [1] https://github.com/rancher/k3s/commit/2c9444399b427ffb706818f5bf3892a8880673bf 41 | 42 | set -o errexit 43 | set -o nounset 44 | set -o pipefail 45 | 46 | CLUSTER_NAMES="${*-}" 47 | NS="${KUBEFED_NAMESPACE:-kube-federation-system}" 48 | 49 | for CLUSTER_NAME in $CLUSTER_NAMES; do 50 | CA_CRT=$(kubectl config view --raw -o jsonpath='{.clusters[?(@.name=="'"${CLUSTER_NAME}"'")].cluster.certificate-authority-data}') 51 | kubectl patch -n ${NS} kubefedclusters "${CLUSTER_NAME}" \ 52 | --type='merge' \ 53 | --patch '{"spec": {"caBundle": "'${CA_CRT}'"}}' 54 | done 55 | 56 | # Restart the controller manager to make it reload the caBundle 57 | kubectl delete -n ${NS} po -l control-plane=controller-manager 58 | -------------------------------------------------------------------------------- /scripts/fix-joined-kind-clusters.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | 21 | # This script updates APIEndpoints of KubeFedCluster resources for 22 | # Docker on MacOS. 23 | # 24 | # By default, `https://:6443` is used to ensure 25 | # compatibility with control plane components running in a kind 26 | # cluster. 27 | # 28 | # If LOCAL_TESTING is set, the api endpoint defined in the local 29 | # kubeconfig is used to ensure compatibility with control plane 30 | # components run in-memory by local e2e tests. 31 | LOCAL_TESTING="${LOCAL_TESTING:-}" 32 | 33 | if [ "`uname`" != 'Darwin' ]; then 34 | >&2 echo "This script is only intended for use on MacOS" 35 | exit 1 36 | fi 37 | 38 | NS="${KUBEFED_NAMESPACE:-kube-federation-system}" 39 | 40 | INSPECT_PATH='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 41 | 42 | CLUSTERS="$(kubectl get kubefedclusters -n "${NS}" -o jsonpath='{range .items[*]}{.metadata.name}{" "}{end}')" 43 | for cluster in ${CLUSTERS}; 44 | do 45 | if [[ "${LOCAL_TESTING}" ]]; then 46 | ENDPOINT="$(kubectl config view -o jsonpath='{.clusters[?(@.name == "'"${cluster}"'")].cluster.server}')" 47 | else 48 | IP_ADDR="$(docker inspect -f "${INSPECT_PATH}" "${cluster}-control-plane")" 49 | ENDPOINT="https://${IP_ADDR}:6443" 50 | fi 51 | kubectl patch kubefedclusters -n "${NS}" "${cluster}" --type merge \ 52 | --patch "{\"spec\":{\"apiEndpoint\":\"${ENDPOINT}\"}}" 53 | done 54 | -------------------------------------------------------------------------------- /scripts/update-bindata.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This script ensures that enable type directives are not merged to 18 | # the tree without corresponding fixture to ensure federation of the 19 | # target type will be tested. 20 | 21 | set -o errexit 22 | set -o nounset 23 | set -o pipefail 24 | 25 | ROOT_DIR="$(cd "$(dirname "$0")/.." ; pwd)" 26 | 27 | cd "${ROOT_DIR}" 28 | 29 | if [ ! -x "${ROOT_DIR}"/bin/go-bindata ]; then 30 | echo "go-bindata is not found. Use './scripts/download-binaries.sh' to download it." 31 | exit 1 32 | fi 33 | 34 | "${ROOT_DIR}"/bin/go-bindata \ 35 | -nocompress \ 36 | -nometadata \ 37 | -pkg 'common' \ 38 | -o test/common/bindata.go \ 39 | test/common/fixtures \ 40 | config/kubefedconfig.yaml \ 41 | config/enabletypedirectives 42 | 43 | cat ./hack/boilerplate.go.txt ./test/common/bindata.go > bindatatmp \ 44 | && mv bindatatmp ./test/common/bindata.go 45 | -------------------------------------------------------------------------------- /staticcheck.conf: -------------------------------------------------------------------------------- 1 | checks = ["all"] 2 | -------------------------------------------------------------------------------- /test/common/fixtures.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | "bytes" 21 | "strings" 22 | 23 | "github.com/pkg/errors" 24 | 25 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 26 | 27 | kfenable "sigs.k8s.io/kubefed/pkg/kubefedctl/enable" 28 | ) 29 | 30 | var fixtures map[string]*unstructured.Unstructured 31 | 32 | func TypeConfigFixturesOrDie(tl TestLogger) map[string]*unstructured.Unstructured { 33 | if fixtures == nil { 34 | var err error 35 | fixtures, err = typeConfigFixtures() 36 | if err != nil { 37 | tl.Fatalf("Error loading type config fixtures: %v", err) 38 | } 39 | } 40 | return fixtures 41 | } 42 | 43 | func typeConfigFixtures() (map[string]*unstructured.Unstructured, error) { 44 | fixtures := make(map[string]*unstructured.Unstructured) 45 | for _, file := range AssetNames() { 46 | fixture := &unstructured.Unstructured{} 47 | typeConfigName, err := DecodeYamlFromBindata(file, "test/common/fixtures/", fixture) 48 | if err != nil { 49 | return nil, errors.Wrapf(err, "Error reading a fixture from %q", typeConfigName) 50 | } 51 | if len(typeConfigName) != 0 { 52 | fixtures[typeConfigName] = fixture 53 | } 54 | } 55 | 56 | return fixtures, nil 57 | } 58 | 59 | func DecodeYamlFromBindata(filename, prefix string, obj interface{}) (string, error) { 60 | if !strings.HasPrefix(filename, prefix) { 61 | return "", nil 62 | } 63 | yaml := MustAsset(filename) 64 | name := strings.TrimSuffix(strings.TrimPrefix(filename, prefix), ".yaml") 65 | err := kfenable.DecodeYAML(bytes.NewBuffer(yaml), obj) 66 | if err != nil { 67 | return "", err 68 | } 69 | return name, nil 70 | } 71 | -------------------------------------------------------------------------------- /test/common/fixtures/clusterroles.rbac.authorization.k8s.io.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | rules: 4 | - apiGroups: 5 | - '*' 6 | resources: 7 | - '*' 8 | verbs: 9 | - '*' 10 | -------------------------------------------------------------------------------- /test/common/fixtures/configmaps.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | data: 4 | foo: bar 5 | overrides: 6 | - clusterOverrides: 7 | - path: /data 8 | value: 9 | foo: baz 10 | -------------------------------------------------------------------------------- /test/common/fixtures/deployments.apps.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | spec: 4 | replicas: 2 5 | selector: 6 | matchLabels: 7 | foo: bar 8 | template: 9 | metadata: 10 | labels: 11 | foo: bar 12 | spec: 13 | terminationGracePeriodSeconds: 0 14 | containers: 15 | - name: busybox 16 | image: busybox 17 | command: ["/bin/sh", "-c", "trap : TERM INT; (while true; do sleep 1000; done) & wait"] 18 | overrides: 19 | - clusterOverrides: 20 | - path: /spec/replicas 21 | value: 1 22 | - path: "/spec/template/spec/containers/0/image" 23 | value: "busybox:1.31.0-uclibc" 24 | -------------------------------------------------------------------------------- /test/common/fixtures/ingresses.networking.k8s.io.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | spec: 4 | defaultBackend: 5 | service: 6 | name: testsvc 7 | port: 8 | number: 80 9 | -------------------------------------------------------------------------------- /test/common/fixtures/jobs.batch.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | spec: 4 | parallelism: 1 5 | selector: 6 | matchLabels: 7 | foo: bar 8 | manualSelector: true 9 | template: 10 | metadata: 11 | labels: 12 | foo: bar 13 | spec: 14 | terminationGracePeriodSeconds: 0 15 | restartPolicy: Never 16 | containers: 17 | - name: busybox 18 | image: busybox 19 | command: ["/bin/sh", "-c", "trap : TERM INT; (while true; do sleep 1000; done) & wait"] 20 | overrides: 21 | - clusterOverrides: 22 | - path: /spec/parallelism 23 | value: 2 24 | -------------------------------------------------------------------------------- /test/common/fixtures/namespaces.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | -------------------------------------------------------------------------------- /test/common/fixtures/replicasets.apps.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | spec: 4 | replicas: 1 5 | selector: 6 | matchLabels: 7 | foo: bar 8 | template: 9 | metadata: 10 | labels: 11 | foo: bar 12 | spec: 13 | terminationGracePeriodSeconds: 0 14 | containers: 15 | - name: busybox 16 | image: busybox 17 | command: ["/bin/sh", "-c", "trap : TERM INT; (while true; do sleep 1000; done) & wait"] 18 | overrides: 19 | - clusterOverrides: 20 | - path: /spec/replicas 21 | value: 2 22 | -------------------------------------------------------------------------------- /test/common/fixtures/secrets.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | data: 4 | foo: YmFy 5 | type: Opaque 6 | overrides: 7 | - clusterOverrides: 8 | - path: /data 9 | value: 10 | foo: YmF6 11 | -------------------------------------------------------------------------------- /test/common/fixtures/serviceaccounts.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | automountServiceAccountToken: true 4 | -------------------------------------------------------------------------------- /test/common/fixtures/services.yaml: -------------------------------------------------------------------------------- 1 | kind: fixture 2 | template: 3 | spec: 4 | type: ClusterIP 5 | ports: 6 | - name: http 7 | port: 80 8 | -------------------------------------------------------------------------------- /test/common/resource_helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes 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 | "context" 21 | "fmt" 22 | 23 | "github.com/pkg/errors" 24 | 25 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 27 | restclient "k8s.io/client-go/rest" 28 | 29 | "sigs.k8s.io/kubefed/pkg/controller/util" 30 | ) 31 | 32 | func CreateResource(kubeconfig *restclient.Config, apiResource metav1.APIResource, desiredObj *unstructured.Unstructured) (*unstructured.Unstructured, error) { 33 | namespace := desiredObj.GetNamespace() 34 | kind := apiResource.Kind 35 | resourceMsg := kind 36 | if len(namespace) > 0 { 37 | resourceMsg = fmt.Sprintf("%s in namespace %q", resourceMsg, namespace) 38 | } 39 | 40 | client, err := util.NewResourceClient(kubeconfig, &apiResource) 41 | if err != nil { 42 | return nil, errors.Wrapf(err, "Error creating resource client") 43 | } 44 | obj, err := client.Resources(namespace).Create(context.Background(), desiredObj, metav1.CreateOptions{}) 45 | if err != nil { 46 | return nil, errors.Wrapf(err, "Error creating %s", resourceMsg) 47 | } 48 | 49 | return obj, nil 50 | } 51 | -------------------------------------------------------------------------------- /test/common/typeconfig.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes 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 | "context" 21 | 22 | runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" 23 | 24 | "sigs.k8s.io/kubefed/pkg/apis/core/typeconfig" 25 | fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1" 26 | client "sigs.k8s.io/kubefed/pkg/client/generic" 27 | ) 28 | 29 | func GetTypeConfig(genericClient client.Client, name, namespace string) (typeconfig.Interface, error) { 30 | typeConfig := &fedv1b1.FederatedTypeConfig{} 31 | err := genericClient.Get(context.Background(), typeConfig, namespace, name) 32 | if err != nil { 33 | return nil, err 34 | } 35 | 36 | return typeConfig, nil 37 | } 38 | 39 | func EnableStatusCollection(genericClient client.Client, typeConfig *fedv1b1.FederatedTypeConfig) error { 40 | patch := runtimeclient.MergeFrom(typeConfig.DeepCopy()) 41 | statusCollection := fedv1b1.StatusCollectionEnabled 42 | typeConfig.Spec.StatusCollection = &statusCollection 43 | 44 | err := genericClient.Patch(context.Background(), typeConfig, patch) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /test/e2e/deleteoptions.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Kubernetes 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 e2e 18 | 19 | import ( 20 | . "github.com/onsi/ginkgo" //nolint:stylecheck 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "sigs.k8s.io/controller-runtime/pkg/client" 23 | 24 | "sigs.k8s.io/kubefed/test/common" 25 | "sigs.k8s.io/kubefed/test/e2e/framework" 26 | ) 27 | 28 | var typeConfigName = "deployments.apps" 29 | 30 | var _ = Describe("DeleteOptions", func() { 31 | f := framework.NewKubeFedFramework("delete-options") 32 | 33 | tl := framework.NewE2ELogger() 34 | 35 | typeConfigFixtures := common.TypeConfigFixturesOrDie(tl) 36 | 37 | fixture := typeConfigFixtures[typeConfigName] 38 | 39 | It("Deployment should be created and deleted successfully, but ReplicaSet that created by Deployment won't be deleted", func() { 40 | 41 | typeConfig, testObjectsFunc := getCrudTestInput(f, tl, typeConfigName, fixture) 42 | crudTester, targetObject, overrides := initCrudTest(f, tl, f.KubeFedSystemNamespace(), typeConfig, testObjectsFunc) 43 | fedObject := crudTester.CheckCreate(targetObject, overrides, nil) 44 | 45 | By("Set PropagationPolicy property as 'Orphan' on the DeleteOptions for Federated Deployment") 46 | orphan := metav1.DeletePropagationOrphan 47 | prop := client.PropagationPolicy(orphan) 48 | 49 | crudTester.SetDeleteOption(fedObject, prop) 50 | 51 | crudTester.CheckDelete(fedObject, false) 52 | 53 | By("Checking ReplicatSet stutus for every cluster") 54 | crudTester.CheckReplicaSet(targetObject) 55 | }) 56 | }) 57 | -------------------------------------------------------------------------------- /test/e2e/e2e_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 e2e 18 | 19 | import ( 20 | "os" 21 | "testing" 22 | 23 | _ "k8s.io/client-go/plugin/pkg/client/auth" // Load all client auth plugins for GCP, Azure, etc 24 | 25 | "sigs.k8s.io/kubefed/test/e2e/framework" 26 | ) 27 | 28 | func TestMain(m *testing.M) { 29 | framework.ParseFlags() 30 | os.Exit(m.Run()) 31 | } 32 | 33 | func TestE2E(t *testing.T) { 34 | RunE2ETests(t) 35 | } 36 | -------------------------------------------------------------------------------- /test/e2e/framework/cleanup.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 framework 18 | 19 | import ( 20 | "sync" 21 | ) 22 | 23 | type CleanupActionHandle *int 24 | 25 | var cleanupActionsLock sync.Mutex 26 | var cleanupActions = map[CleanupActionHandle]func(){} 27 | 28 | // AddCleanupAction installs a function that will be called in the event of the 29 | // whole test being terminated. This allows arbitrary pieces of the overall 30 | // test to hook into SynchronizedAfterSuite(). 31 | func AddCleanupAction(fn func()) CleanupActionHandle { 32 | p := CleanupActionHandle(new(int)) 33 | cleanupActionsLock.Lock() 34 | defer cleanupActionsLock.Unlock() 35 | cleanupActions[p] = fn 36 | return p 37 | } 38 | 39 | // RemoveCleanupAction removes a function that was installed by 40 | // AddCleanupAction. 41 | func RemoveCleanupAction(p CleanupActionHandle) { 42 | cleanupActionsLock.Lock() 43 | defer cleanupActionsLock.Unlock() 44 | delete(cleanupActions, p) 45 | } 46 | 47 | // RunCleanupActions runs all functions installed by AddCleanupAction. It does 48 | // not remove them (see RemoveCleanupAction) but it does run unlocked, so they 49 | // may remove themselves. 50 | func RunCleanupActions() { 51 | list := []func(){} 52 | func() { 53 | cleanupActionsLock.Lock() 54 | defer cleanupActionsLock.Unlock() 55 | for _, fn := range cleanupActions { 56 | list = append(list, fn) 57 | } 58 | }() 59 | // Run unlocked. 60 | for _, fn := range list { 61 | fn() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/e2e/framework/enable.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 framework 18 | 19 | import ( 20 | kfenable "sigs.k8s.io/kubefed/pkg/kubefedctl/enable" 21 | "sigs.k8s.io/kubefed/test/common" 22 | ) 23 | 24 | func LoadEnableTypeDirectives(tl common.TestLogger) []*kfenable.EnableTypeDirective { 25 | enableTypeDirectives := []*kfenable.EnableTypeDirective{} 26 | for _, file := range common.AssetNames() { 27 | obj := kfenable.NewEnableTypeDirective() 28 | filename, err := common.DecodeYamlFromBindata(file, "config/enabletypedirectives/", obj) 29 | if err != nil { 30 | tl.Fatalf("Error loading EnableTypeDirective from this file %q: %v", filename, err) 31 | } 32 | if len(filename) != 0 { 33 | enableTypeDirectives = append(enableTypeDirectives, obj) 34 | } 35 | } 36 | return enableTypeDirectives 37 | } 38 | -------------------------------------------------------------------------------- /test/e2e/framework/logger.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 framework 18 | 19 | import ( 20 | "sigs.k8s.io/kubefed/test/common" 21 | ) 22 | 23 | type e2eLogger struct{} 24 | 25 | func NewE2ELogger() common.TestLogger { 26 | return e2eLogger{} 27 | } 28 | 29 | func (e2eLogger) Errorf(format string, args ...interface{}) { 30 | Errorf(format, args...) 31 | } 32 | 33 | func (e2eLogger) Fatal(args ...interface{}) { 34 | // TODO(marun) Is there a nicer way to do this? 35 | FailfWithOffset(1, "%v", args) 36 | } 37 | 38 | func (e2eLogger) Fatalf(format string, args ...interface{}) { 39 | FailfWithOffset(1, format, args...) 40 | } 41 | 42 | func (e2eLogger) Log(args ...interface{}) { 43 | // TODO(marun) Is there a nicer way to do this? 44 | Logf("%v", args) 45 | } 46 | 47 | func (e2eLogger) Logf(format string, args ...interface{}) { 48 | Logf(format, args...) 49 | } 50 | -------------------------------------------------------------------------------- /test/e2e/kubefedcluster.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "fmt" 5 | 6 | "k8s.io/client-go/discovery" 7 | restclient "k8s.io/client-go/rest" 8 | 9 | "sigs.k8s.io/kubefed/pkg/controller/util" 10 | "sigs.k8s.io/kubefed/test/e2e/framework" 11 | 12 | . "github.com/onsi/ginkgo" //nolint:stylecheck 13 | . "github.com/onsi/gomega" //nolint:stylecheck 14 | ) 15 | 16 | var _ = Describe("KubeFedCluster", func() { 17 | f := framework.NewKubeFedFramework("kubefedcluster") 18 | 19 | tl := framework.NewE2ELogger() 20 | 21 | It("should correctly report the Kubernetes git version of the cluster", func() { 22 | userAgent := "test-kubefedcluster-kubernetes-version" 23 | client := f.Client(userAgent) 24 | clusterList := framework.ListKubeFedClusters(tl, client, framework.TestContext.KubeFedSystemNamespace) 25 | 26 | for _, cluster := range clusterList.Items { 27 | config, err := util.BuildClusterConfig(&cluster, client, framework.TestContext.KubeFedSystemNamespace) 28 | Expect(err).NotTo(HaveOccurred()) 29 | restclient.AddUserAgent(config, userAgent) 30 | 31 | client, err := discovery.NewDiscoveryClientForConfig(config) 32 | if err != nil { 33 | tl.Fatalf("Error creating discovery client for cluster %q", cluster.Name) 34 | } 35 | version, err := client.ServerVersion() 36 | if err != nil { 37 | tl.Fatalf("Error retrieving Kubernetes version of cluster %q", cluster.Name) 38 | } 39 | Expect(cluster.Status.KubernetesVersion).To(Equal(version.GitVersion), fmt.Sprintf( 40 | "the KubernetesVersion field of KubeFedCluster %q should be equal to the Kubernetes git version of the cluster", cluster.Name)) 41 | } 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.bazelignore: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.bazelrc: -------------------------------------------------------------------------------- 1 | build --verbose_failures 2 | test --test_output=errors 3 | 4 | # TODO(fejta): figure out why this causes problems 5 | #test --features=race # enable data race detection 6 | 7 | # Note needs an instance name 8 | # https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/bazel-0.27.0.bazelrc 9 | build:remote --jobs=500 10 | build:remote --host_javabase=@rbe_default//java:jdk 11 | build:remote --javabase=@rbe_default//java:jdk 12 | build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 13 | build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 14 | build:remote --crosstool_top=@rbe_default//cc:toolchain 15 | build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 16 | 17 | build:remote --extra_toolchains=@rbe_default//config:cc-toolchain 18 | build:remote --extra_execution_platforms=@io_k8s_repo_infra//:rbe_with_network 19 | build:remote --host_platform=@io_k8s_repo_infra//:rbe_with_network 20 | build:remote --platforms=@io_k8s_repo_infra//:rbe_with_network 21 | 22 | build:remote --define=EXECUTOR=remote 23 | build:remote --remote_executor=grpcs://remotebuildexecution.googleapis.com 24 | build:remote --remote_timeout=3600 25 | 26 | # Alt: --google_credentials=some_file.json 27 | build:remote --google_default_credentials=true 28 | 29 | # Improve cache hit rate 30 | build:remote --incompatible_strict_action_env=true 31 | 32 | # Minimize what is downloaded 33 | build:inmemory --experimental_inmemory_jdeps_files 34 | build:inmemory --experimental_inmemory_dotd_files 35 | 36 | # Minimize what is downloaded 37 | build:toplevel --config=inmemory 38 | build:toplevel --experimental_remote_download_outputs=toplevel 39 | 40 | build:minimal --config=inmemory 41 | build:minimal --experimental_remote_download_outputs=minimal 42 | 43 | build:remote --config=toplevel 44 | 45 | run:remote --experimental_remote_download_outputs=all --noexperimental_inmemory_jdeps_files --noexperimental_inmemory_dotd_files 46 | 47 | # Compose the remote configs with an instance name 48 | # A couple examples below: 49 | 50 | # --config=ci-instance adds the instance name 51 | build:ci-instance --remote_instance_name=projects/k8s-prow-builds/instances/default_instance 52 | 53 | # Config we want to use in ci 54 | build:ci --config=remote --config=ci-instance 55 | build:ci --noshow_progress 56 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.bazelversion: -------------------------------------------------------------------------------- 1 | 2.2.0 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | /bazel-* 7 | /_output 8 | 9 | # Vim-related files 10 | [._]*.s[a-w][a-z] 11 | [._]s[a-w][a-z] 12 | *.un~ 13 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | deadline: 180s 3 | tests: true 4 | skip-dirs: 5 | - .git 6 | - .tool 7 | - vendor 8 | - verify 9 | 10 | linters-settings: 11 | dupl: 12 | threshold: 100 13 | gocyclo: 14 | min-complexity: 50 15 | 16 | linters: 17 | enable: 18 | - govet 19 | - deadcode 20 | - golint 21 | - gocyclo 22 | disable-all: true 23 | 24 | issues: 25 | exclude-rules: 26 | - linters: 27 | - golint 28 | text: ".*should not use dot dot imports" 29 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/.kazelcfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "GoPrefix": "k8s.io/repo-infra", 3 | "AddSourcesRules": true 4 | } 5 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # gazelle:prefix k8s.io/repo-infra 2 | # gazelle:exclude hack 3 | # gazelle:proto disable 4 | 5 | # Use the Bazel-vendored protobuf library since we use go_proto_library 6 | # gazelle:resolve go github.com/golang/protobuf/proto @com_github_golang_protobuf//proto:go_default_library 7 | 8 | package(default_visibility = ["//visibility:public"]) 9 | 10 | licenses(["notice"]) 11 | 12 | load("//defs:run_in_workspace.bzl", "workspace_binary") 13 | 14 | workspace_binary( 15 | name = "gofmt", 16 | cmd = "@go_sdk//:bin/gofmt", 17 | ) 18 | 19 | workspace_binary( 20 | name = "go", 21 | cmd = "@go_sdk//:bin/go", 22 | ) 23 | 24 | workspace_binary( 25 | name = "kazel", 26 | cmd = "//cmd/kazel", 27 | ) 28 | 29 | workspace_binary( 30 | name = "golangci-lint", 31 | cmd = "@com_github_golangci_golangci_lint//cmd/golangci-lint", 32 | ) 33 | 34 | workspace_binary( 35 | name = "buildifier", 36 | cmd = "@com_github_bazelbuild_buildtools//buildifier", 37 | ) 38 | 39 | load("@bazel_gazelle//:def.bzl", "gazelle") 40 | 41 | gazelle(name = "gazelle") 42 | 43 | exports_files([".kazelcfg.json"]) 44 | 45 | filegroup( 46 | name = "package-srcs", 47 | srcs = glob( 48 | ["**"], 49 | exclude = [ 50 | "bazel-*/**", 51 | ".git/**", 52 | ], 53 | ), 54 | tags = ["automanaged"], 55 | visibility = ["//visibility:private"], 56 | ) 57 | 58 | filegroup( 59 | name = "all-srcs", 60 | srcs = [ 61 | ":package-srcs", 62 | "//cmd/kazel:all-srcs", 63 | "//defs:all-srcs", 64 | "//go:all-srcs", 65 | "//hack:all-srcs", 66 | "//tools/build_tar:all-srcs", 67 | "//verify:all-srcs", 68 | ], 69 | tags = ["automanaged"], 70 | visibility = ["//visibility:public"], 71 | ) 72 | 73 | platform( 74 | name = "rbe_with_network", 75 | parents = ["@rbe_default//config:platform"], 76 | remote_execution_properties = """ 77 | properties: { 78 | name: "dockerNetwork" 79 | value: "standard" 80 | } 81 | {PARENT_REMOTE_EXECUTION_PROPERTIES} 82 | """, 83 | ) 84 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for taking the time to join our community and start contributing! 4 | 5 | The [Contributor Guide](https://github.com/kubernetes/community/blob/master/contributors/guide/README.md) 6 | provides detailed instructions on how to get your ideas and bug fixes seen and accepted. 7 | 8 | Please remember to sign the [CNCF CLA](https://github.com/kubernetes/community/blob/master/CLA.md) and 9 | read and observe the [Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). 10 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - BenTheElder 3 | - clarketm 4 | - fejta 5 | - justaugustus 6 | - mikedanese 7 | 8 | reviewers: 9 | - BenTheElder 10 | - clarketm 11 | - fejta 12 | - justaugustus 13 | - mikedanese 14 | - Verolop 15 | 16 | emeritus_approvers: 17 | - ixdy 18 | 19 | labels: 20 | - sig/release 21 | - area/release-eng 22 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Security Announcements 4 | 5 | Join the [kubernetes-security-announce] group for security and vulnerability announcements. 6 | 7 | You can also subscribe to an RSS feed of the above using [this link][kubernetes-security-announce-rss]. 8 | 9 | ## Reporting a Vulnerability 10 | 11 | Instructions for reporting a vulnerability can be found on the 12 | [Kubernetes Security and Disclosure Information] page. 13 | 14 | ## Supported Versions 15 | 16 | Information about supported Kubernetes versions can be found on the 17 | [Kubernetes version and version skew support policy] page on the Kubernetes website. 18 | 19 | [kubernetes-security-announce]: https://groups.google.com/forum/#!forum/kubernetes-security-announce 20 | [kubernetes-security-announce-rss]: https://groups.google.com/forum/feed/kubernetes-security-announce/msgs/rss_v2_0.xml?num=50 21 | [Kubernetes version and version skew support policy]: https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-versions 22 | [Kubernetes Security and Disclosure Information]: https://kubernetes.io/docs/reference/issues-security/security/#report-a-vulnerability 23 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Committee to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | ixdy 14 | mikedanese 15 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/WORKSPACE: -------------------------------------------------------------------------------- 1 | # gazelle:repository_macro repos.bzl%go_repositories 2 | workspace(name = "io_k8s_repo_infra") 3 | 4 | load("//:load.bzl", "repositories") 5 | 6 | repositories() 7 | 8 | load("//:repos.bzl", "configure", "repo_infra_go_repositories") 9 | 10 | configure() 11 | 12 | repo_infra_go_repositories() 13 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/cmd/kazel/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | licenses(["notice"]) 4 | 5 | load( 6 | "@io_bazel_rules_go//go:def.bzl", 7 | "go_binary", 8 | "go_library", 9 | "go_test", 10 | ) 11 | 12 | go_binary( 13 | name = "kazel", 14 | embed = [":go_default_library"], 15 | ) 16 | 17 | go_library( 18 | name = "go_default_library", 19 | srcs = [ 20 | "config.go", 21 | "diff.go", 22 | "generator.go", 23 | "kazel.go", 24 | "sourcerer.go", 25 | ], 26 | importpath = "k8s.io/repo-infra/cmd/kazel", 27 | deps = [ 28 | "@com_github_bazelbuild_buildtools//build:go_default_library", 29 | "@io_k8s_klog_v2//:go_default_library", 30 | ], 31 | ) 32 | 33 | go_test( 34 | name = "go_default_test", 35 | srcs = [ 36 | "generator_test.go", 37 | "kazel_test.go", 38 | ], 39 | embed = [":go_default_library"], 40 | deps = ["@com_github_bazelbuild_buildtools//build:go_default_library"], 41 | ) 42 | 43 | filegroup( 44 | name = "package-srcs", 45 | srcs = glob(["**"]), 46 | tags = ["automanaged"], 47 | visibility = ["//visibility:private"], 48 | ) 49 | 50 | filegroup( 51 | name = "all-srcs", 52 | srcs = [":package-srcs"], 53 | tags = ["automanaged"], 54 | visibility = ["//visibility:public"], 55 | ) 56 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/cmd/kazel/diff.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes 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 | "io/ioutil" 21 | "os" 22 | "os/exec" 23 | ) 24 | 25 | // Diff prints the unified diff of the two provided byte slices 26 | // using the unix diff command. 27 | func Diff(left, right []byte) error { 28 | lf, err := ioutil.TempFile("/tmp", "actual-file-") 29 | if err != nil { 30 | return err 31 | } 32 | defer lf.Close() 33 | defer os.Remove(lf.Name()) 34 | 35 | rf, err := ioutil.TempFile("/tmp", "expected-file-") 36 | if err != nil { 37 | return err 38 | } 39 | defer rf.Close() 40 | defer os.Remove(rf.Name()) 41 | 42 | _, err = lf.Write(left) 43 | if err != nil { 44 | return err 45 | } 46 | lf.Close() 47 | 48 | _, err = rf.Write(right) 49 | if err != nil { 50 | return err 51 | } 52 | rf.Close() 53 | 54 | cmd := exec.Command("/usr/bin/diff", "-u", lf.Name(), rf.Name()) 55 | cmd.Stdout = os.Stdout 56 | cmd.Stderr = os.Stderr 57 | cmd.Run() 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/cmd/kazel/kazel_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 | "testing" 21 | 22 | "github.com/bazelbuild/buildtools/build" 23 | ) 24 | 25 | func TestAsExpr(t *testing.T) { 26 | var testCases = []struct { 27 | expr interface{} 28 | want string 29 | }{ 30 | {42, "42"}, 31 | {2.71828, "2.71828"}, 32 | {2.718281828459045, "2.718281828459045"}, 33 | {"a string", `"a string"`}, 34 | // values should stay in specified order 35 | {[]int{4, 7, 2, 9, 21}, `[ 36 | 4, 37 | 7, 38 | 2, 39 | 9, 40 | 21, 41 | ]`}, 42 | // keys should get sorted 43 | {map[int]string{1: "foo", 5: "baz", 3: "bar"}, `{ 44 | 1: "foo", 45 | 3: "bar", 46 | 5: "baz", 47 | }`}, 48 | // keys true and false should be sorted by their string representation 49 | { 50 | map[bool]map[string][]float64{ 51 | true: {"b": {2, 2.2}, "a": {1, 1.1, 1.11}}, 52 | false: {"": {}}, 53 | }, 54 | `{ 55 | false: {"": []}, 56 | true: { 57 | "a": [ 58 | 1, 59 | 1.1, 60 | 1.11, 61 | ], 62 | "b": [ 63 | 2, 64 | 2.2, 65 | ], 66 | }, 67 | }`}, 68 | } 69 | 70 | for _, testCase := range testCases { 71 | result := build.FormatString(asExpr(testCase.expr)) 72 | if result != testCase.want { 73 | t.Errorf("asExpr(%v) = %v; want %v", testCase.expr, result, testCase.want) 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":pkg.bzl", "pkg_tar") 2 | load(":build.bzl", "release_filegroup") 3 | load("@subpar//:subpar.bzl", "par_binary") 4 | 5 | par_binary( 6 | name = "gcs_uploader", 7 | srcs = [ 8 | "gcs_uploader.py", 9 | ], 10 | python_version = "PY2", 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | pkg_tar( 15 | name = "pkg_tar_smoke", 16 | srcs = glob(["*.bzl"]), 17 | ) 18 | 19 | # generate the hash files to use in the sh_tests below 20 | release_filegroup( 21 | name = "testfile", 22 | testonly = True, 23 | srcs = [":testdata/testfile.txt"], 24 | ) 25 | 26 | [ 27 | sh_test( 28 | name = "test_gen%ssum" % hash, 29 | srcs = ["diff_test.sh"], 30 | args = [ 31 | "$(location testdata/testfile.txt.%s.expected)" % hash, 32 | "$(location testdata/testfile.txt.%s)" % hash, 33 | ], 34 | data = [ 35 | ":testdata/testfile.txt.%s" % hash, 36 | ":testdata/testfile.txt.%s.expected" % hash, 37 | ], 38 | ) 39 | for hash in [ 40 | "md5", 41 | "sha1", 42 | "sha512", 43 | ] 44 | ] 45 | 46 | filegroup( 47 | name = "package-srcs", 48 | srcs = glob(["**"]), 49 | tags = ["automanaged"], 50 | visibility = ["//visibility:private"], 51 | ) 52 | 53 | filegroup( 54 | name = "all-srcs", 55 | srcs = [ 56 | ":package-srcs", 57 | "//defs/testgen:all-srcs", 58 | "//defs/testpkg:all-srcs", 59 | ], 60 | tags = ["automanaged"], 61 | visibility = ["//visibility:public"], 62 | ) 63 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/diff_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | expected=$1 21 | generated=$2 22 | 23 | diff=$(diff -u "${expected}" "${generated}" || true) 24 | 25 | if [[ -n "${diff}" ]]; then 26 | echo "Generated file ${generated} does not match expected file ${expected}" 27 | echo "${diff}" 28 | exit 1 29 | fi 30 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/pkg.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Kubernetes 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 | """A faster implementation of the pkg_tar rule. 16 | 17 | pkg_tar wraps the official pkg_tar rule with our faster 18 | Go-based build_tar binary. 19 | Additionally, the upstream pkg_tar rule defaults mode to "0555", 20 | which prevents build_tar from automatically choosing an 21 | appropriate mode, so we instead default it to "". 22 | """ 23 | 24 | load( 25 | "@bazel_tools//tools/build_defs/pkg:pkg.bzl", 26 | _real_pkg_tar = "pkg_tar", 27 | ) 28 | 29 | def pkg_tar( 30 | build_tar = "@io_k8s_repo_infra//tools/build_tar", 31 | mode = "", 32 | **kwargs): 33 | """pkg_tar wraps the official pkg_tar rule with a faster version.""" 34 | _real_pkg_tar(build_tar = build_tar, mode = mode, **kwargs) 35 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/rpm.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Kubernetes 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 | """Rules for creating redhat packages.""" 16 | 17 | load("@bazel_tools//tools/build_defs/pkg:rpm.bzl", "pkg_rpm") 18 | 19 | GOARCH_TO_RPMARCH = { 20 | "386": "i386", 21 | "amd64": "x86_64", 22 | "arm": "armhfp", 23 | "arm64": "aarch64", 24 | "ppc64le": "ppc64le", 25 | "s390x": "s390x", 26 | } 27 | 28 | def pkg_rpm_for_goarch(name, data, goarch, tags = None, **kwargs): 29 | """Creates a pkg_rpm filtering to data relevant to the specified goarch.""" 30 | rpmarch = GOARCH_TO_RPMARCH[goarch] 31 | pkg_rpm( 32 | name = name + "-" + goarch, 33 | architecture = rpmarch, 34 | data = select( 35 | { 36 | "@io_bazel_rules_go//go/platform:" + goarch: [ 37 | d.format(GOARCH = goarch, RPMARCH = rpmarch) 38 | for d in data 39 | ], 40 | }, 41 | ), 42 | tags = tags, 43 | **kwargs 44 | ) 45 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testdata/testfile.txt: -------------------------------------------------------------------------------- 1 | This is just some data to hash 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testdata/testfile.txt.md5.expected: -------------------------------------------------------------------------------- 1 | 6c840392943ddfc0d213a8786ddcf913 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testdata/testfile.txt.sha1.expected: -------------------------------------------------------------------------------- 1 | a1ee087329ef524229a8eb3dadc33265a0d30288 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testdata/testfile.txt.sha512.expected: -------------------------------------------------------------------------------- 1 | 77f3b6ab7f0b30eac6c84baecd7308c462df575b5a1bea484253fcdf5a0f61f0d9aeaa5a25f51a1621c90d0cc461f041ba5dba7573092221287af620f0f1c573 2 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testgen/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["main.go"], 6 | importpath = "k8s.io/repo-infra/defs/testgen", 7 | visibility = ["//defs:__subpackages__"], 8 | ) 9 | 10 | go_binary( 11 | name = "testgen", 12 | embed = [":go_default_library"], 13 | visibility = ["//defs:__subpackages__"], 14 | ) 15 | 16 | filegroup( 17 | name = "package-srcs", 18 | srcs = glob(["**"]), 19 | tags = ["automanaged"], 20 | visibility = ["//visibility:private"], 21 | ) 22 | 23 | filegroup( 24 | name = "all-srcs", 25 | srcs = [":package-srcs"], 26 | tags = ["automanaged"], 27 | visibility = ["//visibility:public"], 28 | ) 29 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testgen/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 | "flag" 21 | "fmt" 22 | "go/ast" 23 | "go/importer" 24 | "go/parser" 25 | "go/token" 26 | "go/types" 27 | "io/ioutil" 28 | "log" 29 | ) 30 | 31 | var ( 32 | in = flag.String("in", "", "input") 33 | out = flag.String("out", "", "output") 34 | pkgName = flag.String("pkg", "", "package") 35 | ) 36 | 37 | func main() { 38 | flag.Parse() 39 | 40 | fset := token.NewFileSet() 41 | f, err := parser.ParseFile(fset, *in, nil, 0) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | 46 | conf := types.Config{Importer: importer.Default()} 47 | 48 | pkg, err := conf.Check(*pkgName, fset, []*ast.File{f}, nil) 49 | if err != nil { 50 | log.Fatal(err) 51 | } 52 | if err := ioutil.WriteFile(*out, []byte(fmt.Sprintf("package %s\nconst OK = true", pkg.Name())), 0666); err != nil { 53 | log.Fatal(err) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testpkg/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//defs:go.bzl", "go_genrule") 2 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 3 | 4 | go_library( 5 | name = "go_default_library", 6 | srcs = [ 7 | "ok.go", 8 | "pkg.go", 9 | ], 10 | importpath = "k8s.io/repo-infra/defs/testpkg", 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | go_genrule( 15 | name = "go_genrule_test", 16 | srcs = [ 17 | "pkg.go", 18 | ], 19 | outs = [ 20 | "ok.go", 21 | ], 22 | cmd = "$(location //defs/testgen) -in=$< -out=$@ -pkg k8s.io/repo-infra/defs/testpkg", 23 | tools = ["//defs/testgen"], 24 | ) 25 | 26 | filegroup( 27 | name = "package-srcs", 28 | srcs = glob(["**"]), 29 | tags = ["automanaged"], 30 | visibility = ["//visibility:private"], 31 | ) 32 | 33 | filegroup( 34 | name = "all-srcs", 35 | srcs = [":package-srcs"], 36 | tags = ["automanaged"], 37 | visibility = ["//visibility:public"], 38 | ) 39 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/defs/testpkg/pkg.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 testpkg 18 | 19 | import ( 20 | // Make sure stdlib is accessible 21 | "fmt" 22 | ) 23 | 24 | // TestFunc is a func. 25 | func TestFunc() { 26 | fmt.Println("ok") 27 | } 28 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/go.mod: -------------------------------------------------------------------------------- 1 | module k8s.io/repo-infra 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/bazelbuild/bazel-gazelle v0.21.1 7 | github.com/bazelbuild/buildtools v0.0.0-20200228172928-c9d9e342afdb 8 | github.com/golangci/golangci-lint v1.29.0 9 | golang.org/x/build v0.0.0-20200720211405-d0191c8228ec 10 | k8s.io/klog/v2 v2.3.0 11 | ) 12 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/go/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "package-srcs", 3 | srcs = glob(["**"]), 4 | tags = ["automanaged"], 5 | visibility = ["//visibility:private"], 6 | ) 7 | 8 | filegroup( 9 | name = "all-srcs", 10 | srcs = [":package-srcs"], 11 | tags = ["automanaged"], 12 | visibility = ["//visibility:public"], 13 | ) 14 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/tools.go: -------------------------------------------------------------------------------- 1 | // +build tools 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package hack 20 | 21 | import ( 22 | _ "github.com/bazelbuild/bazel-gazelle/cmd/gazelle" 23 | _ "github.com/bazelbuild/buildtools/buildifier" 24 | _ "github.com/golangci/golangci-lint/cmd/golangci-lint" 25 | ) 26 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/update-bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2016 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel 21 | echo "Updating bazel rules..." >&2 22 | elif ! command -v bazel &>/dev/null; then 23 | echo "Install bazel at https://bazel.build" >&2 24 | exit 1 25 | else 26 | ( 27 | set -o xtrace 28 | bazel run @io_k8s_repo_infra//hack:update-bazel 29 | ) 30 | exit 0 31 | fi 32 | 33 | buildifier=$(realpath "$1") 34 | gazelle=$(realpath "$2") 35 | kazel=$(realpath "$3") 36 | 37 | cd "$BUILD_WORKSPACE_DIRECTORY" 38 | 39 | if [[ ! -f go.mod ]]; then 40 | echo "No module defined, see https://github.com/golang/go/wiki/Modules#how-to-define-a-module" >&2 41 | exit 1 42 | fi 43 | 44 | set -o xtrace 45 | "$gazelle" fix --external=external 46 | "$kazel" --cfg-path=./.kazelcfg.json 47 | find . -name BUILD -o -name BUILD.bazel -o -name '*.bzl' -type f \ 48 | \( -not -path '*/vendor/*' -prune \) \ 49 | -exec "$buildifier" --mode=fix --lint=fix '{}' + 50 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/update-gofmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | 21 | if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel 22 | echo "Updating gofmt..." >&2 23 | elif ! command -v bazel &>/dev/null; then 24 | echo "Install bazel at https://bazel.build" >&2 25 | exit 1 26 | else 27 | ( 28 | set -o xtrace 29 | bazel run @io_k8s_repo_infra//hack:update-gofmt 30 | ) 31 | exit 0 32 | fi 33 | 34 | gofmt=$PWD/$1 35 | cd "$BUILD_WORKSPACE_DIRECTORY" 36 | find . -name "*.go" \( -not -path '*/vendor/*' -prune \) -exec "$gofmt" -s -w '{}' + 37 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/verify-bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2016 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | 21 | fail() { 22 | echo "ERROR: $1. Fix with:" >&2 23 | echo " bazel run @io_k8s_repo_infra//hack:update-bazel" >&2 24 | exit 1 25 | } 26 | 27 | if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel 28 | echo "Validating bazel rules..." >&2 29 | elif ! command -v bazel &> /dev/null; then 30 | echo "Install bazel at https://bazel.build" >&2 31 | exit 1 32 | elif ! bazel query @//:all-srcs &>/dev/null; then 33 | fail "bazel rules need bootstrapping" 34 | else 35 | ( 36 | set -o xtrace 37 | bazel test --test_output=streamed @io_k8s_repo_infra//hack:verify-bazel 38 | ) 39 | exit 0 40 | fi 41 | 42 | buildifier=$1 43 | gazelle=$2 44 | kazel=$3 45 | 46 | gazelle_diff=$("$gazelle" fix --mode=diff --external=external || echo "ERROR: gazelle diffs") 47 | kazel_diff=$("$kazel" --dry-run --print-diff --cfg-path=./.kazelcfg.json || echo "ERROR: kazel diffs") 48 | # TODO(fejta): --mode=diff --lint=warn 49 | buildifier_diff=$(find . \ 50 | -name BUILD -o -name BUILD.bazel -o -name '*.bzl' -type f \ 51 | \( -not -path '*/vendor/*' -prune \) \ 52 | -exec "$buildifier" --mode=diff '{}' + 2>&1 || echo "ERROR: found buildifier diffs") 53 | 54 | if [[ -n "${gazelle_diff}${kazel_diff}${buildifier_diff}" ]]; then 55 | echo "Current rules (-) do not match expected (+):" >&2 56 | echo "gazelle diff:" 57 | echo "${gazelle_diff}" 58 | echo "kazel diff:" 59 | echo "${kazel_diff}" 60 | echo "buildifier diff:" 61 | echo "$buildifier_diff" 62 | echo 63 | fail "bazel rules out of date" 64 | fi 65 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/verify-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 The Kubernetes 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 | set -o nounset 17 | set -o errexit 18 | set -o pipefail 19 | 20 | fail() { 21 | echo "ERROR: $1. Fix with:" >&2 22 | echo " bazel run @io_k8s_repo_infra//hack:update-deps" >&2 23 | exit 1 24 | } 25 | 26 | 27 | if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel 28 | echo "Checking modules for changes..." >&2 29 | elif ! command -v bazel &>/dev/null; then 30 | echo "Install bazel at https://bazel.build" >&2 31 | exit 1 32 | elif ! bazel query @//:all-srcs &>/dev/null; then 33 | fail "bazel rules need bootstrapping" 34 | else 35 | ( 36 | set -o xtrace 37 | bazel test --test_output=streamed @io_k8s_repo_infra//hack:verify-deps 38 | ) 39 | exit 0 40 | fi 41 | 42 | 43 | tmpfiles=$TEST_TMPDIR/files 44 | 45 | ( 46 | mkdir -p "$tmpfiles" 47 | rm -f bazel-* 48 | cp -aL "." "$tmpfiles" 49 | export BUILD_WORKSPACE_DIRECTORY=$tmpfiles 50 | export HOME=$(realpath "$TEST_TMPDIR/home") 51 | unset GOPATH 52 | go=$(realpath "$2") 53 | export PATH=$(dirname "$go"):$PATH 54 | "$@" 55 | ) 56 | 57 | ( 58 | # Remove the platform/binary for gazelle and kazel 59 | gazelle=$(dirname "$3") 60 | kazel=$(dirname "$4") 61 | rm -rf {.,"$tmpfiles"}/{"$gazelle","$kazel"} 62 | ) 63 | # Avoid diff -N so we handle empty files correctly 64 | diff=$(diff -upr \ 65 | -x ".git" \ 66 | -x "bazel-*" \ 67 | -x "_output" \ 68 | "." "$tmpfiles" 2>/dev/null || true) 69 | 70 | if [[ -n "${diff}" ]]; then 71 | echo "${diff}" >&2 72 | echo >&2 73 | fail "modules changed" 74 | fi 75 | echo "SUCCESS: modules up-to-date" 76 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/verify-gofmt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel 21 | echo "Validating gofmt..." >&2 22 | elif ! command -v bazel &> /dev/null; then 23 | echo "Install bazel at https://bazel.build" >&2 24 | exit 1 25 | else 26 | ( 27 | set -o xtrace 28 | bazel test --test_output=streamed @io_k8s_repo_infra//hack:verify-gofmt 29 | ) 30 | exit 0 31 | fi 32 | 33 | gofmt="$1" 34 | diff=$(find . -name "*.go" \( -not -path '*/vendor/*' -prune \) -exec "$gofmt" -s -d '{}' +) 35 | if [[ -z "$diff" ]]; then 36 | exit 0 37 | fi 38 | 39 | echo "$diff" 40 | echo 41 | echo "ERROR: found unformatted go files, fix with:" >&2 42 | echo " bazel run @io_k8s_repo_infra//hack:update-gofmt" >&2 43 | exit 1 44 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/verify-golangci-lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel 21 | echo "Verifying golangci-lint..." >&2 22 | elif ! command -v bazel &> /dev/null; then 23 | echo "Install bazel at https://bazel.build" >&2 24 | exit 1 25 | else 26 | ( 27 | set -o xtrace 28 | bazel test --test_output=streamed @io_k8s_repo_infra//hack:verify-golangci-lint 29 | ) 30 | exit 0 31 | fi 32 | 33 | trap 'echo ERROR: golangci-lint failed >&2' ERR 34 | 35 | if [[ ! -f .golangci.yml ]]; then 36 | echo 'ERROR: missing .golangci.yml in repo root' >&2 37 | exit 1 38 | fi 39 | 40 | golangci_lint=$2 41 | export GO111MODULE=on 42 | export GOPROXY=https://proxy.golang.org 43 | export GOSUMDB=sum.golang.org 44 | export HOME=$TEST_TMPDIR/home 45 | export GOPATH=$HOME/go 46 | PATH=$(dirname "$1"):$PATH 47 | export PATH 48 | shift 2 49 | "$golangci_lint" run "$@" 50 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/hack/verify_boilerplate_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2016 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import io 18 | import os 19 | import sys 20 | import unittest 21 | 22 | import verify_boilerplate 23 | 24 | class TestBoilerplate(unittest.TestCase): 25 | 26 | def setUp(self): 27 | self.old_cwd = os.getcwd() 28 | if os.getenv('TEST_WORKSPACE'): # Running in bazel 29 | os.chdir('verify/boilerplate') 30 | os.chdir('test/') 31 | self.old_out = sys.stdout 32 | sys.stdout = io.StringIO() 33 | 34 | def tearDown(self): 35 | sys.stdout = self.old_out 36 | os.chdir(self.old_cwd) 37 | 38 | def test_boilerplate(self): 39 | 40 | class Args(object): 41 | def __init__(self): 42 | self.filenames = [] 43 | self.rootdir = '.' 44 | self.boilerplate_dir = '../' 45 | self.skip = [] 46 | self.verbose = True 47 | 48 | verify_boilerplate.ARGS = Args() 49 | with self.assertRaises(SystemExit): 50 | verify_boilerplate.main() 51 | 52 | output = sys.stdout.getvalue() 53 | expected = '\n'.join(verify_boilerplate.nonconforming_lines([ 54 | './fail.go', 55 | './fail.py', 56 | ])) + '\n' # add trailing newline 57 | 58 | self.assertEquals(output, expected) 59 | 60 | 61 | if __name__ == '__main__': 62 | unittest.main() 63 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/presubmit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 The Kubernetes 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 | set -o nounset 17 | set -o errexit 18 | set -o pipefail 19 | 20 | cd "$(git rev-parse --show-toplevel)" 21 | 22 | if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then 23 | echo "Service account detected. Adding --config=ci to bazel commands" >&2 24 | mkdir -p "$HOME" 25 | touch "$HOME/.bazelrc" 26 | echo "build --config=ci" >> "$HOME/.bazelrc" 27 | fi 28 | ( 29 | set -o xtrace 30 | bazel test //... # This also builds everything 31 | ./verify/verify-boilerplate.sh --rootdir="$(pwd)" -v # TODO(fejta) migrate to bazel 32 | ) 33 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/tools/build_tar/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["buildtar.go"], 6 | importpath = "k8s.io/repo-infra/tools/build_tar", 7 | visibility = ["//visibility:private"], 8 | deps = [ 9 | "@io_k8s_klog_v2//:go_default_library", 10 | "@org_golang_x_build//pargzip:go_default_library", 11 | ], 12 | ) 13 | 14 | go_binary( 15 | name = "build_tar", 16 | embed = [":go_default_library"], 17 | visibility = ["//visibility:public"], 18 | ) 19 | 20 | filegroup( 21 | name = "package-srcs", 22 | srcs = glob(["**"]), 23 | tags = ["automanaged"], 24 | visibility = ["//visibility:private"], 25 | ) 26 | 27 | filegroup( 28 | name = "all-srcs", 29 | srcs = [":package-srcs"], 30 | tags = ["automanaged"], 31 | visibility = ["//visibility:public"], 32 | ) 33 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "package-srcs", 3 | srcs = glob(["**"]), 4 | tags = ["automanaged"], 5 | visibility = ["//visibility:private"], 6 | ) 7 | 8 | filegroup( 9 | name = "all-srcs", 10 | srcs = [ 11 | ":package-srcs", 12 | "//verify/boilerplate:all-srcs", 13 | ], 14 | tags = ["automanaged"], 15 | visibility = ["//visibility:public"], 16 | ) 17 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/README.md: -------------------------------------------------------------------------------- 1 | # Verification scripts 2 | 3 | Collection of scripts that verifies that a project meets requirements set for kubernetes related projects. The scripts are to be invoked depending on the needs via CI tooling, such as Travis CI. See main Readme file on how to integrate the repo-infra in your project. 4 | 5 | The scripts are currently being migrated from the main kubernetes repository. If your project requires additional set of verifications, consider creating an issue/PR on repo-infra to avoid code duplication across multiple projects. 6 | 7 | If repo-infra is integrated at the root of your project as git submodule at path: `/repo-infra`, 8 | then scripts can be invoked as `repo-infra/verify/verify-*.sh` 9 | 10 | travis.yaml example: 11 | 12 | ``` 13 | dist: trusty 14 | 15 | os: 16 | - linux 17 | 18 | language: go 19 | 20 | go: 21 | - 1.8 22 | 23 | before_install: 24 | - go get -u github.com/alecthomas/gometalinter 25 | 26 | install: 27 | - gometalinter --install 28 | 29 | script: 30 | - repo-infra/verify/verify-go-src.sh -v 31 | - repo-infra/verify/verify-boilerplate.sh 32 | # OR with vendoring 33 | # - vendor/github.com/kubernetes/repo-infra/verify-go-src.sh --rootdir=$(pwd) -v 34 | ``` 35 | 36 | ## Verify boilerplate 37 | 38 | Verifies that the boilerplate for various formats (go files, Makefile, etc.) is included in each file: `verify-boilerplate.sh`. 39 | 40 | ## Verify go source code 41 | 42 | Runs a set of scripts on the go source code excluding vendored files: `verify-go-src.sh`. Expects `gometalinter` tooling installed (see travis file above) 43 | 44 | With git submodule from your repo root: `repo-infra/verify/verify-go-src.sh -v` 45 | 46 | With vendoring: `vendor/repo-infra/verify/verify-go-src.sh -v --rootdir $(pwd)` 47 | 48 | Checks include: 49 | 50 | 1. gofmt 51 | 2. gometalinter 52 | 3. govet 53 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # gazelle:exclude test 2 | # gazelle:exclude verify/boilerplate/test 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | exports_files(glob(["*.txt"])) 6 | 7 | filegroup( 8 | name = "package-srcs", 9 | srcs = glob(["**"]), 10 | tags = ["automanaged"], 11 | visibility = ["//visibility:private"], 12 | ) 13 | 14 | filegroup( 15 | name = "all-srcs", 16 | srcs = [":package-srcs"], 17 | tags = ["automanaged"], 18 | visibility = ["//visibility:public"], 19 | ) 20 | 21 | filegroup( 22 | name = "templates", 23 | srcs = glob(["boilerplate.*.txt"]), 24 | ) 25 | 26 | filegroup( 27 | name = "testdata", 28 | srcs = glob(["test/**"]), 29 | ) 30 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.Dockerfile.txt: -------------------------------------------------------------------------------- 1 | # Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.Makefile.txt: -------------------------------------------------------------------------------- 1 | # Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.bzl.txt: -------------------------------------------------------------------------------- 1 | # Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.py.txt: -------------------------------------------------------------------------------- 1 | # Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/boilerplate.sh.txt: -------------------------------------------------------------------------------- 1 | # Copyright YEAR The Kubernetes 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 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/test/fail.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | fail 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package test 20 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/test/fail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2015 The Kubernetes Authors. 4 | # 5 | # failed 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/test/pass.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes 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 test 18 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/boilerplate/test/pass.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2015 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | True 18 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/go_install_from_commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017 The Kubernetes 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 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | PKG=$1 21 | COMMIT=$2 22 | export GOPATH=$3 23 | export GOBIN="$GOPATH/bin" 24 | 25 | go get -d -u "${PKG}" 26 | cd "${GOPATH}/src/${PKG}" 27 | git checkout -q "${COMMIT}" 28 | go install "${PKG}" 29 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/verify-bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2016 The Kubernetes 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 | # TODO(fejta): delete this file 17 | 18 | set -o errexit 19 | set -o nounset 20 | set -o pipefail 21 | set -o xtrace 22 | 23 | bazel test @io_k8s_repo_infra//hack:verify-deps 24 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/verify-boilerplate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2014 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # TODO(fejta): delete this file 18 | 19 | set -o errexit 20 | set -o nounset 21 | set -o pipefail 22 | set -o xtrace 23 | 24 | bazel test @io_k8s_repo_infra//hack:verify-boilerplate 25 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/verify-errexit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Kubernetes 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 | # This script will verify that the specified script files have 17 | # "set -o errexit" turned on at some point. 18 | # 19 | # Usage: verify-errexit.sh [ dir | file ... ] 20 | # default args is the root of our source tree 21 | 22 | set -o errexit 23 | set -o nounset 24 | set -o pipefail 25 | 26 | REPO_ROOT=$(dirname "${BASH_SOURCE}")/.. 27 | 28 | if [[ "$*" != "" ]]; then 29 | args="$*" 30 | else 31 | args=$(ls "${REPO_ROOT}" | grep -v vendor | grep -v glide) 32 | fi 33 | 34 | # Gather the list of files that appear to be shell scripts. 35 | # Meaning they have some form of "#!...sh" as a line in them. 36 | shFiles=$(grep -rl '^#!.*sh$' ${args}) 37 | 38 | rc="0" 39 | for file in ${shFiles}; do 40 | grep "set -o errexit" ${file} &> /dev/null && continue 41 | grep "set -[a-z]*e" ${file} &> /dev/null && continue 42 | 43 | echo ${file}: appears to be missing \"set -o errexit\" 44 | rc="1" 45 | done 46 | 47 | exit ${rc} 48 | 49 | -------------------------------------------------------------------------------- /third-party/k8s.io/repo-infra/verify/verify-go-src.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | set -o xtrace 21 | 22 | bazel test @io_k8s_repo_infra//hack:verify-all 23 | -------------------------------------------------------------------------------- /tools/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mesosphere/kommander-cluster-lifecycle/tools 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/go-bindata/go-bindata/v3 v3.1.3 7 | sigs.k8s.io/controller-tools v0.6.0 8 | ) 9 | -------------------------------------------------------------------------------- /tools/tools.go: -------------------------------------------------------------------------------- 1 | // +build tools 2 | 3 | package tools 4 | 5 | import ( 6 | _ "github.com/go-bindata/go-bindata/v3/go-bindata" 7 | _ "sigs.k8s.io/controller-tools/cmd/controller-gen" 8 | ) 9 | --------------------------------------------------------------------------------