Skip to content

Commit

Permalink
Merge pull request #36 from caesarxuchao/configurable-namespace
Browse files Browse the repository at this point in the history
Make the namespace where the migration system run configurable,
  • Loading branch information
k8s-ci-robot committed Aug 16, 2019
2 parents 571636a + 96a3a96 commit c80e838
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

REGISTRY ?= gcr.io/google-containers
VERSION ?= v0.1
NAMESPACE ?= kube-system
DELETE ?= "gcloud container images delete"

.PHONY: test
Expand Down Expand Up @@ -50,6 +51,7 @@ local-manifests:
cp manifests/* manifests.local/
find ./manifests.local -type f -exec sed -i -e "s|REGISTRY|$(REGISTRY)|g" {} \;
find ./manifests.local -type f -exec sed -i -e "s|VERSION|$(VERSION)|g" {} \;
find ./manifests.local -type f -exec sed -i -e "s|NAMESPACE|$(NAMESPACE)|g" {} \;

.PHONY: all-containers
push-all: all-containers
Expand Down
2 changes: 1 addition & 1 deletion manifests/initializer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: initializer
namespace: kube-storage-migration
namespace: NAMESPACE
spec:
template:
spec:
Expand Down
2 changes: 1 addition & 1 deletion manifests/migrator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: migrator
namespace: kube-storage-migration
namespace: NAMESPACE
labels:
app: migrator
spec:
Expand Down
14 changes: 7 additions & 7 deletions manifests/namespace-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: kube-storage-migration
name: NAMESPACE
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -40,7 +40,7 @@ kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: storage-version-migration-initializer
namespace: kube-storage-migration
namespace: NAMESPACE
rules:
- apiGroups: ["migration.k8s.io"]
resources: ["storageversionmigrations"]
Expand All @@ -53,7 +53,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: default
namespace: kube-storage-migration
namespace: NAMESPACE
roleRef:
kind: ClusterRole
name: storage-version-migration-migrator
Expand All @@ -66,7 +66,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: default
namespace: kube-storage-migration
namespace: NAMESPACE
roleRef:
kind: ClusterRole
name: storage-version-migration-trigger
Expand All @@ -79,7 +79,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: default
namespace: kube-storage-migration
namespace: NAMESPACE
roleRef:
kind: ClusterRole
name: storage-version-migration-crd-creator
Expand All @@ -89,11 +89,11 @@ kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: storage-version-migration-initializer
namespace: kube-storage-migration
namespace: NAMESPACE
subjects:
- kind: ServiceAccount
name: default
namespace: kube-storage-migration
namespace: NAMESPACE
roleRef:
kind: Role
name: storage-version-migration-initializer
Expand Down
2 changes: 1 addition & 1 deletion manifests/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: trigger
namespace: kube-storage-migration
namespace: NAMESPACE
labels:
app: trigger
spec:
Expand Down
15 changes: 9 additions & 6 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ limitations under the License.
package initializer

import (
"flag"
"fmt"
"time"

migrationv1alpha1 "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/apis/migration/v1alpha1"
"github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -53,13 +54,15 @@ func NewInitializer(
discovery: d,
crdClient: crdClient,
namespaceClient: namespaceClient,
migrationClient: migrationGetter.StorageVersionMigrations(namespaceName),
migrationClient: migrationGetter.StorageVersionMigrations(*namespaceName),
}
}

var (
namespaceName = flag.String("namespace", "kube-system", "the namespace the initializer is going to run in. The namespace should be created before running the initializer. The namespace should be the same one where the migrator runs. Default to kube-system.")
)

const (
// TODO: get the namespace name from the enviroment variable
namespaceName = "kube-storage-migration"
singularCRDName = "storageversionmigration"
pluralCRDName = "storageversionmigrations"
kind = "StorageVersionMigration"
Expand Down Expand Up @@ -145,13 +148,13 @@ func (init *initializer) initializeCRD() error {
// TODO: remove this function. Users will use provided yaml files to create the
// namespace, and then create the initializer in the namespace.
func (init *initializer) initializeNamespace() error {
_, err := init.namespaceClient.Get(namespaceName, metav1.GetOptions{})
_, err := init.namespaceClient.Get(*namespaceName, metav1.GetOptions{})
if (err != nil && !errors.IsNotFound(err)) || err == nil {
return err
}
_, err = init.namespaceClient.Create(&v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
Name: *namespaceName,
},
})
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package trigger

import (
"flag"
"fmt"
"reflect"
"time"
Expand All @@ -38,11 +39,11 @@ var (
Factor: 5.0,
Jitter: 0.1,
}

namespaceName = flag.String("namespace", "kube-system", "the namespace the trigger is going to run in. The namespace should be created before running the trigger. The namespace should be the same one where the migrator runs. Default to kube-system.")
)

const (
// TODO: centralize the namespace definitions.
namespaceName = "kube-storage-migration"
// The migration trigger controller redo the discovery every discoveryPeriod.
discoveryPeriod = 10 * time.Minute
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/trigger/discovery_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (mt *MigrationTrigger) launchMigration(resource migrationv1alpha1.GroupVers
Resource: resource,
},
}
_, err := mt.client.MigrationV1alpha1().StorageVersionMigrations(namespaceName).Create(m)
_, err := mt.client.MigrationV1alpha1().StorageVersionMigrations(*namespaceName).Create(m)
return err
}

Expand Down
10 changes: 5 additions & 5 deletions test/e2e/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function wait-for-migration()
{
# wait for initialization
for count in {0..9}; do
tasks=$(kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-storage-migration -o json | jq -r '.items | length') && rc=$? || rc=$?
tasks=$(kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-system -o json | jq -r '.items | length') && rc=$? || rc=$?
if [ ${rc} -ne 0 ]; then
echo "retry after 10s"
sleep 10
Expand All @@ -59,7 +59,7 @@ function wait-for-migration()
for count in {0..9}; do
# pending storageversionmigrations either have no status, or have
# status.conditions that are not "Succeeded".
pendings=$(kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-storage-migration -o json | jq -r '.items[] | select((has("status") | not) or ([ .status.conditions[] | select(.type != "Succeeded" and .status == "True") ] | length !=0) ) | .metadata.namespace + "/" + .metadata.name')
pendings=$(kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-system -o json | jq -r '.items[] | select((has("status") | not) or ([ .status.conditions[] | select(.type != "Succeeded" and .status == "True") ] | length !=0) ) | .metadata.namespace + "/" + .metadata.name')
# Note that number=1 when pendings="".
number=$(echo "${pendings}" | wc -l)
if [ -z "${pendings}" ]; then
Expand All @@ -76,9 +76,9 @@ function wait-for-migration()

echo "Timed out waiting for migration to complete."
echo "initializer logs:"
kubectl logs --namespace=kube-storage-migration -l job-name=initializer || true
kubectl logs --namespace=kube-system -l job-name=initializer || true
echo "migrator logs:"
kubectl logs --namespace=kube-storage-migration -l app=migrator || true
kubectl logs --namespace=kube-system -l app=migrator || true
return 1
}

Expand Down Expand Up @@ -111,7 +111,7 @@ cleanup() {
echo "Deleting images successfully"
popd

kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-storage-migration -o json
kubectl get storageversionmigrations.migration.k8s.io --namespace=kube-system -o json
}

trap cleanup EXIT
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/crd-migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
// TODO: centralize the namespace definitions.
namespaceName = "kube-storage-migration"
namespaceName = "kube-system"
// The migration trigger controller redo the discovery every discoveryPeriod.
discoveryPeriod = 10 * time.Minute
)
Expand Down

0 comments on commit c80e838

Please sign in to comment.