diff --git a/assets/defaults/cluster-ingress.yaml b/assets/defaults/cluster-ingress.yaml index c5ae259b6d..1a0f2fd002 100644 --- a/assets/defaults/cluster-ingress.yaml +++ b/assets/defaults/cluster-ingress.yaml @@ -5,7 +5,6 @@ apiVersion: ingress.openshift.io/v1alpha1 metadata: name: default namespace: openshift-cluster-ingress-operator - finalizers: # Ensure that only the operator can delete the default cluster ingress object. finalizers: - ingress.openshift.io/default-cluster-ingress diff --git a/pkg/manifests/bindata.go b/pkg/manifests/bindata.go index 8e237ed8ec..9ea978fb9b 100644 --- a/pkg/manifests/bindata.go +++ b/pkg/manifests/bindata.go @@ -82,7 +82,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _assetsDefaultsClusterIngressYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x91\x31\x8f\x9b\x40\x10\x85\x7b\x7e\xc5\x93\x5d\x43\x74\x2d\x5d\x94\xa4\x38\x29\x45\xa4\x48\xe9\xc7\xcb\xc3\x4c\xbc\xcc\xae\x76\x07\x9f\x9c\x5f\x1f\x71\x40\x0a\xe7\x4a\x9e\x86\x6f\xbe\x7d\x73\xc6\x97\xb8\x54\x67\x79\xb5\x6b\x61\xad\x78\x53\x9f\x30\x70\x94\x25\x3a\xee\x12\x17\xd6\xe6\x8c\x57\xab\x2e\x31\xb2\x20\x24\x1b\xf5\x8a\x9a\x19\x74\xd4\xb0\x8f\x40\x0a\x21\x39\x47\xe5\x00\x71\x94\xc5\x5c\x67\x76\xcd\x4d\x6d\xe8\x9f\x76\x34\x92\xf5\x17\x4b\xd5\x64\x3d\x74\xcb\xba\x94\x69\x75\xd2\xd1\x3b\x4d\x9f\xee\x2f\x12\xf3\x24\x2f\xcd\x4c\x97\x41\x5c\xfa\x06\x30\x99\xd9\x1f\x6a\xfb\x77\xcd\x12\xd8\xe3\xdf\xcf\x6d\xd8\x36\xb5\x3b\xb6\x4d\x99\x45\x3c\x95\x06\x18\xd5\x24\xea\x1f\x96\xba\xd2\xce\xf8\x66\x75\x29\x84\x4f\xe2\x48\x16\x1f\xf0\x89\x38\xe6\x11\xc4\x30\x30\xd2\xf9\x9e\x1f\x8d\xec\xfc\x43\x1b\xe9\xf2\x9b\xc1\xbb\xff\xf0\xed\xc7\x0f\xdb\x31\xcf\x9a\xcd\x5a\xe7\x66\xb5\x77\xf4\x35\xcd\xa2\x06\xad\x1f\xb4\x8a\xa5\xaa\x5d\xdf\xb5\xf4\xe9\x2e\xab\x88\xa5\x81\x3f\xa2\x04\xce\x34\x5f\xa1\x5b\xf4\x93\x91\xc1\x53\xd9\x12\x60\x16\x0f\xd3\x77\xb9\x30\xd6\x23\x02\x4e\xeb\x64\x5b\x52\x64\x77\x5b\x2e\x2c\x46\x67\x5d\xc5\xdf\x52\xb9\xb1\x9c\x7a\x9c\x4e\x0d\x30\xe9\x75\xfa\x7c\x17\x8d\x72\xd1\xa8\xfe\xd8\x00\xfe\xc8\x5c\x6f\x9d\x96\xa1\xf9\x1b\x00\x00\xff\xff\x3c\x82\x14\x4d\x58\x02\x00\x00") +var _assetsDefaultsClusterIngressYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x91\xb1\x8e\xdb\x30\x10\x44\x7b\x7e\xc5\xc0\xae\xa5\xe0\x5a\x75\x41\x92\xe2\x80\x14\x01\x02\xa4\x5f\x53\x23\x69\x63\x8a\x24\xc8\x95\x0f\xce\xd7\x07\xb2\xa4\x2b\x0c\x97\x1c\x0c\x67\xdf\xce\x9e\xf1\x2d\x2c\xd5\x58\xde\xe3\x58\x58\x2b\x3e\xd4\x26\xf4\x1c\x64\x09\x86\x9b\x84\x85\xd5\x9d\xf1\x1e\xab\x49\x08\x2c\xf0\x29\x0e\x3a\xa2\x66\x7a\x1d\xd4\xef\x16\x48\x21\x24\xe7\xa0\xec\x21\x86\xb2\x44\xd3\x99\xad\xbb\x6a\xec\xbb\xa7\x19\x4e\xb2\xfe\x61\xa9\x9a\x62\x07\xdd\xb4\x36\x65\xc6\x3a\xe9\x60\xad\xa6\x2f\xb7\x37\x09\x79\x92\x37\x37\xd3\xa4\x17\x93\xce\x01\x51\x66\x76\x07\xda\xfe\xae\x59\x3c\x3b\x7c\x7e\x6e\xfc\x36\xa9\xd9\x63\x9b\x94\x59\xc4\x52\x71\xc0\x19\x3f\x62\x5d\x0a\x61\x93\x18\x52\x0c\x77\xd8\x44\x1c\x0e\x78\x89\xe8\x19\x68\x7c\xe8\x47\x07\x7b\xe2\x01\x8a\x74\xf9\x4b\x6f\xad\x03\x06\x8d\x12\xf4\x1f\x4b\x5d\xf1\x9a\xd7\xab\xec\x31\xcf\x60\x6e\x2d\xb0\x7b\x50\xed\xad\x7c\x4f\xb3\x68\x84\xd6\x17\x3d\x62\xa9\x1a\xc7\x07\x96\x3e\x5d\x62\x05\x89\xa9\xe7\xaf\x20\x9e\x33\xa3\xad\xa1\x9b\xf4\x9b\x81\xde\x52\xd9\x14\x60\x16\xf3\xd3\x4f\xb9\x30\xd4\x43\x02\x4e\xab\xb3\x29\x29\xb0\xbd\x2e\x17\x96\x48\x63\x5d\xc1\x3f\x52\xb9\xb2\x9c\x3a\x9c\x4e\x0e\x98\x74\x9c\xbe\xde\x44\x83\x5c\x34\xa8\xdd\xb7\x00\xbb\x67\xae\xd7\x4d\x4b\xef\xfe\x07\x00\x00\xff\xff\x21\xfa\x63\x49\x4a\x02\x00\x00") func assetsDefaultsClusterIngressYamlBytes() ([]byte, error) { return bindataRead( @@ -97,7 +97,7 @@ func assetsDefaultsClusterIngressYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "assets/defaults/cluster-ingress.yaml", size: 600, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "assets/defaults/cluster-ingress.yaml", size: 586, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/pkg/stub/handler.go b/pkg/stub/handler.go index 5e0fbdb3a0..2bdafd43f6 100644 --- a/pkg/stub/handler.go +++ b/pkg/stub/handler.go @@ -69,16 +69,56 @@ func (h *Handler) EnsureDefaultClusterIngress() error { return err } - err = sdk.Create(ci) - if err == nil || errors.IsAlreadyExists(err) { - if err == nil { - logrus.Infof("created default cluster ingress %s/%s", ci.Namespace, ci.Name) + changed, nci, err := checkClusterIngress(ci) + if err != nil { + return err + } + if changed { + err = sdk.Update(nci) + if err != nil { + return fmt.Errorf("updating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err) } + logrus.Infof("updated default cluster ingress %s/%s", ci.Namespace, ci.Name) + } else if nci == nil { + err = sdk.Create(ci) + if err != nil { + return fmt.Errorf("creating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err) + } + logrus.Infof("created default cluster ingress %s/%s", ci.Namespace, ci.Name) + } + return nil +} - return nil +func checkClusterIngress(ci *ingressv1alpha1.ClusterIngress) (bool, *ingressv1alpha1.ClusterIngress, error) { + oldci := &ingressv1alpha1.ClusterIngress{ + TypeMeta: metav1.TypeMeta{ + Kind: ci.Kind, + APIVersion: ci.APIVersion, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: ci.Name, + Namespace: ci.Namespace, + }, + } + err := sdk.Get(oldci) + if err != nil { + if !errors.IsNotFound(err) { + return false, nil, fmt.Errorf("failed to fetch existing default cluster ingress %s/%s, %v", ci.Namespace, ci.Name, err) + } + return false, nil, nil } - return fmt.Errorf("creating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err) + if ci.Spec.IngressDomain == nil { + return false, nil, fmt.Errorf("invalid ingress domain for default cluster ingress %s/%s", ci.Namespace, ci.Name) + } + if oldci.Spec.IngressDomain == nil { + oldci.Spec.IngressDomain = new(string) + } + if *oldci.Spec.IngressDomain != *ci.Spec.IngressDomain { + *oldci.Spec.IngressDomain = *ci.Spec.IngressDomain + return true, oldci, nil + } + return false, oldci, nil } // Reconcile performs a full reconciliation loop for ingress, including