origin icon indicating copy to clipboard operation
origin copied to clipboard

Setting Global Build Defaults and Build Overrides

Open alikhajeh1 opened this issue 9 years ago • 42 comments

We've manually set global build defaults but they don't seem to be having any effect, e.g. we tried setting annotations and env vars. Apart from updating master-config.yaml and restarting master-api/controllers, is there anything else needed to enable this plugin?

We're seeing the same issue with BuildOverrides.

Version
oc v1.4.1
kubernetes v1.4.0+776c994
features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://...
openshift v1.4.1
kubernetes v1.4.0+776c994
Steps To Reproduce
  1. Update the following section of master-config.yml and restart master-api/controllers:
kubernetesMasterConfig:
  admissionConfig:
    pluginConfig:
      BuildDefaults:
        configuration:
          apiVersion: v1
          kind: BuildDefaultsConfig
          env:
          - name: CUSTOM_VAR 
            value: custom_value
          imageLabels:
          - name: vendor
            value: ExampleCorp Ltd.
          annotations: 
            key1: value1
            key2: value2
  1. Create a new project, use oc new-app --strategy=docker ... to create a new app, wait for the build to complete.
Current Result

The produced image does not show the custom env, image label or annotations.

Expected Result

The BuildDefaultsConfig settings should be applied. We also tried the BuildOverrides configuration, it also does not set the imageLabels or the annotations.

alikhajeh1 avatar Mar 05 '17 06:03 alikhajeh1

turn on loglevel 5 tracing on your master and restart, look for: Initialized build defaults plugin with config: and Initialized build overrides plugin with config:

you can also look for this output, again in your master: https://github.com/openshift/origin/blob/release-1.4/pkg/build/admission/defaults/admission.go#L44

also providing level 5 build logs would help.

bparees avatar Mar 06 '17 18:03 bparees

Thanks @bparees, I can't seem to find anything in the docs about turning on loglevel 5 tracing on masters, can you possibly let me know how? I'll include the level 5 build logs alongside them

alikhajeh1 avatar Mar 09 '17 15:03 alikhajeh1

Pass --loglevel=5 to openshift start.

Ben Parees | OpenShift

On Mar 9, 2017 7:12 AM, "Ali Khajeh-Hosseini" [email protected] wrote:

Thanks @bparees https://github.com/bparees, I can't seem to find anything in the docs about turning on loglevel 5 tracing on masters, can you possibly let me know how? I'll include the level 5 build logs alongside them

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/13239#issuecomment-285378196, or mute the thread https://github.com/notifications/unsubscribe-auth/AEvl3rz7kXkPvDn1upYdtgt4qvzO7dIrks5rkBa8gaJpZM4MTVSJ .

bparees avatar Mar 09 '17 15:03 bparees

@alikhajeh1 any updates here?

bparees avatar Apr 11 '17 21:04 bparees

@bparees sorry I dropped the ball on this. I updated /etc/systemd/system/multi-user.target.wants/origin-master-controllers.service:

ExecStart=/usr/bin/openshift start master controllers --loglevel=5 --config=${CONFIG_FILE} $OPTIONS

And /etc/systemd/system/multi-user.target.wants/origin-master-api.service:

ExecStart=/usr/bin/openshift start master api --loglevel=5 --config=${CONFIG_FILE} $OPTIONS

Then ran the following greps and restarted controllers/apis on one of our masters, nothing was output so it seems the plugin isn't being activated?

journalctl -u origin-master-controllers.service -f | grep defaults
journalctl -u origin-master-api.service -f | grep defaults

alikhajeh1 avatar Apr 12 '17 19:04 alikhajeh1

it doesn't make a lot of sense that we wouldn't at least get the initializing log output. are you seeing anything else in your master log output that demonstrates the loglevel=5 was successfully enabled? (other verbose logging that was not present before).

also running a build with "oc start-build --build-loglevel=5" and providing that build log may still show me something.

bparees avatar Apr 12 '17 19:04 bparees

@alikhajeh1 bump

bparees avatar May 12 '17 19:05 bparees

