forked from openshift/cluster-image-registry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "IR-373: remove node-ca daemon"
- Loading branch information
Showing
11 changed files
with
573 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package assets | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed *.yaml | ||
var f embed.FS | ||
|
||
// MustAsset reads and returns the content of the named file or panics | ||
// if something went wrong. | ||
func MustAsset(name string) []byte { | ||
data, err := f.ReadFile(name) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: node-ca | ||
namespace: openshift-image-registry | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: node-ca | ||
updateStrategy: | ||
type: RollingUpdate | ||
rollingUpdate: | ||
maxUnavailable: 10% | ||
template: | ||
metadata: | ||
annotations: | ||
target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' | ||
labels: | ||
name: node-ca | ||
spec: | ||
nodeSelector: | ||
kubernetes.io/os: linux | ||
priorityClassName: system-cluster-critical | ||
tolerations: | ||
- operator: Exists | ||
hostNetwork: true # run as host network to tolerate unready networks | ||
serviceAccountName: node-ca | ||
containers: | ||
- name: node-ca | ||
securityContext: | ||
privileged: true | ||
runAsUser: 1001 | ||
runAsGroup: 0 | ||
image: docker.io/openshift/origin-cluster-image-registry-operator:latest | ||
resources: | ||
requests: | ||
cpu: 10m | ||
memory: 10Mi | ||
command: | ||
- "/bin/sh" | ||
- "-c" | ||
- | | ||
trap 'jobs -p | xargs -r kill; echo shutting down node-ca; exit 0' TERM | ||
while [ true ]; | ||
do | ||
for f in $(ls /tmp/serviceca); do | ||
echo $f | ||
ca_file_path="/tmp/serviceca/${f}" | ||
f=$(echo $f | sed -r 's/(.*)\.\./\1:/') | ||
reg_dir_path="/etc/docker/certs.d/${f}" | ||
if [ -e "${reg_dir_path}" ]; then | ||
cp -u $ca_file_path $reg_dir_path/ca.crt | ||
else | ||
mkdir $reg_dir_path | ||
cp $ca_file_path $reg_dir_path/ca.crt | ||
fi | ||
done | ||
for d in $(ls /etc/docker/certs.d); do | ||
echo $d | ||
dp=$(echo $d | sed -r 's/(.*):/\1\.\./') | ||
reg_conf_path="/tmp/serviceca/${dp}" | ||
if [ ! -e "${reg_conf_path}" ]; then | ||
rm -rf /etc/docker/certs.d/$d | ||
fi | ||
done | ||
sleep 60 & wait ${!} | ||
done | ||
volumeMounts: | ||
- name: serviceca | ||
mountPath: /tmp/serviceca | ||
- name: host | ||
mountPath: /etc/docker/certs.d | ||
volumes: | ||
- name: host | ||
hostPath: | ||
path: /etc/docker/certs.d | ||
- name: serviceca | ||
configMap: | ||
name: image-registry-certificates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package resource | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
kfake "k8s.io/client-go/kubernetes/fake" | ||
|
||
imageregistryv1 "github.com/openshift/api/imageregistry/v1" | ||
imageregistryfake "github.com/openshift/client-go/imageregistry/clientset/versioned/fake" | ||
imageregistryinformers "github.com/openshift/client-go/imageregistry/informers/externalversions" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
|
||
"github.com/openshift/cluster-image-registry-operator/pkg/client" | ||
) | ||
|
||
func findToleration(list []corev1.Toleration, cond func(toleration corev1.Toleration) bool) *corev1.Toleration { | ||
for i, t := range list { | ||
if cond(t) { | ||
return &list[i] | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func TestNodeCADaemon(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
imageregistryObjects := []runtime.Object{ | ||
&imageregistryv1.Config{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "cluster", | ||
}, | ||
}, | ||
} | ||
|
||
clientset := kfake.NewSimpleClientset() | ||
imageregistryClient := imageregistryfake.NewSimpleClientset(imageregistryObjects...) | ||
|
||
imageregistryInformers := imageregistryinformers.NewSharedInformerFactory(imageregistryClient, time.Minute) | ||
|
||
operatorClient := client.NewConfigOperatorClient( | ||
imageregistryClient.ImageregistryV1().Configs(), | ||
imageregistryInformers.Imageregistry().V1().Configs(), | ||
) | ||
|
||
imageregistryInformers.Start(ctx.Done()) | ||
imageregistryInformers.WaitForCacheSync(ctx.Done()) | ||
|
||
g := NewGeneratorNodeCADaemonSet(events.NewInMemoryRecorder("image-registry-operator"), nil, nil, clientset.AppsV1(), operatorClient) | ||
obj, err := g.Create() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ds := obj.(*appsv1.DaemonSet) | ||
noScheduleToleration := findToleration(ds.Spec.Template.Spec.Tolerations, func(tol corev1.Toleration) bool { | ||
return tol.Key == "" && tol.Operator == "Exists" && tol.Value == "" && tol.Effect == "" | ||
}) | ||
if noScheduleToleration == nil { | ||
t.Errorf("unable to find toleration for all taints, %#+v", ds.Spec.Template.Spec.Tolerations) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.