@@ -93,17 +93,9 @@ func (p *GCEProvisioner) Provision(host BasicHost) (*ProvisionedHost, error) {
93
93
},
94
94
}
95
95
96
- exists , _ := p .gceFirewallExists (host .Additional ["projectid" ], host .Additional ["firewall-name" ], host .Additional ["firewall-port" ])
97
-
98
- if ! exists {
99
- err := p .createInletsFirewallRule (host .Additional ["projectid" ], host .Additional ["firewall-name" ], host .Additional ["firewall-port" ])
100
- log .Println ("inlets firewallRule does not exist" )
101
- if err != nil {
102
- return nil , fmt .Errorf ("could not create inlets firewall rule: %v" , err )
103
- }
104
- log .Printf ("Creating inlets firewallRule opening port: %s\n " , host .Additional ["firewall-port" ])
105
- } else {
106
- log .Println ("inlets firewallRule exists" )
96
+ err := p .createInletsFirewallRule (host .Additional ["projectid" ], host .Additional ["firewall-name" ], host .Additional ["firewall-port" ], host .Additional ["pro" ])
97
+ if err != nil {
98
+ return nil , err
107
99
}
108
100
109
101
op , err := p .gceProvisioner .Instances .Insert (host .Additional ["projectid" ], host .Additional ["zone" ], instance ).Do ()
@@ -116,53 +108,73 @@ func (p *GCEProvisioner) Provision(host BasicHost) (*ProvisionedHost, error) {
116
108
if op .Status == gceHostRunning {
117
109
status = ActiveStatus
118
110
}
119
-
120
111
return & ProvisionedHost {
121
112
ID : toGCEID (host .Name , host .Additional ["zone" ], host .Additional ["projectid" ]),
122
113
Status : status ,
123
114
}, nil
124
115
}
125
116
126
117
// gceFirewallExists checks if the inlets firewall rule exists or not
127
- func (p * GCEProvisioner ) gceFirewallExists (projectID string , firewallRuleName string , controlPort string ) (bool , error ) {
118
+ func (p * GCEProvisioner ) gceFirewallExists (projectID string , firewallRuleName string ) (bool , error ) {
128
119
op , err := p .gceProvisioner .Firewalls .Get (projectID , firewallRuleName ).Do ()
129
120
if err != nil {
130
121
return false , fmt .Errorf ("could not get inlets firewall rule: %v" , err )
131
122
}
132
123
if op .Name == firewallRuleName {
133
- for _ , firewallRule := range op .Allowed {
134
- for _ , port := range firewallRule .Ports {
135
- if port == controlPort {
136
- return true , nil
137
- }
138
- }
139
- }
124
+ return true , nil
140
125
}
141
126
return false , nil
142
127
}
143
128
144
129
// createInletsFirewallRule creates a firewall rule opening up the control port for inlets
145
- func (p * GCEProvisioner ) createInletsFirewallRule (projectID string , firewallRuleName string , controlPort string ) error {
146
- firewallRule := & compute.Firewall {
147
- Name : firewallRuleName ,
148
- Description : "Firewall rule created by inlets-operator" ,
149
- Network : fmt .Sprintf ("projects/%s/global/networks/default" , projectID ),
150
- Allowed : []* compute.FirewallAllowed {
151
- {
152
- IPProtocol : "tcp" ,
153
- Ports : []string {controlPort },
130
+ func (p * GCEProvisioner ) createInletsFirewallRule (projectID string , firewallRuleName string , controlPort string , pro string ) error {
131
+ var firewallRule * compute.Firewall
132
+ if pro == "true" {
133
+ firewallRule = & compute.Firewall {
134
+ Name : firewallRuleName ,
135
+ Description : "Firewall rule created by inlets-operator" ,
136
+ Network : fmt .Sprintf ("projects/%s/global/networks/default" , projectID ),
137
+ Allowed : []* compute.FirewallAllowed {
138
+ {
139
+ IPProtocol : "tcp" ,
140
+ },
154
141
},
155
- },
156
- SourceRanges : []string {"0.0.0.0/0" },
157
- Direction : "INGRESS" ,
158
- TargetTags : []string {"inlets" },
142
+ SourceRanges : []string {"0.0.0.0/0" },
143
+ Direction : "INGRESS" ,
144
+ TargetTags : []string {"inlets" },
145
+ }
146
+ } else {
147
+ firewallRule = & compute.Firewall {
148
+ Name : firewallRuleName ,
149
+ Description : "Firewall rule created by inlets-operator" ,
150
+ Network : fmt .Sprintf ("projects/%s/global/networks/default" , projectID ),
151
+ Allowed : []* compute.FirewallAllowed {
152
+ {
153
+ IPProtocol : "tcp" ,
154
+ Ports : []string {controlPort },
155
+ },
156
+ },
157
+ SourceRanges : []string {"0.0.0.0/0" },
158
+ Direction : "INGRESS" ,
159
+ TargetTags : []string {"inlets" },
160
+ }
161
+ }
162
+
163
+ exists , _ := p .gceFirewallExists (projectID , firewallRuleName )
164
+ if exists {
165
+ log .Println ("inlets firewallRule exists, updating firewall-rules" )
166
+ _ , err := p .gceProvisioner .Firewalls .Update (projectID , firewallRuleName , firewallRule ).Do ()
167
+ if err != nil {
168
+ return fmt .Errorf ("could not update inlets firewall rule: %v" , err )
169
+ }
170
+ return nil
159
171
}
160
172
161
173
_ , err := p .gceProvisioner .Firewalls .Insert (projectID , firewallRule ).Do ()
174
+ log .Println ("creating inlets firewallRule" )
162
175
if err != nil {
163
- return fmt .Errorf ("could not create firewall rule: %v" , err )
176
+ return fmt .Errorf ("could not create inlets firewall rule: %v" , err )
164
177
}
165
-
166
178
return nil
167
179
}
168
180
0 commit comments