@bparees we've been planning an upgrade to Origin 1.5 (it'll happen in the next few days) so I'm waiting to see if I can repro on that as well.

alikhajeh1 avatar May 13 '17 05:05 alikhajeh1

I tried the same with OC 1.5.0 (kubernetes v1.5.2+43a9be4) but no luck. I can't say I'm seeing more logs in the master api/controllers that indicate that loglevel=5 was successfully enabled.

Here are the build logs with --build-loglevel=5:

$ oc logs -f helloworld-3-build
I0517 10:31:19.902484       1 builder.go:53] $BUILD env var is {"kind":"Build","apiVersion":"v1","metadata":{"name":"helloworld-3","namespace":"abc","selfLink":"/oapi/v1/namespaces/abc/builds/helloworld-3","uid":"f1c7ad5f-3aeb-11e7-b509-02838bd04ced","resourceVersion":"448432","creationTimestamp":"2017-05-17T10:31:10Z","labels":{"app":"helloworld","buildconfig":"helloworld","openshift.io/build-config.name":"helloworld","openshift.io/build.start-policy":"Serial"},"annotations":{"openshift.io/build-config.name":"helloworld","openshift.io/build.number":"3"}},"spec":{"serviceAccount":"builder","source":{"type":"Git","git":{"uri":"https://github.com/abarcloud/hello_world"}},"strategy":{"type":"Docker","dockerStrategy":{"from":{"kind":"DockerImage","name":"iron/ruby@sha256:0a58227a5729dc7bbf7c4c02385a506e7d9ce1ca624039f2ee3f933653e7ebf0"},"env":[{"name":"BUILD_LOGLEVEL","value":"5"}]}},"output":{"to":{"kind":"DockerImage","name":"172.30.153.104:5000/abc/helloworld:latest"},"pushSecret":{"name":"builder-dockercfg-wv7b2"}},"resources":{},"postCommit":{},"nodeSelector":null,"triggeredBy":[{"message":"Manually triggered"}]},"status":{"phase":"New","outputDockerImageReference":"172.30.153.104:5000/abc/helloworld:latest","config":{"kind":"BuildConfig","namespace":"abc","name":"helloworld"},"output":{}}}

I0517 10:31:19.981618       1 builder.go:61] Build: &api.Build{TypeMeta:unversioned.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:api.ObjectMeta{Name:"helloworld-3", GenerateName:"", Namespace:"abc", SelfLink:"/oapi/v1/namespaces/abc/builds/helloworld-3", UID:"f1c7ad5f-3aeb-11e7-b509-02838bd04ced", ResourceVersion:"448432", Generation:0, CreationTimestamp:unversioned.Time{Time:time.Time{sec:63630613870, nsec:0, loc:(*time.Location)(0xa309880)}}, DeletionTimestamp:(*unversioned.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string{"app":"helloworld", "buildconfig":"helloworld", "openshift.io/build-config.name":"helloworld", "openshift.io/build.start-policy":"Serial"}, Annotations:map[string]string{"openshift.io/build-config.name":"helloworld", "openshift.io/build.number":"3"}, OwnerReferences:[]api.OwnerReference(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:api.BuildSpec{CommonSpec:api.CommonSpec{ServiceAccount:"builder", Source:api.BuildSource{Binary:(*api.BinaryBuildSource)(nil), Dockerfile:(*string)(nil), Git:(*api.GitBuildSource)(0xc420648780), Images:[]api.ImageSource(nil), ContextDir:"", SourceSecret:(*api.LocalObjectReference)(nil), Secrets:[]api.SecretBuildSource(nil)}, Revision:(*api.SourceRevision)(nil), Strategy:api.BuildStrategy{DockerStrategy:(*api.DockerBuildStrategy)(0xc420651db0), SourceStrategy:(*api.SourceBuildStrategy)(nil), CustomStrategy:(*api.CustomBuildStrategy)(nil), JenkinsPipelineStrategy:(*api.JenkinsPipelineBuildStrategy)(nil)}, Output:api.BuildOutput{To:(*api.ObjectReference)(0xc420a89110), PushSecret:(*api.LocalObjectReference)(0xc4201b2c90), ImageLabels:[]api.ImageLabel(nil)}, Resources:api.ResourceRequirements{Limits:api.ResourceList(nil), Requests:api.ResourceList(nil)}, PostCommit:api.BuildPostCommitSpec{Command:[]string(nil), Args:[]string(nil), Script:""}, CompletionDeadlineSeconds:(*int64)(nil), NodeSelector:map[string]string(nil)}, TriggeredBy:[]api.BuildTriggerCause{api.BuildTriggerCause{Message:"Manually triggered", GenericWebHook:(*api.GenericWebHookCause)(nil), GitHubWebHook:(*api.GitHubWebHookCause)(nil), ImageChangeBuild:(*api.ImageChangeCause)(nil)}}}, Status:api.BuildStatus{Phase:"New", Cancelled:false, Reason:"", Message:"", StartTimestamp:(*unversioned.Time)(nil), CompletionTimestamp:(*unversioned.Time)(nil), Duration:0, OutputDockerImageReference:"172.30.153.104:5000/abc/helloworld:latest", Config:(*api.ObjectReference)(0xc420a89180), Output:api.BuildStatusOutput{To:(*api.BuildStatusOutputTo)(nil)}}}
I0517 10:31:19.981784       1 builder.go:66] warning: OpenShift server version "v1.5.0" differs from this image "v1.5.0+031cbe4"
I0517 10:31:19.982285       1 builder.go:160] Running build with cgroup limits: api.CGroupLimits{MemoryLimitBytes:1073741824, CPUShares:239, CPUPeriod:100000, CPUQuota:195300, MemorySwap:1073741824}
Cloning "https://github.com/abarcloud/hello_world" ...
I0517 10:31:20.061276       1 source.go:134] git ls-remote --heads https://github.com/abarcloud/hello_world

