Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1497839 - copy secrets to transient namespace and always run #473

Merged
merged 4 commits into from Oct 13, 2017

Conversation

shawn-hurley
Copy link
Contributor

@shawn-hurley shawn-hurley commented Oct 4, 2017

Describe what this PR does and why we need it:
Removes split code path based on secrets to run the APB in the transient namespace always
Changes proposed in this pull request

  • remove branch on secrets
  • copy secrets to the transient namespace
  • panic the broker if we are attempting to delete its namespace.

Does this PR depend on another PR (Use this to track when PRs should be merged)
depends-on
N/A
Which issue this PR fixes (This will close that issue when PR gets merged)
N/A

Fixes: #385

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 nitpick

}

// Using a new UUID is sane, because it will have some gurantee
// of uniquenes and will meet DNS name requirements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Using a new UUID is sane, because it will have some guarantee
of uniqueness and will meet DNS name requirements.

namespace := v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{transientNameSpaceKey: spec.FQName},
Name: executionContext.Namespace,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use GenerateName

https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency, but then you would have to get the name after you have created the namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think then we could give the namespace a name that is more obvious like apb-namespace-(unique suffix).

@jmrodri jmrodri self-requested a review October 5, 2017 15:10
@shawn-hurley
Copy link
Contributor Author

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 12, 2017
@eriknelson eriknelson self-requested a review October 12, 2017 17:18
@djzager
Copy link
Member

djzager commented Oct 12, 2017

Example Namespace:

- apiVersion: v1
  kind: Namespace
  metadata:
    annotations:
      openshift.io/sa.scc.mcs: s0:c13,c7
      openshift.io/sa.scc.supplemental-groups: 1000170000/10000
      openshift.io/sa.scc.uid-range: 1000170000/10000
    creationTimestamp: 2017-10-12T17:12:06Z
    generateName: dh-hello-world-apb-prov-
    labels:
      apb-action: provision
      apb-fqname: dh-hello-world-apb
    name: dh-hello-world-apb-prov-84s0z
    namespace: ""
    resourceVersion: "10004"
    selfLink: /api/v1/namespaces/dh-hello-world-apb-prov-84s0z
    uid: 7927f3e5-af70-11e7-a5b7-64006a6fb904
  spec:
    finalizers:
    - kubernetes
    - openshift.io/origin
  status:
    phase: Active

Copy link
Contributor

@eriknelson eriknelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor requests, overall looks good.

namespace := v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
GenerateName: fmt.Sprintf("%s-%.4s-", spec.FQName, action),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the upper limit on the size of this field? 64 chars? We should guarantee we're under it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this change if you like, but my understanding is that GenerateName handles this for you:

Names generated by the system may be requested using metadata.generateName. GenerateName indicates that the name should be made unique by the server prior to persisting it. A non-empty value for the field indicates the name will be made unique (and the name returned to the client will be different than the name passed). The value of this field will be combined with a unique suffix on the server if the Name field has not been provided. The provided value must be valid within the rules for Name, and may be truncated by the length of the suffix required to make the value unique on the server. If this field is specified, and Name is not present, the server will NOT return a 409 if the generated name exists - instead, it will either return 201 Created or 504 with Reason ServerTimeout indicating a unique name could not be found in the time allotted, and the client should retry (optionally after the time indicated in the Retry-After header).

From https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change needed, that looks good! Thank you for the link 👍

@@ -236,8 +237,11 @@ func (s *ServiceAccountManager) DestroyApbSandbox(executionContext ExecutionCont
if asbNamespace != executionContext.Namespace {
s.log.Debug("Deleting namespace %s", executionContext.Namespace)
k8scli.CoreV1().Namespaces().Delete(executionContext.Namespace, &metav1.DeleteOptions{})

} else {
//We should not be attempting to run pods in the ASB namespace, if we are, something is seriously wrong.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Space after //

@@ -201,3 +200,22 @@ func checkPullPolicy(policy string) (v1.PullPolicy, error) {

return value, nil
}

func copySecretsToNamespace(executionContext ExecutionContext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We have a couple stylistic patterns for long function signatures in the codebase right now. Admittedly, it's not super consistent, but we should try to not introduce other forms as well IMO. Personally, I like a vertically favored format:

func copySecretsToNamespace(
	executionContext ExecutionContext,
	clusterConfig ClusterConfig,
	k8scli *clientset.Clientset,
	secrets []string,
) error { // Return values
	// Implementation
}

Also a longer form format, wrapping after the last full var/type crosses something like 80 chars:

func copySecretsToNamespace(executionContext ExecutionContext, clusterConfig ClusterConfig,
	k8scli *clientset.Clientset, secrets []string) error {
	// Implementation
}

I would just advocate picking one and sticking with it.


} else {
//We should not be attempting to run pods in the ASB namespace, if we are, something is seriously wrong.
panic(fmt.Errorf("Broker is attempting to delete its own namespace"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, let's not implode 🎉

@eriknelson
Copy link
Contributor

@shawn-hurley @djzager meant to request changes, apparently I can't operate github.

Add additional labels to apb pod for use when debugging failed apb
execution.
@eriknelson
Copy link
Contributor

doublecomboACK

@eriknelson eriknelson merged commit 81381b1 into openshift:master Oct 13, 2017
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
…nshift#473)

* Bug 1497839 - copy secrets to transient namespace and always run

the APB in the transient namespace.

* using kubernetes generatename to get a unique name that is readable.

* update based on PR comments

* Make transient namespace name user friendly

Add additional labels to apb pod for use when debugging failed apb
execution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APB pods should have descriptive names
4 participants