Our kubernetesMasterConfig has also has ClusterResourceOverride in case there's a conflict (I doubt it)?

alikhajeh1 avatar May 17 '17 10:05 alikhajeh1

and you are still not seeing either of these messages in your openshift master log after enabling loglevel 5?

Initialized build defaults plugin with config:
Initialized build overrides plugin with config:

?

bparees avatar May 17 '17 13:05 bparees

Correct, I can't see that in master api or controller logs

On May 17, 2017 18:29, "Ben Parees" [email protected] wrote:

and you are still not seeing either of these messages in your openshift master log after enabling loglevel 5?

Initialized build defaults plugin with config:

Initialized build overrides plugin with config:

?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/13239#issuecomment-302098791, or mute the thread https://github.com/notifications/unsubscribe-auth/AAm-cS5CYj4TQhtKRdmma5YBLhEESv5zks5r6v08gaJpZM4MTVSJ .

alikhajeh1 avatar May 17 '17 15:05 alikhajeh1

@alikhajeh1 can you provide me with your the logs? there are some other things i'd like to look for.

bparees avatar May 17 '17 15:05 bparees

Much appreciated @bparees, I emailed you the logs, I'd rather not share them here.

alikhajeh1 avatar May 18 '17 06:05 alikhajeh1

sorry, I think you have configured the plugin at the wrong level of your master config file....

the openshift admission control config goes at the top level of your config, eg:

admissionConfig:
  pluginConfig:
    openshift.io/ImagePolicy:
      configuration:
        apiVersion: v1
        executionRules:
        - matchImageAnnotations:
          - key: images.openshift.io/deny-execution
            value: "true"
          name: execution-denied
          onResources:
          - resource: pods
          - resource: builds
          reject: true
          skipOnResolutionFailure: true
        kind: ImagePolicyConfig
      location: ""
kubernetesMasterConfig:
  admissionConfig:
    pluginConfig: null
  apiLevels: null
  apiServerArguments:
    storage-backend:
    - etcd3
    storage-media-type:
    - application/vnd.kubernetes.protobuf

whereas you have nested yours under the kubernetes config section, which is for kubernetes admission controllers.

Sorry I did not notice that sooner.

bparees avatar May 18 '17 21:05 bparees

Doh! Ok I fixed that. My understanding was that the memory requests defined in Global Build Defaults took precedence over the project's defaultRequest defined in the LimitRange. So we could setup a project LimitRange to define defaults and bounds for normal pods, and use the BuildDefaultsConfig to define default and bounds for build pods. However, looking at some example builds, it doesn't seem that way. Am I misunderstanding something? See the following setup/logs:

BuildDefaultsConfig:

admissionConfig:
  pluginConfig:
    BuildDefaults:
      configuration:
        apiVersion: v1
        kind: BuildDefaultsConfig
        resources:
          requests:
            memory: "400Mi"
          limits:
            memory: "400Mi"

Logs showing the above is being applied:

$ journalctl -u origin-master-controllers.service -f | grep 'build defaults'

May 19 04:17:56 XXX origin-master-controllers[31273]: I0519 04:17:56.554038   31273 admission.go:29] Initialized build defaults plugin with config: api.BuildDefaultsConfig{TypeMeta:unversioned.TypeMeta{Kind:"", APIVersion:""}, GitHTTPProxy:"", GitHTTPSProxy:"", GitNoProxy:"", Env:[]api.EnvVar(nil), SourceStrategyDefaults:(*api.SourceStrategyDefaultsConfig)(nil), ImageLabels:[]api.ImageLabel(nil), NodeSelector:map[string]string(nil), Annotations:map[string]string(nil), Resources:api.ResourceRequirements{Limits:api.ResourceList{"memory":resource.Quantity{i:resource.int64Amount{value:419430400, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:"", Format:"BinarySI"}}, Requests:api.ResourceList{"memory":resource.Quantity{i:resource.int64Amount{value:419430400, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:"", Format:"BinarySI"}}}}

The project LimitRange:

- apiVersion: v1
  kind: LimitRange
  metadata:
    name: project-compute-resource-limits
    namespace: test
  spec:
    limits:
    - default:
        memory: 201Mi
      defaultRequest:
        memory: 201Mi

An example build, with no resources defined, shows that the 400Mi parameters are being passed in, yet the build container is created with the project's default request of 201Mi. The pod's request shows memory: 201Mi as well:

I0519 04:25:20.262482       1 builder.go:53] $BUILD env var is {"kind":"Build","apiVersion":"v1","metadata":{"name":"helloworld-20","namespace":"test","selfLink":"/oapi/v1/namespaces/test/builds/helloworld-20","uid":"248de40d-3c4b-11e7-8e86-02838bd04ced","resourceVersion":"472991","creationTimestamp":"2017-05-19T04:25:09Z","labels":{"app":"helloworld","buildconfig":"helloworld","openshift.io/build-config.name":"helloworld","openshift.io/build.start-policy":"Serial"},"annotations":{"openshift.io/build-config.name":"helloworld","openshift.io/build.number":"20"}},"spec":{"serviceAccount":"builder","source":{"type":"Git","git":{"uri":"https://github.com/abarcloud/hello_world"}},"strategy":{"type":"Docker","dockerStrategy":{"from":{"kind":"DockerImage","name":"iron/ruby@sha256:0a58227a5729dc7bbf7c4c02385a506e7d9ce1ca624039f2ee3f933653e7ebf0"},"env":[{"name":"BUILD_LOGLEVEL","value":"5"}]}},"output":{"to":{"kind":"DockerImage","name":"172.30.153.104:5000/test/helloworld:latest"},"pushSecret":{"name":"builder-dockercfg-w3szn"}},"resources":{"limits":{"memory":"400Mi"},"requests":{"memory":"400Mi"}},"postCommit":{},"nodeSelector":null,"triggeredBy":[{"message":"Manually triggered"}]},"status":{"phase":"New","outputDockerImageReference":"172.30.153.104:5000/test/helloworld:latest","config":{"kind":"BuildConfig","namespace":"test","name":"helloworld"},"output":{}}}

I0519 04:25:20.513627       1 builder.go:61] Build: &api.Build{TypeMeta:unversioned.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:api.ObjectMeta{Name:"helloworld-20", GenerateName:"", Namespace:"test", SelfLink:"/oapi/v1/namespaces/test/builds/helloworld-20", UID:"248de40d-3c4b-11e7-8e86-02838bd04ced", ResourceVersion:"472991", Generation:0, CreationTimestamp:unversioned.Time{Time:time.Time{sec:63630764709, nsec:0, loc:(*time.Location)(0xa309880)}}, DeletionTimestamp:(*unversioned.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string{"app":"helloworld", "buildconfig":"helloworld", "openshift.io/build-config.name":"helloworld", "openshift.io/build.start-policy":"Serial"}, Annotations:map[string]string{"openshift.io/build.number":"20", "openshift.io/build-config.name":"helloworld"}, OwnerReferences:[]api.OwnerReference(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:api.BuildSpec{CommonSpec:api.CommonSpec{ServiceAccount:"builder", Source:api.BuildSource{Binary:(*api.BinaryBuildSource)(nil), Dockerfile:(*string)(nil), Git:(*api.GitBuildSource)(0xc4203d0bc0), Images:[]api.ImageSource(nil), ContextDir:"", SourceSecret:(*api.LocalObjectReference)(nil), Secrets:[]api.SecretBuildSource(nil)}, Revision:(*api.SourceRevision)(nil), Strategy:api.BuildStrategy{DockerStrategy:(*api.DockerBuildStrategy)(0xc420160e60), SourceStrategy:(*api.SourceBuildStrategy)(nil), CustomStrategy:(*api.CustomBuildStrategy)(nil), JenkinsPipelineStrategy:(*api.JenkinsPipelineBuildStrategy)(nil)}, Output:api.BuildOutput{To:(*api.ObjectReference)(0xc420f82070), PushSecret:(*api.LocalObjectReference)(0xc42019a820), ImageLabels:[]api.ImageLabel(nil)}, Resources:api.ResourceRequirements{Limits:api.ResourceList{"memory":resource.Quantity{i:resource.int64Amount{value:419430400, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:"", Format:"BinarySI"}}, Requests:api.ResourceList{"memory":resource.Quantity{i:resource.int64Amount{value:419430400, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:"", Format:"BinarySI"}}}, PostCommit:api.BuildPostCommitSpec{Command:[]string(nil), Args:[]string(nil), Script:""}, CompletionDeadlineSeconds:(*int64)(nil), NodeSelector:map[string]string(nil)}, TriggeredBy:[]api.BuildTriggerCause{api.BuildTriggerCause{Message:"Manually triggered", GenericWebHook:(*api.GenericWebHookCause)(nil), GitHubWebHook:(*api.GitHubWebHookCause)(nil), ImageChangeBuild:(*api.ImageChangeCause)(nil)}}}, Status:api.BuildStatus{Phase:"New", Cancelled:false, Reason:"", Message:"", StartTimestamp:(*unversioned.Time)(nil), CompletionTimestamp:(*unversioned.Time)(nil), Duration:0, OutputDockerImageReference:"172.30.153.104:5000/test/helloworld:latest", Config:(*api.ObjectReference)(0xc420f820e0), Output:api.BuildStatusOutput{To:(*api.BuildStatusOutputTo)(nil)}}}
I0519 04:25:20.513799       1 builder.go:66] warning: OpenShift server version "v1.5.0" differs from this image "v1.5.0+031cbe4"
I0519 04:25:20.514342       1 builder.go:160] Running build with cgroup limits: api.CGroupLimits{MemoryLimitBytes:210763776, CPUShares:48, CPUPeriod:100000, CPUQuota:39200, MemorySwap:210763776}

alikhajeh1 avatar May 19 '17 04:05 alikhajeh1

unfortunately i think you're hitting this bug in which the builddefault resource values weren't being properly applied to the build pod:

https://bugzilla.redhat.com/show_bug.cgi?id=1443187

it'll be fixed in OCP3.6 (and is fixed in current origin master).

the fix is here: https://github.com/openshift/origin/pull/13825

bparees avatar May 19 '17 04:05 bparees

Thanks Ben, you rock! I'll close this issue and re-open if I can have issues after our 3.6 upgrade.

On May 19, 2017 09:16, "Ben Parees" [email protected] wrote:

unfortunately i think you're hitting this bug in which the builddefault resource values weren't being properly applied to the build pod:

https://bugzilla.redhat.com/show_bug.cgi?id=1443187

it'll be fixed in OCP3.6 (and is fixed in current origin master).

the fix is here: #13825 https://github.com/openshift/origin/pull/13825

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/13239#issuecomment-302607410, or mute the thread https://github.com/notifications/unsubscribe-auth/AAm-cVfN-h1rCAtkK3n_-Conh5JGscLJks5r7R6vgaJpZM4MTVSJ .

alikhajeh1 avatar May 19 '17 05:05 alikhajeh1

@bparees just wanted to check that #13825 also fixes BuildOverridesConfig? In Origin 1.5.1, I set BuildOverridesConfig and the master logs show:

Jul 26 13:43:30 XXX origin-master-controllers[69283]: I0726 13:43:30.964350   69283 admission.go:29] Initialized build overrides plugin with config: api.BuildOverridesConfig{TypeMeta:unversioned.TypeMeta{Kind:"", APIVersion:""}, ForcePull:false, ImageLabels:[]api.ImageLabel(nil), NodeSelector:map[string]string{"key1":"value1"}, Annotations:map[string]string(nil)}

But the build logs don't reflect this:

I0726 13:44:01.269375       1 builder.go:53] $BUILD env var is {"kind":"Build","apiVersion":"v1","metadata":{"name":"helloworld-9","namespace":"abc","selfLink":"/oapi/v1/namespaces/abc/builds/helloworld-9","uid":"7949e100-7208-11e7-aaf9-0233bdbcecf3","resourceVersion":"520109","creationTimestamp":"2017-07-26T13:43:57Z","labels":{"app":"helloworld","buildconfig":"helloworld","openshift.io/build-config.name":"helloworld","openshift.io/build.start-policy":"Serial"},"annotations":{"openshift.io/build-config.name":"helloworld","openshift.io/build.number":"9"}},"spec":{"serviceAccount":"builder","source":{"type":"Git","git":{"uri":"https://github.com/abarcloud/hello_world"}},"strategy":{"type":"Docker","dockerStrategy":{"from":{"kind":"DockerImage","name":"iron/ruby@sha256:0a58227a5729dc7bbf7c4c02385a506e7d9ce1ca624039f2ee3f933653e7ebf0"},"env":[{"name":"BUILD_LOGLEVEL","value":"5"}]}},"output":{"to":{"kind":"DockerImage","name":"XXX:5000/abc/helloworld:latest"},"pushSecret":{"name":"builder-dockercfg-sbvvb"}},"resources":{},"postCommit":{},**"nodeSelector":null**,"triggeredBy":[{"message":"Manually triggered"}]},"status":{"phase":"New","outputDockerImageReference":"172.30.20.248:5000/abc/helloworld:latest","config":

alikhajeh1 avatar Jul 26 '17 14:07 alikhajeh1

@alikhajeh1 that PR has no affect on the override admission logic (the issue was only for resource limits which are not configurable via the override plugin). But i'm not sure what you expected to see in the BUILD env var in your case. It looks like you're only setting a NodeSelector in the overrides, and the NodeSelector will be applied to the buildpod.

bparees avatar Jul 26 '17 14:07 bparees

Thanks for clarifying @bparees. My master-config.yaml has:

admissionConfig:
  pluginConfig:
    BuildOverrides:
      configuration:
        apiVersion: v1
        kind: BuildOverridesConfig
        nodeSelector:
          build: "true"
...
projectConfig:
  defaultNodeSelector: "scope=public, generic=true"

And I have two nodes:

  • node1 has labels: generic=true, build=true
  • node2 has labels: build=true

I expected build pods to be scheduled on either node1 or 2, and normal pods to only be scheduled on node1. What I'm seeing with 1.5.1 is that build pods complain about not matching any node selector.

Am I doing something wrong?

alikhajeh1 avatar Jul 26 '17 15:07 alikhajeh1